Macro rust_ad::forward[][src]

forward!() { /* proc-macro */ }
Expand description

Calls forward auto-differentiation function corresponding to a given function.

#[rust_ad::forward_autodiff]
fn multi(x: f32, y: f32) -> f32 {
    let a = x.powi(2i32);
    let b = x * 2f32;
    let c = 2f32 / y;
    let f = a + b + c;
    return f;
}
fn main() {
    let (f, der_x, der_y) = rust_ad::forward!(multi, 3f32, 5f32, 1f32, 1f32);
    assert_eq!(f, 15.4f32);
    assert_eq!(der_x, 8f32); // 2(x+1)
    assert_eq!(der_y, -0.08f32); // -2/y^2
}

This is just a procedural functional macro replacement for the declarative macro:

#[macro_export]
macro_rules! forward {
    ($f:ident,$($x:expr),*) => {{
        FORWARD_MODE_PREFIX$ident($($x,)*);
    }}
}

Since you can’t export declarative macros from a procedural macro crate.