pub struct HybridTape {
pub prelude: Vec<TapeOp>,
pub summands: Vec<Summand>,
}Fields§
§prelude: Vec<TapeOp>Shared CSE bodies. Slot indices in SummandOp::Shared
point here; this Vec is built bottom-up by build_recursive,
so operand indices are always less than the consumer’s
index (topo in ascending order).
summands: Vec<Summand>Implementations§
Source§impl HybridTape
impl HybridTape
Sourcepub fn build_multi(exprs: &[Expr]) -> Self
pub fn build_multi(exprs: &[Expr]) -> Self
Build hybrid tape from a list of root expressions. CSE bodies referenced from ≥ 2 roots are promoted into the shared prelude; CSEs touched by only one root are inlined into that summand’s local ops.
pub fn n_prelude_ops(&self) -> usize
pub fn n_summands(&self) -> usize
pub fn max_summand_ops(&self) -> usize
pub fn total_local_ops(&self) -> usize
Sourcepub fn forward_prelude(&self, x: &[f64], prelude_vals: &mut [f64])
pub fn forward_prelude(&self, x: &[f64], prelude_vals: &mut [f64])
Forward sweep over the shared prelude. prelude_vals must
have length n_prelude_ops.
Sourcepub fn forward_summand(
&self,
s: &Summand,
x: &[f64],
prelude_vals: &[f64],
local_vals: &mut [f64],
)
pub fn forward_summand( &self, s: &Summand, x: &[f64], prelude_vals: &[f64], local_vals: &mut [f64], )
Forward sweep over one summand. local_vals must hold at
least s.ops.len() entries.
Sourcepub fn root_value(&self, s: &Summand, local_vals: &[f64]) -> f64
pub fn root_value(&self, s: &Summand, local_vals: &[f64]) -> f64
Value at the summand root after forward_summand.
Sourcepub fn gradient_summand(
&self,
s: &Summand,
prelude_vals: &[f64],
local_vals: &[f64],
seed: f64,
grad: &mut [f64],
local_adj: &mut [f64],
prelude_adj: &mut [f64],
)
pub fn gradient_summand( &self, s: &Summand, prelude_vals: &[f64], local_vals: &[f64], seed: f64, grad: &mut [f64], local_adj: &mut [f64], prelude_adj: &mut [f64], )
Reverse-mode gradient for one summand. Walks local_reach
in reverse — propagating adjoints into prelude_adj at
Shared boundaries — and then walks prelude_reach in
reverse to land contributions in grad. Scratch arrays
local_adj and prelude_adj are zeroed only at the slots
actually touched.
Sourcepub fn hessian_summand(
&self,
s: &Summand,
prelude_vals: &[f64],
local_vals: &[f64],
weight: f64,
hess_map: &HashMap<(usize, usize), usize>,
values: &mut [f64],
local_dot: &mut [f64],
local_adj: &mut [f64],
local_adj_dot: &mut [f64],
prelude_dot: &mut [f64],
prelude_adj: &mut [f64],
prelude_adj_dot: &mut [f64],
)
pub fn hessian_summand( &self, s: &Summand, prelude_vals: &[f64], local_vals: &[f64], weight: f64, hess_map: &HashMap<(usize, usize), usize>, values: &mut [f64], local_dot: &mut [f64], local_adj: &mut [f64], local_adj_dot: &mut [f64], prelude_dot: &mut [f64], prelude_adj: &mut [f64], prelude_adj_dot: &mut [f64], )
Forward-over-reverse Hessian for one summand with multiplier
weight. Iterates over s.all_vars; for each seed variable
j: (1) forward tangent through prelude_reach then local_reach,
(2) reverse over local (folding adj/adj_dot into prelude at
Shared boundaries), (3) reverse over prelude_reach. All
scratch buffers are zeroed only at the touched slots inside
the per-j loop.
Sourcepub fn hessian_sparsity_all(&self) -> BTreeSet<(usize, usize)>
pub fn hessian_sparsity_all(&self) -> BTreeSet<(usize, usize)>
Structural Hessian sparsity over the whole hybrid tape: every pair the prelude or any summand can produce.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HybridTape
impl RefUnwindSafe for HybridTape
impl Send for HybridTape
impl Sync for HybridTape
impl Unpin for HybridTape
impl UnsafeUnpin for HybridTape
impl UnwindSafe for HybridTape
Blanket Implementations§
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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