Skip to main content

HybridTape

Struct HybridTape 

Source
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

Source

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.

Source

pub fn n_prelude_ops(&self) -> usize

Source

pub fn n_summands(&self) -> usize

Source

pub fn max_summand_ops(&self) -> usize

Source

pub fn total_local_ops(&self) -> usize

Source

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.

Source

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.

Source

pub fn root_value(&self, s: &Summand, local_vals: &[f64]) -> f64

Value at the summand root after forward_summand.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for HybridTape

Source§

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

Formats the value using the given formatter. Read more

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> 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.