Struct autograd::context::Context [] [src]

pub struct Context {
    pub variables: HashMap<Tensor, NdArray>,
    // some fields omitted
}

What is necessary to run computation graphs.

Context object is used to:

  • create shared variable tensors
  • create constant tensors
  • run computation graphs actually

When a computation graph is evaluated, all the variables/constants in the graph must be generated in 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.]);
assert!(ctx.variables.contains_key(v));
assert_eq!(ctx.variables.get(v).unwrap(), &ndarray::arr1(&[2., 2.]).into_dyn());

Fields

Variables generated in this context. Each array can be obtained by using corresponding Tensor object.

Methods

impl Context
[src]

[src]

Creates new context object.

[src]

Returns all variables in this context.

[src]

Skips arr's shape checking.

[src]

[src]

[src]

Trait Implementations

impl Clone for Context
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more