pub fn jvp(
f: impl FnOnce(&[Array]) -> Result<Vec<Array>>,
primals: &[Array],
tangents: &[Array],
) -> Result<(Vec<Array>, Vec<Array>)>Expand description
Forward mode: runs f on primals and returns its outputs together with the
Jacobian-vector product, one tangent per output, for one tangent per primal.
use nuvec_core::{Array, Result, jvp, sin};
let x = Array::scalar(0.0f32);
let (_, tangents) = jvp(|xs| Ok(vec![sin(&xs[0])?]), &[x], &[Array::scalar(1.0f32)])?;
assert_eq!(tangents[0].item::<f32>()?, 1.0); // cos(0)