Value

Struct Value 

Source
pub struct Value<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§

Source§

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

Source

pub fn new(primal: V) -> Self

Create a detached value.

Source

pub fn primal(&self) -> &V

Borrow the primal value.

Source

pub fn requires_grad(&self) -> bool

Return whether this value participates in reverse-mode AD.

Source

pub fn with_requires_grad(self, enabled: bool) -> Self

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

Source

pub fn grad(&self) -> AdResult<Option<V::Tangent>>
where V::Tangent: Clone,

Read the accumulated leaf gradient, if available.

Source

pub fn zero_grad(&self) -> AdResult<()>

Clear the accumulated leaf gradient.

Source

pub fn backward(&self) -> AdResult<()>
where V::Tangent: Clone,

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

Source

pub fn backward_with_seed(&self, seed: V::Tangent) -> AdResult<()>
where V::Tangent: Clone,

Run reverse-mode backward with an explicit cotangent seed.

Source

pub fn grad_wrt_with_seed( &self, seed: V::Tangent, wrt: &[&Self], ) -> AdResult<Vec<Option<V::Tangent>>>
where V::Tangent: Clone,

Compute functional gradients with respect to the requested inputs.

Source

pub fn shares_reverse_graph(&self, other: &Self) -> 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
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, 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.