Function autograd::run [−][src]
Expand description
Creates a scope for a computation graph.
This is the preferred way to create Graph instances.
use autograd as ag;
use ag::ndarray;
let grad = ag::run(|g| {
let x = g.placeholder(&[]);
let y = g.placeholder(&[]);
let z = 2.*x*x + 3.*y + 1.;
// dz/dx (symbolic):
let grad = &g.grad(&[z], &[x])[0];
// Evaluate dz/dx when x=3:
grad.eval(&[x.given(ndarray::arr0(3.0).view())]).unwrap()
});
assert_eq!(grad, ndarray::arr0(12.0).into_dyn());