Skip to main content

grad

Function grad 

Source
pub fn grad<F>(f: F) -> impl Fn(&Array) -> Result<Array>
where F: Fn(&Array) -> Result<Array>,
Expand description

Returns the gradient function of a scalar function of one array.

Gradient functions can be differentiated again:

use nuvec_core::{Array, Result, grad, sin};

let d2 = grad(grad(|x: &Array| sin(x)));
let x = Array::scalar(1.0f32);
assert!((d2(&x)?.item::<f32>()? + 1f32.sin()).abs() < 1e-6); // −sin(x)