Skip to main content

HyperDual

Struct HyperDual 

Source
pub struct HyperDual<T: Numeric> {
    pub real: T,
    pub eps1: T,
    pub eps2: T,
    pub eps1eps2: T,
}
Expand description

A hyper-dual number real + eps1·ε₁ + eps2·ε₂ + eps1eps2·ε₁ε₂, where ε₁² = ε₂² = 0.

After evaluating a function, real holds the value, eps1/eps2 hold the first derivatives along each seeded direction, and eps1eps2 holds the second (mixed) derivative.

Fields§

§real: T

The value, f.

§eps1: T

First derivative along direction 1.

§eps2: T

First derivative along direction 2.

§eps1eps2: T

Second derivative across the two directions.

Implementations§

Source§

impl<T: Numeric> HyperDual<T>

Source

pub fn new(real: T, eps1: T, eps2: T, eps1eps2: T) -> Self

A hyper-dual number with explicit components.

Source

pub fn constant(real: T) -> Self

A constant, whose derivatives are all zero.

Source

pub fn variable(real: T) -> Self

The independent variable, seeded along both directions to read f, f', and f'' of a single-variable function. For a mixed partial, seed two inputs on separate directions with new(xᵢ, 1, 0, 0) and new(xⱼ, 0, 1, 0).

Trait Implementations§

Source§

impl<T: Numeric> Add for HyperDual<T>

Source§

type Output = HyperDual<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Numeric> AddAssign for HyperDual<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + Numeric> Clone for HyperDual<T>

Source§

fn clone(&self) -> HyperDual<T>

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<T: Copy + Numeric> Copy for HyperDual<T>

Source§

impl<T: Debug + Numeric> Debug for HyperDual<T>

Source§

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

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

impl<T: Numeric> Div for HyperDual<T>

Source§

fn div(self, rhs: Self) -> Self

self · (1/rhs). A zero divisor yields inf/NaN, as with plain floats.

Source§

type Output = HyperDual<T>

The resulting type after applying the / operator.
Source§

impl<T: Numeric> DivAssign for HyperDual<T>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<T: Numeric> Mul for HyperDual<T>

Source§

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

Second-order product rule: each derivative part collects the cross terms that survive ε₁² = ε₂² = 0.

Source§

type Output = HyperDual<T>

The resulting type after applying the * operator.
Source§

impl<T: Numeric> MulAssign for HyperDual<T>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T: Numeric> Neg for HyperDual<T>

Source§

type Output = HyperDual<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T: Numeric> Numeric for HyperDual<T>

Source§

fn abs(self) -> Self

Derivative of |x| is its sign (the subgradient at zero is +1); its second derivative is zero.

Source§

fn sqrt(self) -> Self

At real == 0 the derivatives are unbounded and become inf/NaN.

Source§

fn ln(self) -> Self

Defined for real > 0; at 0 the value is -inf and the derivatives unbounded.

Source§

fn atan2(self, other: Self) -> Self

Four-quadrant arctangent carried to second order. With Y = self.real, X = other.real, r² = X² + Y², the partials are f_Y = X/r², f_X = −Y/r², f_YY = −2XY/r⁴, f_XX = 2XY/r⁴, f_XY = (Y² − X²)/r⁴. The denominator is nonzero off the origin, so the x = 0 axis is handled; only X = Y = 0 degenerates, as for float atan2.

Source§

fn copysign(self, sign: Self) -> Self

Magnitude of self with the sign of sign: a linear scaling by ±1, so it rides the univariate chain helper with slope s and zero curvature.

Source§

fn floor(self) -> Self

Largest integer <= self; the derivatives of a step function are zero.

Source§

fn is_nan(self) -> bool

Reflects the real part only; the derivatives are not inspected.

Source§

fn is_finite(self) -> bool

Reflects the real part only; a finite value can still carry a non-finite derivative (e.g. from sqrt(0) or ln(0)).

Source§

const ZERO: Self

The value 0.
Source§

const ONE: Self

The value 1.
Source§

const TWO: Self

The value 2.
Source§

const HALF: Self

The value 0.5.
Source§

const PI: Self

Archimedes’ constant, π.
Source§

const EPSILON: Self

The difference between 1 and the next larger representable value.
Source§

const NAN: Self

Not a Number.
Source§

const INFINITY: Self

Positive infinity.
Source§

const NEG_INFINITY: Self

Negative infinity.
Source§

const MAX: Self

The largest finite value. Read more
Source§

const MIN_POSITIVE: Self

The smallest positive normal value. Read more
Source§

fn from_f64(value: f64) -> Self

Converts from f64, narrowing if necessary. Used for table values and literals.
Source§

fn from_u64(value: u64) -> Self

Converts from u64, e.g. an iteration count.
Source§

fn from_usize(value: usize) -> Self

Converts from usize, e.g. a point or variable count.
Source§

fn sin(self) -> Self

Sine, with self in radians.
Source§

fn cos(self) -> Self

Cosine, with self in radians.
Source§

fn tan(self) -> Self

Tangent, with self in radians.
Source§

fn exp(self) -> Self

e raised to the power self.
Source§

fn signum(self) -> Self

Sign of self: 1 for positive, -1 for negative, 0 at zero. Read more
Source§

fn max(self, other: Self) -> Self

The larger of self and other, compared with >. Read more
Source§

fn min(self, other: Self) -> Self

The smaller of self and other, compared with <. Read more
Source§

fn atan(self) -> Self

Arctangent, in radians.
Source§

fn asin(self) -> Self

Arcsine, in radians, for self in [-1, 1].
Source§

fn acos(self) -> Self

Arccosine, in radians, for self in [-1, 1].
Source§

fn sinh(self) -> Self

Hyperbolic sine.
Source§

fn cosh(self) -> Self

Hyperbolic cosine.
Source§

fn tanh(self) -> Self

Hyperbolic tangent.
Source§

fn hypot(self, other: Self) -> Self

Euclidean distance √(self² + other²), scaled to avoid overflow and underflow.
Source§

fn powf(self, n: Self) -> Self

self raised to a floating-point power, via exp(n · ln self). Defined for self > 0; the f32/f64 impls override for negative bases and edge cases.
Source§

fn mul_add(self, a: Self, b: Self) -> Self

self * a + b. The f32/f64 impls fuse the operation for extra precision.
Source§

fn recip(self) -> Self

The reciprocal 1 / self.
Source§

fn powi(self, n: i32) -> Self

self raised to an integer power, by exponentiation-by-squaring. Read more
Source§

impl<T: Numeric> PartialEq for HyperDual<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: Numeric> PartialOrd for HyperDual<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Numeric + Primal> Primal for HyperDual<T>

Source§

fn to_f64(&self) -> f64

Returns the value as an f64 (the primal part, for autodiff scalars).
Source§

fn to_f32(&self) -> f32

Returns the value as an f32 (the primal part, for autodiff scalars).
Source§

impl<T: Numeric> Sub for HyperDual<T>

Source§

type Output = HyperDual<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<T: Numeric> SubAssign for HyperDual<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for HyperDual<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for HyperDual<T>
where T: RefUnwindSafe,

§

impl<T> Send for HyperDual<T>
where T: Send,

§

impl<T> Sync for HyperDual<T>
where T: Sync,

§

impl<T> Unpin for HyperDual<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for HyperDual<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for HyperDual<T>
where T: UnwindSafe,

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> 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, 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.