[][src]Struct melange::backprop::variable::Variable

pub struct Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>(_);

Core type of backprop module that represents a node in the computation graph. It contains a combination of Rc and RefCell to allow mutable reference counting of the actual BackpropNodes.

Implementations

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback> where
    Tensor<T, S, Contiguous, Lgrad, P>: Clone
[src]

pub fn grad(&self) -> Option<Tensor<T, S, Contiguous, Lgrad, P>>[src]

impl<T, S, C, L, P, Cback, Lback, Pback> Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape,
    L: for<'a> Layout<'a, T>,
    P: StaticAllocationPolicy<T, S>, 
[src]

pub fn backward(&self, grad: Tensor<T, S, Cback, Lback, Pback>) where
    T: Send + Sync + Copy + AddAssign,
    Lback: for<'a> Layout<'a, T>, 
[src]

Add given gradient to the retained gradient if needed and backpropagate using the closure.

To initiate backpropagation a tensor full of ones is a good choice.

pub fn new(tensor: Tensor<T, S, C, L, P>, require_grad: bool) -> Self[src]

Create a new variable that retains its gradient if require_grad is true by moving the given tensor.

impl<T, S, C, L, P, Cback, Lback, Pback> Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    L: for<'a> Layout<'a, T>,
    P: DynamicAllocationPolicy<T>, 
[src]

pub fn backward_dynamic(&self, grad: Tensor<T, S, Cback, Lback, Pback>) where
    T: Send + Sync + Copy + AddAssign,
    P: DynamicAllocationPolicy<T>,
    P::Layout: for<'a> Layout<'a, T>,
    Lback: for<'a> Layout<'a, T>, 
[src]

Dynamic version of the backpropagation function. Name has to be different because specialization is not yet available in stable Rust.

Add given gradient to the retained gradient if needed and backpropagate using the closure.

To initiate backpropagation a tensor full of ones is a good choice.

Methods from Deref<Target = Rc<RefCell<BackpropNode<T, S, C, L, P, Lgrad, Cback, Lback, Pback>>>>

Trait Implementations

impl<T, S, C, L, P, Cback, Lback, Pback> Add<T> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Add<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the + operator.

impl<T, S, C, L, P, Cback, Lback, Pback, Crhs, Lrhs, Prhs> Add<Variable<T, S, Crhs, Lrhs, Prhs, <Prhs as StaticAllocationPolicy<T, S>>::Layout, Contiguous, <Pback as StaticAllocationPolicy<T, S>>::Layout, Pback>> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Crhs: 'static,
    Prhs: StaticAllocationPolicy<T, S> + 'static,
    Prhs::Layout: for<'a> Layout<'a, T> + 'static,
    Lrhs: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Add<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the + operator.

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> Clone for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>[src]

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> Debug for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback> where
    T: Debug,
    S: Debug,
    C: Debug,
    L: Debug,
    P: Debug,
    Lgrad: Debug
[src]

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> Deref for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>[src]

type Target = Rc<RefCell<BackpropNode<T, S, C, L, P, Lgrad, Cback, Lback, Pback>>>

The resulting type after dereferencing.

impl<T, S, C, L, P, Cback, Lback, Pback> Div<T> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Div<Output = T> + Mul<Output = T> + Ring + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the / operator.

impl<T, S, C, L, P, Cback, Lback, Pback, Crhs, Lrhs, Prhs> Div<Variable<T, S, Crhs, Lrhs, Prhs, <Prhs as StaticAllocationPolicy<T, S>>::Layout, Contiguous, <Pback as StaticAllocationPolicy<T, S>>::Layout, Pback>> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Crhs: 'static,
    Prhs: StaticAllocationPolicy<T, S> + 'static,
    Prhs::Layout: for<'a> Layout<'a, T> + 'static,
    Lrhs: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + DivAssign + Div<Output = T> + Mul<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the / operator.

impl<T, S, C, L, P, Cback, Lback, Pback> Mul<T> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Mul<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the * operator.

impl<T, S, C, L, P, Cback, Lback, Pback, Crhs, Lrhs, Prhs> Mul<Variable<T, S, Crhs, Lrhs, Prhs, <Prhs as StaticAllocationPolicy<T, S>>::Layout, Contiguous, <Pback as StaticAllocationPolicy<T, S>>::Layout, Pback>> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Crhs: 'static,
    Prhs: StaticAllocationPolicy<T, S> + 'static,
    Prhs::Layout: for<'a> Layout<'a, T> + 'static,
    Lrhs: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + MulAssign + Mul<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the * operator.

impl<T, S, C, L, P, Cback, Lback, Pback> Sub<T> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Sub<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the - operator.

impl<T, S, C, L, P, Cback, Lback, Pback, Crhs, Lrhs, Prhs> Sub<Variable<T, S, Crhs, Lrhs, Prhs, <Prhs as StaticAllocationPolicy<T, S>>::Layout, Contiguous, <Pback as StaticAllocationPolicy<T, S>>::Layout, Pback>> for Variable<T, S, C, L, P, P::Layout, Cback, Lback, Pback> where
    S: StaticShape + 'static,
    C: 'static,
    L: for<'a> Layout<'a, T> + 'static,
    P: StaticAllocationPolicy<T, S> + 'static,
    P::Layout: for<'a> Layout<'a, T> + 'static,
    Crhs: 'static,
    Prhs: StaticAllocationPolicy<T, S> + 'static,
    Prhs::Layout: for<'a> Layout<'a, T> + 'static,
    Lrhs: for<'a> Layout<'a, T> + 'static,
    Cback: 'static,
    Lback: for<'a> Layout<'a, T> + for<'a> LayoutMut<'a, T> + 'static,
    Pback: StaticAllocationPolicy<T, S> + 'static,
    Pback::Layout: for<'a> Layout<'a, T> + 'static,
    T: Send + Sync + Copy + AddAssign + Sub<Output = T> + Ring + Neg<Output = T> + Mul<Output = T> + 'static, 
[src]

type Output = Variable<T, S, Contiguous, P::Layout, P, P::Layout, Cback, Lback, Pback>

The resulting type after applying the - operator.

Auto Trait Implementations

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> !RefUnwindSafe for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> !Send for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> !Sync for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> Unpin for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>

impl<T, S, C, L, P, Lgrad, Cback, Lback, Pback> !UnwindSafe for Variable<T, S, C, L, P, Lgrad, Cback, Lback, Pback>

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> Pointable for T

type Init = T

The type for initializers.

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

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.