[−][src]Struct autograd::op::ComputeContext
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,
T: Unpin,
impl<'t, 'v, T> !UnwindSafe for ComputeContext<'t, 'v, T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,