Skip to main content

Tower2

Struct Tower2 

Source
pub struct Tower2<const K: usize> {
    pub v: f64,
    pub g: [f64; K],
    pub h: [[f64; K]; K],
}
Expand description

Truncated SECOND-order multivariate Taylor scalar in K variables.

This is the value/gradient/Hessian-only sibling of Tower4. Every channel it carries (v, g, h) is computed by the SAME formulas Tower4 uses for those orders, so for any program written over both towers the order-≤2 outputs are bit-identical: the order-2 Leibniz and Faà-di-Bruno terms read only the order-≤2 channels of their inputs (see Tower4::mul / Tower4::compose_unaryout.h never touches t3 or t4), so dropping the third/fourth tensors cannot perturb the value, gradient, or Hessian.

It exists purely for performance: an inner Newton step (and the value-only ρ-homotopy pre-warm) needs at most curvature, never the outer-κ/ψ third/fourth derivatives. Evaluating a row likelihood over Tower2 skips the K⁴ fourth-tensor product/composition arithmetic that dominates the cold marginal-slope fit, while returning the exact same (v, g, h).

Fields§

§v: f64

Value ℓ.

§g: [f64; K]

Gradient ∂ℓ/∂p_a.

§h: [[f64; K]; K]

Hessian ∂²ℓ/∂p_a∂p_b (symmetric).

Implementations§

Source§

impl<const K: usize> Tower2<K>

Source

pub fn zero() -> Self

The additive identity.

Source

pub fn constant(c: f64) -> Self

A constant: value c, all derivatives zero.

Source

pub fn variable(value: f64, idx: usize) -> Self

The seeded variable p_idx with current value value: unit first derivative in slot idx, zero elsewhere and above.

Source

pub fn mul(&self, o: &Self) -> Self

Exact truncated (order ≤ 2) Leibniz product. The v/g/h channels match Tower4::mul term-for-term.

Source

pub fn compose_unary(&self, d: [f64; 3]) -> Self

Exact (order ≤ 2) multivariate Faà di Bruno composition f ∘ self.

d = [f(u), f′(u), f″(u)] evaluated at u = self.v. The v/g/h channels match Tower4::compose_unary term-for-term (which uses only d[0..=2] for those orders), so this is a strict truncation, not an approximation. The full-order [f64; 5] derivative stacks the families already produce can be passed by slicing their first three entries.

Source

pub fn scale(&self, s: f64) -> Self

Multiply every channel by a plain scalar.

Source

pub fn exp(&self) -> Self

e^self.

Source

pub fn sqrt(&self) -> Self

√self. Caller guarantees positivity.

Trait Implementations§

Source§

impl<const K: usize> Add for Tower2<K>

Source§

type Output = Tower2<K>

The resulting type after applying the + operator.
Source§

fn add(self, o: Self) -> Self

Performs the + operation. Read more
Source§

impl<const K: usize> Add<f64> for Tower2<K>

Source§

type Output = Tower2<K>

The resulting type after applying the + operator.
Source§

fn add(self, c: f64) -> Self

Performs the + operation. Read more
Source§

impl<const K: usize> Clone for Tower2<K>

Source§

fn clone(&self) -> Tower2<K>

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<const K: usize> Copy for Tower2<K>

Source§

impl<const K: usize> Debug for Tower2<K>

Source§

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

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

impl<const K: usize> Mul for Tower2<K>

Source§

type Output = Tower2<K>

The resulting type after applying the * operator.
Source§

fn mul(self, o: Self) -> Self

Performs the * operation. Read more
Source§

impl<const K: usize> Mul<f64> for Tower2<K>

Source§

type Output = Tower2<K>

The resulting type after applying the * operator.
Source§

fn mul(self, c: f64) -> Self

Performs the * operation. Read more

Auto Trait Implementations§

§

impl<const K: usize> Freeze for Tower2<K>

§

impl<const K: usize> RefUnwindSafe for Tower2<K>

§

impl<const K: usize> Send for Tower2<K>

§

impl<const K: usize> Sync for Tower2<K>

§

impl<const K: usize> Unpin for Tower2<K>

§

impl<const K: usize> UnsafeUnpin for Tower2<K>

§

impl<const K: usize> UnwindSafe for Tower2<K>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V