Dual

Struct Dual 

Source
pub struct Dual<V, A = V> {
    pub value: V,
    pub adjoint: A,
}
Expand description

Dual variable for forward-mode autodifferentiation over aegir buffers.

This struct can be used as a simple container for a value and its adjoint (as we do within this crate). Alternatively, it can be used as a lightweight implementation of the “augmented algebra” commonly found in autodifferentiation libraries. It is by no means exhaustive, but may come in handy for some applications.

Fields§

§value: V

The value associated with the dual number.

§adjoint: A

The gradient/adjoint associated with the dual number.

Implementations§

Source§

impl<F: Scalar, B: Buffer<Field = F>> Dual<B>

Source

pub fn variable(buffer: B) -> Dual<B>

Returns a dual number with adjoint initialised as ones.

Source

pub fn constant(buffer: B) -> Dual<B>

Returns a dual number with adjoint initialised as zeroes.

Source§

impl<V, A: Buffer> Dual<V, A>
where FieldOf<A>: Neg<Output = FieldOf<A>>,

Source

pub fn conj(self) -> Dual<V, A>

Returns the dual conjugate of self.

Trait Implementations§

Source§

impl<'a, V, A> Add<&'a Dual<V, A>> for Dual<V, A>
where V: Buffer + Add<&'a V>, A: Buffer + Add<&'a A>,

Source§

type Output = Dual<<V as Add<&'a V>>::Output, <A as Add<&'a A>>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a Dual<V, A>) -> Dual<V::Output, A::Output>

Performs the + operation. Read more
Source§

impl<'a, V, A> Add<&'a V> for Dual<V, A>
where V: Buffer + Add<&'a V>,

Source§

type Output = Dual<<V as Add<&'a V>>::Output, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a V) -> Dual<V::Output, A>

Performs the + operation. Read more
Source§

impl<V, A> Add<V> for Dual<V, A>
where V: Buffer + Add<V>,

Source§

type Output = Dual<<V as Add>::Output, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: V) -> Dual<V::Output, A>

Performs the + operation. Read more
Source§

impl<V, A> Add for Dual<V, A>
where V: Buffer + Add<V>, A: Buffer + Add<A>,

Source§

type Output = Dual<<V as Add>::Output, <A as Add>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dual<V, A>) -> Dual<V::Output, A::Output>

Performs the + operation. Read more
Source§

impl<V: Clone, A: Clone> Clone for Dual<V, A>

Source§

fn clone(&self) -> Dual<V, A>

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<V: Debug, A: Debug> Debug for Dual<V, A>

Source§

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

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

impl<V, A> From<(V, A)> for Dual<V, A>

Source§

fn from((value, adjoint): (V, A)) -> Dual<V, A>

Converts to this type from the input type.
Source§

impl<'a, V, A> Mul<&'a Dual<V, A>> for Dual<V, A>
where V: Buffer + Mul<&'a V> + Mul<&'a A>, A: Buffer + Mul<&'a V>, <A as Mul<&'a V>>::Output: Add<<V as Mul<&'a A>>::Output>,

Source§

type Output = Dual<<V as Mul<&'a V>>::Output, <<A as Mul<&'a V>>::Output as Add<<V as Mul<&'a A>>::Output>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a Dual<V, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, V, A> Mul<&'a V> for Dual<V, A>
where V: Buffer + Mul<&'a V>,

Source§

type Output = Dual<<V as Mul<&'a V>>::Output, A>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a V) -> Self::Output

Performs the * operation. Read more
Source§

impl<V, A> Mul<V> for Dual<V, A>
where V: Buffer + Mul<V>,

Source§

type Output = Dual<<V as Mul>::Output, A>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<V, A> Mul for Dual<V, A>
where V: Buffer + Mul<V>, A: Buffer + Mul<V>, <A as Mul<V>>::Output: Add<<A as Mul<V>>::Output>,

Source§

type Output = Dual<<V as Mul>::Output, <<A as Mul<V>>::Output as Add>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dual<V, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<V, A> Neg for Dual<V, A>
where V: Buffer + Neg, A: Buffer + Neg,

Source§

type Output = Dual<<V as Neg>::Output, <A as Neg>::Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Dual<V::Output, A::Output>

Performs the unary - operation. Read more
Source§

impl<V: PartialEq, A: PartialEq> PartialEq for Dual<V, A>

Source§

fn eq(&self, other: &Dual<V, A>) -> 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<'a, V, A> Sub<&'a Dual<V, A>> for Dual<V, A>
where V: Buffer + Sub<&'a V>, A: Buffer + Sub<&'a A>,

Source§

type Output = Dual<<V as Sub<&'a V>>::Output, <A as Sub<&'a A>>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a Dual<V, A>) -> Dual<V::Output, A::Output>

Performs the - operation. Read more
Source§

impl<'a, V, A> Sub<&'a V> for Dual<V, A>
where V: Buffer + Sub<&'a V>,

Source§

type Output = Dual<<V as Sub<&'a V>>::Output, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a V) -> Dual<V::Output, A>

Performs the - operation. Read more
Source§

impl<V, A> Sub<V> for Dual<V, A>
where V: Buffer + Sub<V>,

Source§

type Output = Dual<<V as Sub>::Output, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: V) -> Dual<V::Output, A>

Performs the - operation. Read more
Source§

impl<V, A> Sub for Dual<V, A>
where V: Buffer + Sub<V>, A: Buffer + Sub<A>,

Source§

type Output = Dual<<V as Sub>::Output, <A as Sub>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dual<V, A>) -> Dual<V::Output, A::Output>

Performs the - operation. Read more
Source§

impl<V: Copy, A: Copy> Copy for Dual<V, A>

Source§

impl<V, A> StructuralPartialEq for Dual<V, A>

Auto Trait Implementations§

§

impl<V, A> Freeze for Dual<V, A>
where V: Freeze, A: Freeze,

§

impl<V, A> RefUnwindSafe for Dual<V, A>

§

impl<V, A> Send for Dual<V, A>
where V: Send, A: Send,

§

impl<V, A> Sync for Dual<V, A>
where V: Sync, A: Sync,

§

impl<V, A> Unpin for Dual<V, A>
where V: Unpin, A: Unpin,

§

impl<V, A> UnwindSafe for Dual<V, A>
where V: UnwindSafe, A: 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> 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.