Skip to main content

ResidualSpec

Struct ResidualSpec 

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

Per-rule declaration of which primal inputs/outputs a transpose (VJP) rule reads as full tensor residuals versus which need only shape/dtype metadata.

The AD engine uses this to bound residual retention: an index not declared here may only be accessed through its metadata, never as a tensor operand. Indices are counted in primal-input order (input mask) and primal-output order (output mask).

§Examples

use tenferro_ops::ad::ResidualSpec;

// `add` needs no tensor residuals; `mul` keeps both operands.
let add = ResidualSpec::none();
let mul = ResidualSpec::input(0).with_input(1);
assert!(add.is_empty());
assert!(mul.declares_input(0) && mul.declares_input(1));
// Unary ops that reuse the forward output (e.g. exp) declare it.
let exp = ResidualSpec::output(0);
assert!(exp.declares_output(0));

Implementations§

Source§

impl ResidualSpec

Source

pub const fn none() -> Self

A mask declaring no tensor residuals (metadata-only rule).

Source

pub const fn input(index: usize) -> Self

A mask declaring one input index as a tensor residual.

Source

pub const fn output(index: usize) -> Self

A mask declaring one output index as a tensor residual.

Source

pub const fn with_input(self, index: usize) -> Self

Add one input index to this mask.

Source

pub const fn with_output(self, index: usize) -> Self

Add one output index to this mask.

Source

pub const fn with_all_inputs(self) -> Self

Add every input index to this mask.

Source

pub const fn with_all_outputs(self) -> Self

Add every output index to this mask.

Source

pub const fn all_inputs() -> Self

A mask declaring every input index as a tensor residual.

Used by rules whose required operand set depends on the active-input configuration (e.g. mul, concatenate, einsum), and by multi-op families whose individual ops collectively read any operand.

Source

pub const fn all_outputs() -> Self

A mask declaring every output index as a tensor residual.

Source

pub const fn declares_input(&self, index: usize) -> bool

Whether input index is declared as a tensor residual.

Source

pub const fn declares_output(&self, index: usize) -> bool

Whether output index is declared as a tensor residual.

Source

pub const fn is_empty(&self) -> bool

Whether this mask declares no tensor residuals.

Trait Implementations§

Source§

impl Clone for ResidualSpec

Source§

fn clone(&self) -> ResidualSpec

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 Copy for ResidualSpec

Source§

impl Debug for ResidualSpec

Source§

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

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

impl Default for ResidualSpec

Source§

fn default() -> ResidualSpec

Returns the “default value” for a type. Read more
Source§

impl Eq for ResidualSpec

Source§

impl PartialEq for ResidualSpec

Source§

fn eq(&self, other: &ResidualSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ResidualSpec

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> 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> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

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> 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 = 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.