Skip to main content

Adjoints

Struct Adjoints 

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

The recorded reverse-mode result: one gradient symbol per wrt entry, in wrt order, paired with the entry it differentiates.

Tape::differentiate and Tape::vjp return this carrier instead of bare symbols because their product exists to be paired — each gradient with its wrt entry for Run::recorded_gradients, and all of them with the target for a training request’s roots. Holding the pairs makes misordered pairs unrepresentable: no consumer rebuilds the pairing by parallel-vector discipline.

The carrier is plain data — detached symbols, no tape borrow — so it survives sealing the tape and crosses threads like any Symbol.

Implementations§

Source§

impl Adjoints

Source

pub fn target(&self) -> Symbol

Returns the differentiated value: the scalar loss for Tape::differentiate, the seeded value — any shape — for Tape::vjp.

Source

pub fn pairs(&self) -> &[(Symbol, Symbol)]

Returns the (wrt, gradient) pairs in wrt order.

Source

pub fn wrt(&self) -> impl Iterator<Item = Symbol> + '_

Returns the wrt entries in their original order.

Source

pub fn gradients(&self) -> impl Iterator<Item = Symbol> + '_

Returns the gradient symbols in wrt order.

Source

pub fn of(&self, wrt: Symbol) -> Symbol

Returns the gradient recorded for wrt.

§Panics

Panics if wrt was not an entry of the transform that produced this carrier.

Source

pub fn roots(&self) -> impl Iterator<Item = Symbol> + '_

Returns the training roots: the target, then every gradient in wrt order — the exact root list a compiled training plan wants, so Entry::roots(adjoints.roots()) replaces the hand-chained loss-plus-gradients idiom.

Source

pub fn map_gradients(&self, rewrite: impl FnMut(Symbol) -> Symbol) -> Self

Returns a new carrier with each gradient symbol rewritten by rewrite, pairing and target preserved.

The emission consumers use this to substitute same-shape reshape aliases for the raw gradient nodes — pinning the emitted result order — without ever holding gradients as a bare list.

Source§

impl Adjoints

Source

pub fn to_html(&self, theme: Theme) -> String

Renders the pairing as a self-contained HTML card: the target, then each wrt → gradient pair in wrt order.

Source

pub fn evcxr_display(&self)

Displays the adjoints when they are the last expression in an Evcxr cell.

Trait Implementations§

Source§

impl Clone for Adjoints

Source§

fn clone(&self) -> Adjoints

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Adjoints

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Detach for Adjoints

Identity: a differentiation product is already detached names.

Source§

type Detached = Adjoints

The detached form of these names.
Source§

fn detach(self) -> Adjoints

Detaches the names.

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <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.