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 input(index: usize) -> Self
pub const fn input(index: usize) -> Self
A mask declaring one input index as a tensor residual.
Sourcepub const fn output(index: usize) -> Self
pub const fn output(index: usize) -> Self
A mask declaring one output index as a tensor residual.
Sourcepub const fn with_input(self, index: usize) -> Self
pub const fn with_input(self, index: usize) -> Self
Add one input index to this mask.
Sourcepub const fn with_output(self, index: usize) -> Self
pub const fn with_output(self, index: usize) -> Self
Add one output index to this mask.
Sourcepub const fn with_all_inputs(self) -> Self
pub const fn with_all_inputs(self) -> Self
Add every input index to this mask.
Sourcepub const fn with_all_outputs(self) -> Self
pub const fn with_all_outputs(self) -> Self
Add every output index to this mask.
Sourcepub const fn all_inputs() -> Self
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.
Sourcepub const fn all_outputs() -> Self
pub const fn all_outputs() -> Self
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 ==.