-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
248039d
commit eea5a26
Showing
17 changed files
with
405 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[burn_tensor_testgen::testgen(ad_sqrt)] | ||
mod tests { | ||
use super::*; | ||
use burn_tensor::Data; | ||
|
||
#[test] | ||
fn should_diff_sqrt() { | ||
let data_1 = Data::<f32, 2>::from([[0.0, 1.0], [3.0, 4.0]]); | ||
let data_2 = Data::<f32, 2>::from([[6.0, 7.0], [9.0, 10.0]]); | ||
|
||
let tensor_1 = TestADTensor::from_data(data_1); | ||
let tensor_2 = TestADTensor::from_data(data_2); | ||
|
||
let tensor_3 = tensor_1.matmul(&tensor_2.sqrt()); | ||
let tensor_4 = tensor_3.matmul(&tensor_2); | ||
let grads = tensor_4.backward(); | ||
|
||
let grad_1 = tensor_1.grad(&grads).unwrap(); | ||
let grad_2 = tensor_2.grad(&grads).unwrap(); | ||
|
||
grad_1 | ||
.to_data() | ||
.assert_approx_eq(&Data::from([[82.1126, 99.0832], [82.1126, 99.0832]]), 3); | ||
grad_2 | ||
.to_data() | ||
.assert_approx_eq(&Data::from([[30.3093, 33.1204], [34.5819, 38.7694]]), 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.