Skip to main content

GradMap

Struct GradMap 

Source
pub struct GradMap { /* private fields */ }
Expand description

Map from forward-graph node IDs to the IDs of their accumulated backward-graph gradient nodes, returned by NodeHandle::backward.

All gradient nodes live on the same graph as the forward nodes. Getting a gradient by calling GradMap::get returns a new NodeHandle handle pointing at the gradient node so callers can realize it, plug it into further computation, or back-propagate through it again.

Implementations§

Source§

impl GradMap

Source

pub fn get(&self, forward: &NodeHandle) -> Option<NodeHandle>

Get the gradient tensor for a forward tensor from the same graph.

Returns None if the forward tensor was not reachable from the root passed to backward (i.e. not part of the computation being differentiated).

§Panics

Panics if any operand belongs to a different Graph than the one this builder is building into. Operand identity is graph-scoped and checked by pointer identity (Arc::ptr_eq), which cannot alias; the panic is deliberate and replaces the hang a cross-graph handle used to produce. Build every operand from one graph, or use a Result-returning entry point where one exists.

Source

pub fn len(&self) -> usize

Number of forward nodes that have a recorded gradient.

Source

pub fn is_empty(&self) -> bool

Whether this map has no gradients (e.g. a backward over a lone const).

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V