Skip to main content

diff

Function diff 

Source
pub fn diff<F: Fn(Dual) -> Dual>(f: F, x: f64) -> (f64, f64)
Expand description

Compute f(x) and f'(x) in one forward-mode pass.

Seeds x (tangent 1.0), runs f, and returns the extracted (value, derivative) pair.

use fdars_core::autodiff::{diff, Scalar};

// d/dx exp(x) at x = 0 is 1.
let (v, d) = diff(|x| Scalar::exp(x), 0.0);
assert!((v - 1.0).abs() < 1e-12);
assert!((d - 1.0).abs() < 1e-12);