pub struct Dual {
pub value: f64,
pub tangent: f64,
}Expand description
A forward-mode dual number: a value (primal) paired with a tangent (directional derivative).
Running a computation written against Scalar on Dual propagates the
derivative through every operation via the chain rule. Seed an input’s
tangent to 1.0 with Dual::seed, then extract the
(value, derivative) pair.
Both PartialEq and PartialOrd compare the value (primal) field only,
so equality and ordering agree on the “primal decides control flow”
semantics (see the module-level docs). Two Duals with equal value but
different tangents therefore compare equal and unordered-as-Equal; this
keeps a == b ⟺ a.partial_cmp(&b) == Some(Equal) — the std contract that a
derived (both-field) PartialEq would violate against the value-only
PartialOrd.
Fields§
§value: f64The primal value of the computation.
tangent: f64The tangent (directional derivative) accumulated by the chain rule.
Implementations§
Trait Implementations§
Source§impl AddAssign for Dual
impl AddAssign for Dual
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl Copy for Dual
Source§impl MulAssign for Dual
impl MulAssign for Dual
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl PartialOrd for Dual
impl PartialOrd for Dual
Source§impl Scalar for Dual
impl Scalar for Dual
Source§fn infinity() -> Self
fn infinity() -> Self
Source§fn sqrt(self) -> Self
fn sqrt(self) -> Self
Source§fn powf(self, p: f64) -> Self
fn powf(self, p: f64) -> Self
f64 power. The tangent uses p * v^(p-1); at
value == 0.0 with p < 1.0 this may be NaN/Inf.Auto Trait Implementations§
impl Freeze for Dual
impl RefUnwindSafe for Dual
impl Send for Dual
impl Sync for Dual
impl Unpin for Dual
impl UnsafeUnpin for Dual
impl UnwindSafe for Dual
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, Right> ClosedAdd<Right> for T
impl<T, Right> ClosedAddAssign<Right> for T
impl<T, Right> ClosedMul<Right> for T
impl<T, Right> ClosedMulAssign<Right> for T
impl<T> ClosedNeg for Twhere
T: Neg<Output = T>,
impl<T, Right> ClosedSub<Right> for T
impl<T, Right> ClosedSubAssign<Right> for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.