[][src]Struct fwd_ad::Dual

pub struct Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
{ /* fields omitted */ }

The struct implementing dual numbers.

It is parametrized by a type which stands for either a borrowed or an owned container, and derefences to [f64].

Creating Duals

From a already existing container

To create a Dual based on a container c, use Dual::from(c). See crate-level documentation for more information on how the container values are interpreted.

Create a constant (derivatives equal to zero) dual

A constant method is provided for RW Duals backed by a Vec or an array (up to size 32). To prevent cluttering, the array implementations documentation has been hidden.

Implementations

impl<F> Dual<Vec<F>, RW, F> where
    F: Scalar
[src]

pub fn constant(value: F, ndiffs: usize) -> Self[src]

Generates a dual number backed by a Vec with value value and ndiffs differentials, set to 0.

impl<T, M, F> Dual<T, M, F> where
    M: OwningMode,
    T: ROAble<F>,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

Implementations for Duals that do not necessarily own their content.

pub fn to_owning(&self) -> Dual<T::Owning, RW, F> where
    T: ToOwning<F>, 
[src]

Clone the borrowed content, so that the resulting Dual owns its content.

pub fn as_slice(&self) -> &[F][src]

Returns the content as a slice.

let d = Dual::<_,RW,f32>::from([17.,0.,0.]);
assert_eq!(d.as_slice()[0], d.val());
assert_eq!(&d.as_slice()[1..], d.diffs())

pub fn val(&self) -> F[src]

Returns the value of the dual.

let d = Dual::<_,RW,f32>::from([17.,0.,0.]);
assert_eq!(d.val(), 17.);

pub fn diffs(&self) -> &[F][src]

Returns a slice of the differentials.

let d = Dual::<_,RW,f32>::from([17.,1.,2.]);
assert_eq!(d.diffs(), &[1.,2.]);

pub fn ndiffs(&self) -> usize[src]

Return the number of differentials.

let d = Dual::<_,RW,f32>::from([17.,1.,2.]);
assert_eq!(d.ndiffs(), 2);

pub fn is_close<S, M2>(&self, b: &Dual<S, M2, F>, atol: F) -> bool where
    M2: OwningMode,
    S: ROAble<F>,
    S: CompatibleWith<M2, F>, 
[src]

Allows comparing to duals by checking whether they are elementwise within atol of each other.

let d1 = Dual::<_,RW,f64>::from([17.,1.,2.]);
let d2 = Dual::<_,RW,f64>::from([17.+1e-10,1.-1e-10,2.]);
assert_eq!(d1.is_close(&d2, 1e-9),true);
assert_eq!(d1.is_close(&d2, 1e-11),false);

pub fn view<'a>(&'a self) -> Dual<&'a T::ViewType, RO, F> where
    T: ToView<F>,
    &'a T::ViewType: CompatibleWith<RO, F>, 
[src]

Returns a non-owning Dual backed by the ViewType of self.

let d1 = Dual::<[f64;3],RW,f64>::from([17.,1.,2.]);
let d2 = Dual::<&[f64;3],RO,f64>::from(&[17.,1.,2.]);
assert_eq!(d1.view(),d2);

pub fn into_container(self) -> T[src]

Consumes the Dual and return the container inside it.

let c = [1.,2.,3.];
assert_eq!(Dual::<_,RW,_>::from(c.clone()).into_container(), c);

impl<T, F> Dual<T, RW, F> where
    T: RWAble<F>,
    F: Scalar
[src]

Methods for Duals that own their content

pub fn as_slice_mut(&mut self) -> &mut [F][src]

Returns the content a mutable slice.

let mut d = Dual::<_,RW,f32>::from([17.,0.,0.]);
assert_eq!(&mut d.clone().as_slice_mut()[0], d.val_mut());
assert_eq!(&d.clone().as_slice_mut()[1..], d.diffs_mut())

pub fn val_mut(&mut self) -> &mut F[src]

Return a mutable reference to the value.

let mut d = Dual::<_,RW,f32>::from([17.,0.,0.]);
*d.val_mut() = 42.;
assert_eq!(d, Dual::<_,RW,f32>::from([42.,0.,0.]))

pub fn diffs_mut(&mut self) -> &mut [F][src]

Return a mutable slice of the differentials.

let mut d = Dual::<_,RW,f32>::from([17.,0.,0.]);
d.diffs_mut()[0] = -1.;
assert_eq!(d, Dual::<_,RW,f32>::from([17.,-1.,0.]))

pub fn exp(self) -> Self[src]

Returns e^self.

pub fn exp2(self) -> Self[src]

Returns 2^self.

pub fn exp_base(self, base: F) -> Self[src]

Returns base^self.

pub fn ln(self) -> Self[src]

Returns ln(self).

pub fn inv(self) -> Self[src]

Returns 1/self.

pub fn powf(self, exp: F) -> Self[src]

Returns self^exp.

pub fn powdual<S, M2>(self, exp: Dual<S, M2, F>) -> Self where
    M2: OwningMode,
    S: ROAble<F>,
    S: CompatibleWith<M2, F>, 
[src]

Returns self^exp.

pub fn abs(self) -> Self[src]

Trait Implementations

