Skip to main content

jvp

Function jvp 

Source
pub fn jvp<P, O, F, R>(f: F, primals: &P, tangents: &P) -> Result<(O, O)>
where P: Tree, O: Tree, F: FnOnce(&P) -> R, R: IntoResult<Ok = O>,
Expand description

Forward mode over trees: f’s output at primals and the Jacobian-vector product for tangents (a tree like primals; tangents of leaves that are not differentiated are ignored), as a tree like the output.

use nuvec_core::{Array, Result, jvp};

let (y, t) = jvp(|x: &Array| x.sin(), &Array::from(0.0f32), &Array::from(1.0f32))?;
assert_eq!((y.item::<f32>()?, t.item::<f32>()?), (0.0, 1.0)); // cos(0)