Skip to content

Commit

Permalink
Activeonly (#7)
Browse files Browse the repository at this point in the history
* add ActiveOnly ret test to CI

* cleanup
  • Loading branch information
ZuseZ4 authored Apr 11, 2024
1 parent 15611d1 commit 28517c8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion samples/tests/reverse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
samples::test! {
square;
/// ANCHOR: square
// ANCHOR: square
#[autodiff(d_square, Reverse, Duplicated, Active)]
fn square(x: &f64) -> f64 {
x * x
Expand All @@ -19,8 +19,29 @@ samples::test! {
// ANCHOR_END: square
}

samples::test! {
active_only;
// ANCHOR: active_only
#[autodiff(d_f, Reverse, Active, Active)]
#[autodiff(d_f2, Reverse, Active, ActiveOnly)]
fn f(x: f64) -> f64 {
f64::sin(x)
}

fn main() {
let x = 1.0;
let (_y, d_y) = d_f(x, 1.0);
let d2_y = d_f2(x, 1.0);
let cos_x = f64::cos(x);
assert!((d2_y - d_y).abs() < 1e-15);
assert!((cos_x - d_y).abs() < 1e-15);
}
// ANCHOR_END: active_only
}

samples::test! {
self_duplicated;
// ANCHOR: self_duplicated
struct Ogden {
k: f64,
}
Expand All @@ -39,6 +60,7 @@ samples::test! {
let res = 2.0 * vol.k;
assert!((out.k - res).abs() < 1e-15, "{} {}", res, out.k);
}
// ANCHOR_END: self_duplicated
}

samples::test! {
Expand Down

0 comments on commit 28517c8

Please sign in to comment.