DualNumber

Struct DualNumber 

Source
pub struct DualNumber<T>
where T: Float,
{ pub real: T, pub dual: T, }
Expand description

A dual number: a + bε where ε² = 0

The real part stores the function value, the dual part stores the derivative.

Fields§

§real: T

Real part (function value)

§dual: T

Dual part (derivative with respect to input variable)

Implementations§

Source§

impl<T> DualNumber<T>
where T: Float,

Source

pub fn new(real: T, dual: T) -> DualNumber<T>

Create a new dual number

Source

pub fn variable(value: T) -> DualNumber<T>

Create a variable (derivative = 1)

Source

pub fn new_variable(value: T) -> DualNumber<T>

Create a variable (derivative = 1) - alias for consistency

Source

pub fn constant(value: T) -> DualNumber<T>

Create a constant (derivative = 0)

Source

pub fn value(&self) -> T

Get the value (real part)

Source

pub fn derivative(&self) -> T

Get the derivative (dual part)

Source

pub fn apply_with_derivative<F, G>(&self, f: F, df: G) -> DualNumber<T>
where F: Fn(T) -> T, G: Fn(T) -> T,

Apply a function with known derivative

Source

pub fn sin(self) -> DualNumber<T>

Sine function

Source

pub fn cos(self) -> DualNumber<T>

Cosine function

Source

pub fn exp(self) -> DualNumber<T>

Exponential function

Source

pub fn ln(self) -> DualNumber<T>

Natural logarithm

Source

pub fn powf(self, n: T) -> DualNumber<T>

Power function

Source

pub fn sqrt(self) -> DualNumber<T>

Square root

Source

pub fn tanh(self) -> DualNumber<T>

Hyperbolic tangent

Source

pub fn relu(self) -> DualNumber<T>

ReLU activation function

Source

pub fn sigmoid(self) -> DualNumber<T>

Sigmoid activation function

Source

pub fn softplus(self) -> DualNumber<T>

Softplus activation function

Source

pub fn max(self, other: DualNumber<T>) -> DualNumber<T>

Maximum of two dual numbers

Source

pub fn min(self, other: DualNumber<T>) -> DualNumber<T>

Minimum of two dual numbers

Source

pub fn tan(self) -> DualNumber<T>

Tangent function

Source

pub fn sinh(self) -> DualNumber<T>

Hyperbolic sine

Source

pub fn cosh(self) -> DualNumber<T>

Hyperbolic cosine

Source

pub fn powi(self, n: i32) -> DualNumber<T>

Integer power

Source§

impl DualNumber<f32>

Source

pub const ZERO: DualNumber<f32>

Zero dual number (0 + 0ε)

Source

pub const ONE: DualNumber<f32>

One dual number (1 + 0ε)

Source

pub const fn new_variable_const(value: f32) -> DualNumber<f32>

Variable dual number (value + 1ε) - useful for GPU operations

Source

pub const fn new_constant_const(value: f32) -> DualNumber<f32>

Constant dual number (value + 0ε) - useful for GPU operations

Trait Implementations§

Source§

impl<T> Add<T> for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the + operator.
Source§

fn add(self, scalar: T) -> DualNumber<T>

Performs the + operation. Read more
Source§

impl<T> Add for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: DualNumber<T>) -> DualNumber<T>

Performs the + operation. Read more
Source§

impl<T> Clone for DualNumber<T>
where T: Clone + Float,

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for DualNumber<T>
where T: Debug + Float,

Source§

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

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

impl<T> Div<T> for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: T) -> DualNumber<T>

Performs the / operation. Read more
Source§

impl<T> Div for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: DualNumber<T>) -> DualNumber<T>

Performs the / operation. Read more
Source§

impl<T, const P: usize, const Q: usize, const R: usize> Mul<DualNumber<T>> for DualMultivector<T, P, Q, R>
where T: Float,

Source§

type Output = DualMultivector<T, P, Q, R>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: DualNumber<T>) -> DualMultivector<T, P, Q, R>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: T) -> DualNumber<T>

Performs the * operation. Read more
Source§

impl<T> Mul for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: DualNumber<T>) -> DualNumber<T>

Performs the * operation. Read more
Source§

impl<T> Neg for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> DualNumber<T>

Performs the unary - operation. Read more
Source§

impl<T> One for DualNumber<T>
where T: Float,

Source§

fn one() -> DualNumber<T>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T> PartialEq for DualNumber<T>
where T: PartialEq + Float,

Source§

fn eq(&self, other: &DualNumber<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Sub<T> for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the - operator.
Source§

fn sub(self, scalar: T) -> DualNumber<T>

Performs the - operation. Read more
Source§

impl<T> Sub for DualNumber<T>
where T: Float,

Source§

type Output = DualNumber<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: DualNumber<T>) -> DualNumber<T>

Performs the - operation. Read more
Source§

impl<T> Zero for DualNumber<T>
where T: Float,

Source§

fn zero() -> DualNumber<T>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T> Copy for DualNumber<T>
where T: Copy + Float,

Source§

impl<T> StructuralPartialEq for DualNumber<T>
where T: Float,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for DualNumber<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> 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<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,