Skip to content

Commit

Permalink
add self duplicated test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 committed Apr 11, 2024
1 parent cb027ff commit b75323b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions samples/tests/reverse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ samples::test! {
// ANCHOR_END: square
}

samples::test! {
self_duplicated;
struct Ogden {
k: f64,
}
impl Ogden {
#[autodiff(d_f, Reverse, Duplicated, Const, Active)]
fn f(&self, j: f64) -> f64 {
self.k * self.k
}
}

fn main() {
let j = 4.0;
let vol = Ogden { k: 1.0 };
let mut out = Ogden { k: 0.0 };
let s = vol.d_f(&mut out, j, 1.0);
let res = 2.0 * vol.k;
assert!((s - res).abs() < 1e-15, "{}", out.k);
}
}

samples::test! {
empty_return;
// ANCHOR: empty_return
Expand Down

0 comments on commit b75323b

Please sign in to comment.