pub struct Tensor<S, GradFn> { /* private fields */ }Expand description
Implementations
sourceimpl<S, F> Tensor<S, F>where
S: Ones + GetShape,
F: Backward<S>,
impl<S, F> Tensor<S, F>where
S: Ones + GetShape,
F: Backward<S>,
sourcepub fn backward(self)
pub fn backward(self)
Tensor backward
Calls backward function on Tensor. Computes gradient of all Variables that were used as inputs to operations that resulted in creation of this Tensor. This function accumulates gradients in those Variables. If you want to clear Variable’s gradients, call Parameters::zero_grad() on that Variable.
Example
let x = cpu::Buffer::cfrom([2., 3., 1.]).with_grad();
let y = x.exp();y is now Tensor, so we can call backward on it.
y.backward();and the gradient of Variable x will now get populated:
assert_eq!(x.grad().to_vec(), x.data().clone().exp().to_vec());sourceimpl<S, GradFn> Tensor<S, GradFn>
impl<S, GradFn> Tensor<S, GradFn>
sourcepub fn register_hook<HOOK>(
self,
hook: HOOK
) -> Tensor<S, GradHookT<GradFn, HOOK>>where
HOOK: FnOnce(S),
pub fn register_hook<HOOK>(
self,
hook: HOOK
) -> Tensor<S, GradHookT<GradFn, HOOK>>where
HOOK: FnOnce(S),
Add custom FnOnce closure that will receive Buffer’s gradient during backward pass The hook is stored in the result, so make sure to do all operations on this result, otherwise your hook will not be called.
Trait Implementations
sourceimpl<'g, XS, YS, XF> Add<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Add<YS> + DType,
YS: Clone + DType,
impl<'g, XS, YS, XF> Add<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Add<YS> + DType,
YS: Clone + DType,
sourceimpl<'g, XS, YS, YF> Add<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Add<YS>,
YS: 'g,
impl<'g, XS, YS, YF> Add<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Add<YS>,
YS: 'g,
sourceimpl<XS, YS, XF, YF> Add<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Add<YS> + DType,
YS: DType,
impl<XS, YS, XF, YF> Add<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Add<YS> + DType,
YS: DType,
sourceimpl<S, S2, GradFn> ConvertFrom<Tensor<S2, GradFn>> for Tensor<S, GradFn>where
S: ConvertFrom<S2>,
impl<S, S2, GradFn> ConvertFrom<Tensor<S2, GradFn>> for Tensor<S, GradFn>where
S: ConvertFrom<S2>,
Conversions between devices and types
sourceimpl<S, GradFn> Display for Tensor<S, GradFn>where
S: Display,
GradFn: Debug,
impl<S, GradFn> Display for Tensor<S, GradFn>where
S: Display,
GradFn: Debug,
Display Tensor
Shows Tensor and it’s grad_fn.
sourceimpl<'g, XS, YS, XF> Div<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Div<YS> + DType,
YS: Clone + DType,
<XS as Div<YS>>::Output: Clone,
impl<'g, XS, YS, XF> Div<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Div<YS> + DType,
YS: Clone + DType,
<XS as Div<YS>>::Output: Clone,
sourceimpl<'g, XS, YS, YF> Div<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Div<YS>,
YS: Clone,
<XS as Div<YS>>::Output: Clone,
impl<'g, XS, YS, YF> Div<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Div<YS>,
YS: Clone,
<XS as Div<YS>>::Output: Clone,
sourceimpl<XS, YS, XF, YF> Div<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Div<YS>,
YS: Clone,
<XS as Div<YS>>::Output: Clone,
impl<XS, YS, XF, YF> Div<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Div<YS>,
YS: Clone,
<XS as Div<YS>>::Output: Clone,
sourceimpl<'g, XS, XF, YS> MatMul<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + MatMul<YS>,
YS: Clone,
impl<'g, XS, XF, YS> MatMul<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + MatMul<YS>,
YS: Clone,
sourceimpl<'g, XS, YS, YF> MatMul<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: Clone,
impl<'g, XS, YS, YF> MatMul<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: Clone,
sourceimpl<XS, YS, XF, YF> MatMul<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Clone + MatMul<YS>,
YS: Clone,
impl<XS, YS, XF, YF> MatMul<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Clone + MatMul<YS>,
YS: Clone,
sourceimpl<'g, XS, YS, XF> Mul<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Mul<YS>,
YS: Clone,
impl<'g, XS, YS, XF> Mul<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Mul<YS>,
YS: Clone,
sourceimpl<'g, XS, YS, F> Mul<Tensor<YS, F>> for &'g Variable<XS>where
XS: Clone + Mul<YS>,
YS: Clone,
impl<'g, XS, YS, F> Mul<Tensor<YS, F>> for &'g Variable<XS>where
XS: Clone + Mul<YS>,
YS: Clone,
sourceimpl<XS, YS, XF, YF> Mul<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Clone + Mul<YS>,
YS: Clone,
impl<XS, YS, XF, YF> Mul<Tensor<YS, YF>> for Tensor<XS, XF>where
XS: Clone + Mul<YS>,
YS: Clone,
sourceimpl<S: Ord, GradFn: Ord> Ord for Tensor<S, GradFn>
impl<S: Ord, GradFn: Ord> Ord for Tensor<S, GradFn>
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<S: PartialEq, GradFn: PartialEq> PartialEq<Tensor<S, GradFn>> for Tensor<S, GradFn>
impl<S: PartialEq, GradFn: PartialEq> PartialEq<Tensor<S, GradFn>> for Tensor<S, GradFn>
sourceimpl<S: PartialOrd, GradFn: PartialOrd> PartialOrd<Tensor<S, GradFn>> for Tensor<S, GradFn>
impl<S: PartialOrd, GradFn: PartialOrd> PartialOrd<Tensor<S, GradFn>> for Tensor<S, GradFn>
sourcefn partial_cmp(&self, other: &Tensor<S, GradFn>) -> Option<Ordering>
fn partial_cmp(&self, other: &Tensor<S, GradFn>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresourceimpl<'g, XS, YS, XF> Pow<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Pow<YS> + Ln,
YS: Clone + Mul<<XS as Pow<YS>>::Output>,
<XS as Pow<YS>>::Output: Clone,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Mul<<XS as Ln>::Output>,
impl<'g, XS, YS, XF> Pow<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Pow<YS> + Ln,
YS: Clone + Mul<<XS as Pow<YS>>::Output>,
<XS as Pow<YS>>::Output: Clone,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Mul<<XS as Ln>::Output>,
sourceimpl<S, S2, F> Pow<S2> for Tensor<S, F>where
S: Clone + Pow<S2>,
S2: DType + Clone + Mul<<S as Pow<S2>>::Output>,
<S as Pow<S2>>::Output: Clone,
<S2 as Mul<<S as Pow<S2>>::Output>>::Output: Div<S>,
impl<S, S2, F> Pow<S2> for Tensor<S, F>where
S: Clone + Pow<S2>,
S2: DType + Clone + Mul<<S as Pow<S2>>::Output>,
<S as Pow<S2>>::Output: Clone,
<S2 as Mul<<S as Pow<S2>>::Output>>::Output: Div<S>,
sourceimpl<S, XF, YF> Pow<Tensor<S, YF>> for Tensor<S, XF>where
S: Clone + Mul<Output = S> + Div<Output = S> + Pow<Output = S> + Ln<Output = S>,
impl<S, XF, YF> Pow<Tensor<S, YF>> for Tensor<S, XF>where
S: Clone + Mul<Output = S> + Div<Output = S> + Pow<Output = S> + Ln<Output = S>,
sourceimpl<'g, XS, YS, YF> Pow<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Pow<YS> + Ln,
YS: Clone + Mul<<XS as Pow<YS>>::Output>,
<XS as Pow<YS>>::Output: Clone,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Mul<<XS as Ln>::Output>,
impl<'g, XS, YS, YF> Pow<Tensor<YS, YF>> for &'g Variable<XS>where
XS: Clone + Pow<YS> + Ln,
YS: Clone + Mul<<XS as Pow<YS>>::Output>,
<XS as Pow<YS>>::Output: Clone,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Mul<<XS as Ln>::Output>,
sourceimpl<'g, XS, YS, XF> Sub<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Sub<YS>,
YS: Clone,
impl<'g, XS, YS, XF> Sub<&'g Variable<YS>> for Tensor<XS, XF>where
XS: Clone + Sub<YS>,
YS: Clone,
impl<S: Eq, GradFn: Eq> Eq for Tensor<S, GradFn>
impl<S, GradFn> StructuralEq for Tensor<S, GradFn>
impl<S, GradFn> StructuralPartialEq for Tensor<S, GradFn>
Auto Trait Implementations
impl<S, GradFn> RefUnwindSafe for Tensor<S, GradFn>where
GradFn: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, GradFn> Send for Tensor<S, GradFn>where
GradFn: Send,
S: Send,
impl<S, GradFn> Sync for Tensor<S, GradFn>where
GradFn: Sync,
S: Sync,
impl<S, GradFn> Unpin for Tensor<S, GradFn>where
GradFn: Unpin,
S: Unpin,
impl<S, GradFn> UnwindSafe for Tensor<S, GradFn>where
GradFn: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more