[][src]Struct autograd::op::ComputeContext

pub struct ComputeContext<'t, 'v, T: Float> { /* fields omitted */ }

Context of an Op's computation phase.

Example

use autograd as ag;

// Implementing `Op` trait for `Sigmoid`.
struct Sigmoid;

impl<T: ag::Float> ag::op::Op<T> for Sigmoid {
    fn compute(
        &self,
        ctx: &mut ag::op::ComputeContext<T>,
    ) {
        // Getting the first input array.
        let x: &ag::NdArrayView<_> = &ctx.input(0);
        let half = T::from(0.5).unwrap();
        let y = x.mapv(move |a| ((a * half).tanh() * half) + half);
        // Put the computed result.
        ctx.append_output(y);
    }

    fn grad(&self, ctx: &mut ag::op::GradientContext<T>) { /* ... */ }
}

Implementations

impl<'g, 't, 'v, T: Float> ComputeContext<'t, 'v, T>[src]

pub fn input(&mut self, i: usize) -> NdArrayView<'v, T>[src]

Grabs the i th input array as a read-only array view.

Calling input(i) more than once causes panic.

pub fn input_mut(&mut self, i: usize) -> NdArrayViewMut<'v, T>[src]

Grabs the i th input array as a read-write array view.

Calling input_mut(i) more than once causes panic.

pub fn append_output_view(&mut self, y: NdArrayView<'v, T>)[src]

Appends an ndarray::ArrayView to the back of the output list of the current op.

NOTE: Implementor of Op::compute must not forget to call append_* as many as the number of its output in Op::compute, otherwise panic occurs.

pub fn append_output(&mut self, y: NdArray<T>)[src]

Appends an ndarray to the back of the output list of the current op.

NOTE: Implementor of Op::compute must not forget to call append_* as many as the number of its output in Op::compute, otherwise panic occurs.

pub fn append_empty_output(&mut self)[src]

Appends an empty result to the back of the output list of the current op.

For example, this is used for gradient-descent-optimizers.

NOTE: Implementor of Op::compute must not forget to call append_* as many as the number of its output in Op::compute, otherwise panic occurs.

pub fn set_error(&mut self, y: OpError)[src]

Marks this op's compute session as failed.

NOTE: After called this function, Op::compute should return early.

pub fn num_inputs(&self) -> usize[src]

Returns a number of input arrays.

Auto Trait Implementations

impl<'t, 'v, T> !RefUnwindSafe for ComputeContext<'t, 'v, T>

impl<'t, 'v, T> !Send for ComputeContext<'t, 'v, T>

impl<'t, 'v, T> !Sync for ComputeContext<'t, 'v, T>

impl<'t, 'v, T> Unpin for ComputeContext<'t, 'v, T> where
    T: Unpin

impl<'t, 'v, T> !UnwindSafe for ComputeContext<'t, 'v, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,