Dual

Struct Dual 

Source
pub struct Dual<F: IntegrateFloat> {
    pub val: F,
    pub der: F,
}
Expand description

Dual number for forward-mode automatic differentiation

Fields§

§val: F

The value part

§der: F

The derivative part

Implementations§

Source§

impl<F: IntegrateFloat> Dual<F>

Source

pub fn new(val: F, der: F) -> Self

Create a new dual number

Source

pub fn constant(val: F) -> Self

Create a constant dual number (zero derivative)

Source

pub fn variable(val: F) -> Self

Create a variable dual number (unit derivative)

Source

pub fn value(&self) -> F

Extract the value

Source

pub fn derivative(&self) -> F

Extract the derivative

Source

pub fn sin(&self) -> Self

Compute sin(x)

Source

pub fn cos(&self) -> Self

Compute cos(x)

Source

pub fn exp(&self) -> Self

Compute exp(x)

Source

pub fn ln(&self) -> Self

Compute ln(x)

Source

pub fn sqrt(&self) -> Self

Compute sqrt(x)

Source

pub fn powf(&self, n: F) -> Self

Compute x^y for constant y

Source

pub fn abs(&self) -> Self

Compute abs(x)

Source

pub fn tan(&self) -> Self

Compute tan(x)

Source

pub fn tanh(&self) -> Self

Compute tanh(x)

Source

pub fn sinh(&self) -> Self

Compute sinh(x)

Source

pub fn cosh(&self) -> Self

Compute cosh(x)

Source

pub fn atan(&self) -> Self

Compute atan(x)

Source

pub fn asin(&self) -> Self

Compute asin(x)

Source

pub fn acos(&self) -> Self

Compute acos(x)

Source

pub fn atan2(&self, x: Self) -> Self

Compute atan2(y, x)

Source

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

Compute max(self, other)

Source

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

Compute min(self, other)

Source

pub fn pow(&self, other: Self) -> Self

Compute x^y where both x and y are dual numbers

Trait Implementations§

Source§

impl<F: IntegrateFloat> Add<F> for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the + operator.
Source§

fn add(self, scalar: F) -> Self

Performs the + operation. Read more
Source§

impl<F: IntegrateFloat> Add for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: Clone + IntegrateFloat> Clone for Dual<F>

Source§

fn clone(&self) -> Dual<F>

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<F: Debug + IntegrateFloat> Debug for Dual<F>

Source§

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

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

impl<F: IntegrateFloat> Display for Dual<F>

Source§

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

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

impl<F: IntegrateFloat> Div<F> for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: F) -> Self

Performs the / operation. Read more
Source§

impl<F: IntegrateFloat> Div for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<F: IntegrateFloat> Mul<F> for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: F) -> Self

Performs the * operation. Read more
Source§

impl<F: IntegrateFloat> Mul for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: IntegrateFloat> Neg for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<F: PartialEq + IntegrateFloat> PartialEq for Dual<F>

Source§

fn eq(&self, other: &Dual<F>) -> 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<F: IntegrateFloat> Sub<F> for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the - operator.
Source§

fn sub(self, scalar: F) -> Self

Performs the - operation. Read more
Source§

impl<F: IntegrateFloat> Sub for Dual<F>

Source§

type Output = Dual<F>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<F: Copy + IntegrateFloat> Copy for Dual<F>

Source§

impl<F: IntegrateFloat> StructuralPartialEq for Dual<F>

Auto Trait Implementations§

§

impl<F> Freeze for Dual<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Dual<F>
where F: RefUnwindSafe,

§

impl<F> Send for Dual<F>
where F: Send,

§

impl<F> Sync for Dual<F>
where F: Sync,

§

impl<F> Unpin for Dual<F>
where F: Unpin,

§

impl<F> UnwindSafe for Dual<F>
where F: 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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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