impl<'_, L, R, M, F> Add<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the + operator.

impl<L, R, M, F> Add<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the + operator.

impl<L, R, F> Add<Dual<R, RW, F>> for Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the + operator.

impl<'_, L, R, F> Add<Dual<R, RW, F>> for &'_ Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the + operator.

impl<R> Add<Dual<R, RW, f32>> for f32 where
    R: RWAble<f32>, 
[src]

type Output = Dual<R, RW, f32>

The resulting type after applying the + operator.

impl<R> Add<Dual<R, RW, f64>> for f64 where
    R: RWAble<f64>,
    f64: Scalar
[src]

type Output = Dual<R, RW, f64>

The resulting type after applying the + operator.

impl<L, F> Add<F> for Dual<L, RW, F> where
    L: RWAble<F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_, L, R, M, F> AddAssign<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<L, R, M, F> AddAssign<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<S, F> AddAssign<F> for Dual<S, RW, F> where
    S: RWAble<F>,
    F: Scalar
[src]

impl<T: Clone, M: Clone, F: Clone> Clone for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<T: Copy, M: Copy, F: Copy> Copy for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<T: Debug, M: Debug, F: Debug> Debug for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<T: Default, M: Default, F: Default> Default for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<'_, L, R, M, F> Div<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the / operator.

impl<L, R, M, F> Div<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the / operator.

impl<L, R, F> Div<Dual<R, RW, F>> for Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the / operator.

impl<'_, L, R, ML, F> Div<Dual<R, RW, F>> for &'_ Dual<L, ML, F> where
    ML: OwningMode,
    L: ROAble<F>,
    L: CompatibleWith<ML, F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the / operator.

impl<L, F> Div<F> for Dual<L, RW, F> where
    L: RWAble<F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the / operator.

impl<'_, L, R, M, F> DivAssign<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<L, R, M, F> DivAssign<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<S, F> DivAssign<F> for Dual<S, RW, F> where
    S: RWAble<F>,
    F: Scalar
[src]

impl<T, M, F> From<T> for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<T: Hash, M: Hash, F: Hash> Hash for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<'_, L, R, M, F> Mul<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the * operator.

impl<L, R, M, F> Mul<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the * operator.

impl<L, R, F> Mul<Dual<R, RW, F>> for Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the * operator.

impl<'_, L, R, F> Mul<Dual<R, RW, F>> for &'_ Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the * operator.

impl<R> Mul<Dual<R, RW, f32>> for f32 where
    R: RWAble<f32>, 
[src]

type Output = Dual<R, RW, f32>

The resulting type after applying the * operator.

impl<R> Mul<Dual<R, RW, f64>> for f64 where
    R: RWAble<f64>,
    f64: Scalar
[src]

type Output = Dual<R, RW, f64>

The resulting type after applying the * operator.

impl<L, F> Mul<F> for Dual<L, RW, F> where
    L: RWAble<F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_, L, R, M, F> MulAssign<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<L, R, M, F> MulAssign<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<S, F> MulAssign<F> for Dual<S, RW, F> where
    S: RWAble<F>,
    F: Scalar
[src]

impl<T, F> Neg for Dual<T, RW, F> where
    T: RWAble<F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the - operator.

impl<T: PartialEq, M: PartialEq, F: PartialEq> PartialEq<Dual<T, M, F>> for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<T, M, F> StructuralPartialEq for Dual<T, M, F> where
    M: OwningMode,
    T: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<'_, L, R, M, F> Sub<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the - operator.

impl<L, R, M, F> Sub<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the - operator.

impl<L, R, F> Sub<Dual<R, RW, F>> for Dual<L, RO, F> where
    L: ROAble<F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the - operator.

impl<'_, L, R, ML, F> Sub<Dual<R, RW, F>> for &'_ Dual<L, ML, F> where
    L: ROAble<F>,
    ML: OwningMode,
    L: CompatibleWith<ML, F>,
    R: RWAble<F>,
    F: Scalar
[src]

type Output = Dual<R, RW, F>

The resulting type after applying the - operator.

impl<S> Sub<Dual<S, RW, f32>> for f32 where
    S: RWAble<f32>, 
[src]

type Output = Dual<S, RW, f32>

The resulting type after applying the - operator.

impl<S> Sub<Dual<S, RW, f64>> for f64 where
    S: RWAble<f64>, 
[src]

type Output = Dual<S, RW, f64>

The resulting type after applying the - operator.

impl<L, F> Sub<F> for Dual<L, RW, F> where
    L: RWAble<F>,
    F: Scalar
[src]

type Output = Self

The resulting type after applying the - operator.

impl<'_, L, R, M, F> SubAssign<&'_ Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<L, R, M, F> SubAssign<Dual<R, M, F>> for Dual<L, RW, F> where
    M: OwningMode,
    L: RWAble<F>,
    R: ROAble<F>,
    R: CompatibleWith<M, F>,
    F: Scalar
[src]

impl<S, F> SubAssign<F> for Dual<S, RW, F> where
    S: RWAble<F>,
    F: Scalar
[src]

Auto Trait Implementations

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

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

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

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

impl<T, M, F> UnwindSafe for Dual<T, M, F> where
    F: UnwindSafe,
    M: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.