Function autograd::ops::variable [] [src]

pub fn variable<T>(arr: Array<f32, T>, ctx: &mut Context) -> Tensor where
    T: Dimension

Creates a shared variable tensor from rust-ndarray's array object.

Same as Context::variable.

The shared variable behaves like any other tensors, except that it can be optimized with gradient descent methods implemented in autograd::gradient_descent. For the usages, see https://github.com/perrier1034/rust-autograd/tree/master/examples

extern crate ndarray;
extern crate autograd as ag;

let mut ctx = ag::Context::new();
let ref x: ag::Tensor = ag::variable(ndarray::arr1(&[2.]), &mut ctx);
let ref y: ag::Tensor = 3 * x;

assert_eq!(6., y.eval(&mut ctx)[0]);