Value

Struct Value 

pub struct Value<V>
where V: Differentiable,
{ /* private fields */ }
Expand description

Public value handle for reverse-mode AD.

Value exposes a torch-like surface while keeping graph ownership hidden. Internally it carries either a leaf gradient sink or an edge into a reverse graph.

Implementations§

§

impl<V> Value<V>
where V: Differentiable + 'static,

pub fn new(primal: V) -> Value<V>

Create a detached value.

pub fn primal(&self) -> &V

Borrow the primal value.

pub fn requires_grad(&self) -> bool

Return whether this value participates in reverse-mode AD.

pub fn with_requires_grad(self, enabled: bool) -> Value<V>

Return a new value handle with gradient tracking enabled or disabled.

pub fn grad( &self, ) -> Result<Option<<V as Differentiable>::Tangent>, AutodiffError>
where <V as Differentiable>::Tangent: Clone,

Read the accumulated leaf gradient, if available.

pub fn zero_grad(&self) -> Result<(), AutodiffError>

Clear the accumulated leaf gradient.

pub fn backward(&self) -> Result<(), AutodiffError>
where <V as Differentiable>::Tangent: Clone,

Run reverse-mode backward with the default scalar cotangent seed.

pub fn backward_with_seed( &self, seed: <V as Differentiable>::Tangent, ) -> Result<(), AutodiffError>
where <V as Differentiable>::Tangent: Clone,

Run reverse-mode backward with an explicit cotangent seed.

pub fn grad_wrt_with_seed( &self, seed: <V as Differentiable>::Tangent, wrt: &[&Value<V>], ) -> Result<Vec<Option<<V as Differentiable>::Tangent>>, AutodiffError>
where <V as Differentiable>::Tangent: Clone,

Compute functional gradients with respect to the requested inputs.

pub fn shares_reverse_graph(&self, other: &Value<V>) -> bool

Return whether self and other share any reachable reverse graph.

Auto Trait Implementations§

§

impl<V> !Freeze for Value<V>

§

impl<V> RefUnwindSafe for Value<V>
where V: RefUnwindSafe,

§

impl<V> Send for Value<V>
where V: Sync + Send, <V as Differentiable>::Tangent: Send,

§

impl<V> Sync for Value<V>
where V: Sync + Send, <V as Differentiable>::Tangent: Send,

§

impl<V> Unpin for Value<V>

§

impl<V> UnwindSafe for Value<V>
where V: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T