pub struct Variable<S> { /* private fields */ }Expand description
Variable
Variable holds data and it’s gradient.
Implementations
sourceimpl<S> Variable<S>
impl<S> Variable<S>
sourcepub fn backward(&mut self)where
S: Add<i32, Output = S> + Zeros,
pub fn backward(&mut self)where
S: Add<i32, Output = S> + Zeros,
Variable backward
Calls backward function on Variable. This results in Variable’s gradient being increased by one. We take Variable with mutable reference, so that we have exclusive access during mutation of gradient.
x.grad += 1;Example
use zyx::prelude::*;
let mut x = 3.with_grad();
x.backward();
assert_eq!(x.grad(), &1);And gradient gets accumulated if we call backward again.
x.backward();
assert_eq!(x.grad(), &2);sourceimpl<S> Variable<S>
impl<S> Variable<S>
sourcepub fn register_hook<HOOK>(
&self,
hook: HOOK
) -> Tensor<S, GradHookV<'_, S, HOOK>>where
S: Clone,
HOOK: FnOnce(S),
pub fn register_hook<HOOK>(
&self,
hook: HOOK
) -> Tensor<S, GradHookV<'_, S, HOOK>>where
S: Clone,
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> Add<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Add<YS>,
YS: Clone,
impl<'g, XS, YS> Add<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Add<YS>,
YS: Clone,
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<S, S2> ConvertFrom<Variable<S2>> for Variable<S>where
S: ConvertFrom<S2>,
S2: Clone,
impl<S, S2> ConvertFrom<Variable<S2>> for Variable<S>where
S: ConvertFrom<S2>,
S2: Clone,
Conversions between devices and types
sourceimpl<S> Display for Variable<S>where
S: Display,
impl<S> Display for Variable<S>where
S: Display,
Display Variable
Shows Variable and it’s gradient.
sourceimpl<'g, XS, YS> Div<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Div<YS> + DType,
YS: Clone + DType,
<XS as Div<YS>>::Output: Clone,
impl<'g, XS, YS> Div<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Div<YS> + DType,
YS: Clone + DType,
<XS as Div<YS>>::Output: Clone,
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<'g, XS, YS> MatMul<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: Clone,
impl<'g, XS, YS> MatMul<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: 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<'g, XS, YS> MatMul<YS> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: Clone + DType,
impl<'g, XS, YS> MatMul<YS> for &'g Variable<XS>where
XS: Clone + MatMul<YS>,
YS: Clone + DType,
sourceimpl<'g, XS, YS> Mul<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Mul<YS>,
YS: Clone,
impl<'g, XS, YS> Mul<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Mul<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<S> Parameters for &mut Variable<S>where
S: Clone + Mul<f64> + Sub<<S as Mul<f64>>::Output, Output = S>,
impl<S> Parameters for &mut Variable<S>where
S: Clone + Mul<f64> + Sub<<S as Mul<f64>>::Output, Output = S>,
sourcefn step<Optim>(self, optim: &Optim)where
Optim: Optimizer,
fn step<Optim>(self, optim: &Optim)where
Optim: Optimizer,
Update Parameter’s data
sourcefn zero_grad(&mut self)
fn zero_grad(&mut self)
Zero Parameter’s gradients
sourceimpl<'g, XS, YS> Pow<&'g Variable<YS>> 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> Pow<&'g Variable<YS>> 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> 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<'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> Pow<YS> for &'g Variable<XS>where
XS: Clone + Pow<YS>,
YS: Clone + DType + Mul<<XS as Pow<YS>>::Output>,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Clone,
impl<'g, XS, YS> Pow<YS> for &'g Variable<XS>where
XS: Clone + Pow<YS>,
YS: Clone + DType + Mul<<XS as Pow<YS>>::Output>,
<YS as Mul<<XS as Pow<YS>>::Output>>::Output: Div<XS>,
<XS as Pow<YS>>::Output: Clone,
sourceimpl<'g, XS, YS> Sub<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Sub<YS>,
YS: Clone,
impl<'g, XS, YS> Sub<&'g Variable<YS>> for &'g Variable<XS>where
XS: Clone + Sub<YS>,
YS: Clone,
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,
Auto Trait Implementations
impl<S> !RefUnwindSafe for Variable<S>
impl<S> Send for Variable<S>where
S: Send,
impl<S> !Sync for Variable<S>
impl<S> Unpin for Variable<S>where
S: Unpin,
impl<S> UnwindSafe for Variable<S>where
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