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
impl ResidualSpec
Sourcepub const fn none() -> ResidualSpec
pub const fn none() -> ResidualSpec
A mask declaring no tensor residuals (metadata-only rule).
Sourcepub const fn input(index: usize) -> ResidualSpec
pub const fn input(index: usize) -> ResidualSpec
A mask declaring one input index as a tensor residual.
Sourcepub const fn output(index: usize) -> ResidualSpec
pub const fn output(index: usize) -> ResidualSpec
A mask declaring one output index as a tensor residual.
Sourcepub const fn with_input(self, index: usize) -> ResidualSpec
pub const fn with_input(self, index: usize) -> ResidualSpec
Add one input index to this mask.
Sourcepub const fn with_output(self, index: usize) -> ResidualSpec
pub const fn with_output(self, index: usize) -> ResidualSpec
Add one output index to this mask.
Sourcepub const fn with_all_inputs(self) -> ResidualSpec
pub const fn with_all_inputs(self) -> ResidualSpec
Add every input index to this mask.
Sourcepub const fn with_all_outputs(self) -> ResidualSpec
pub const fn with_all_outputs(self) -> ResidualSpec
Add every output index to this mask.
Sourcepub const fn all_inputs() -> ResidualSpec
pub const fn all_inputs() -> ResidualSpec
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.
Sourcepub const fn all_outputs() -> ResidualSpec
pub const fn all_outputs() -> ResidualSpec
A mask declaring every output index as a tensor residual.
Sourcepub const fn declares_input(&self, index: usize) -> bool
pub const fn declares_input(&self, index: usize) -> bool
Whether input index is declared as a tensor residual.
Sourcepub const fn declares_output(&self, index: usize) -> bool
pub const fn declares_output(&self, index: usize) -> bool
Whether output index is declared as a tensor residual.
Trait Implementations§
Source§impl Clone for ResidualSpec
impl Clone for ResidualSpec
Source§fn clone(&self) -> ResidualSpec
fn clone(&self) -> ResidualSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ResidualSpec
Source§impl Debug for ResidualSpec
impl Debug for ResidualSpec
Source§impl Default for ResidualSpec
impl Default for ResidualSpec
Source§fn default() -> ResidualSpec
fn default() -> ResidualSpec
impl Eq for ResidualSpec
Source§impl PartialEq for ResidualSpec
impl PartialEq for ResidualSpec
Source§fn eq(&self, other: &ResidualSpec) -> bool
fn eq(&self, other: &ResidualSpec) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ResidualSpec
Auto Trait Implementations§
impl Freeze for ResidualSpec
impl RefUnwindSafe for ResidualSpec
impl Send for ResidualSpec
impl Sync for ResidualSpec
impl Unpin for ResidualSpec
impl UnsafeUnpin for ResidualSpec
impl UnwindSafe for ResidualSpec
Blanket Implementations§
impl<T> Boilerplate for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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