Struct autograd::context::Context
[−]
[src]
pub struct Context { pub variables: HashMap<Tensor, NdArray>, pub outputs: HashMap<Tensor, Result<NdArray, OpComputeErrorStatus>>, }
What is necessary to run computation graphs.
Context
object is used:
- to create shared variable tensors
- to create constant tensors
- to run computation graphs actually
When a computation graph is evaluated, all the variables/constants in the graph must be what derives from the same context; otherwise will panic.
extern crate ndarray; extern crate autograd as ag; // new Context let mut ctx = ag::Context::new(); let ref x = ag::placeholder(&[2]); // make shared variable in the context let ref v = ag::variable(ndarray::arr1(&[2., 2.]), &mut ctx); let ref b = ag::ones(&[2]); let ref z = x + v + b; // fills placeholder ctx.feed_input(x, ndarray::arr1(&[1., 1.])); // eval assert_eq!(z.eval(&mut ctx).as_slice().unwrap(), &[4., 4.]);
Fields
variables: HashMap<Tensor, NdArray>
outputs: HashMap<Tensor, Result<NdArray, OpComputeErrorStatus>>
Methods
impl Context
[src]
fn new() -> Context
[src]
Creates new context object.
fn list_vars(&self) -> Vec<&Tensor>
[src]
Returns all variables in this context.
fn feed_input_unchecked<T>(&mut self, placeholder: &Tensor, arr: Array<f32, T>) where
T: Dimension,
[src]
T: Dimension,
Skips arr
's shape checking.
fn feed_input<T>(&mut self, placeholder: &Tensor, arr: Array<f32, T>) where
T: Dimension,
[src]
T: Dimension,