DualTensor

Struct DualTensor 

Source
pub struct DualTensor<V: Differentiable> { /* private fields */ }
Expand description

Value wrapper for forward-mode AD.

§Examples

use chainrules::DualTensor;
let dual = DualTensor::new(primal);
assert!(!dual.has_tangent());

Implementations§

Source§

impl<V: Differentiable> DualTensor<V>

Source

pub fn new(primal: V) -> Self

Creates a dual value with zero tangent.

§Examples
use chainrules::DualTensor;
let x = DualTensor::new(primal);
Source

pub fn with_tangent(_primal: V, _tangent: V::Tangent) -> AdResult<Self>

Creates a dual value with explicit tangent.

§Errors

Returns AutodiffError::TangentShapeMismatch if shapes differ.

§Examples
use chainrules::DualTensor;
let x = DualTensor::with_tangent(primal, tangent).unwrap();
Source

pub fn primal(&self) -> &V

Returns the primal value.

§Examples
let p = dual.primal();
Source

pub fn tangent(&self) -> Option<&V::Tangent>

Returns the tangent, or None for zero tangent.

§Examples
let maybe_t = dual.tangent();
Source

pub fn has_tangent(&self) -> bool

Returns whether this dual value has a non-zero tangent.

§Examples
assert!(dual.has_tangent());
Source

pub fn into_parts(self) -> (V, Option<V::Tangent>)

Consumes and returns (primal, tangent).

§Examples
let (p, t) = dual.into_parts();
Source

pub fn detach_tangent(self) -> Self

Consumes and returns a dual value with tangent removed.

§Examples
let c = dual.detach_tangent();
assert!(!c.has_tangent());

Auto Trait Implementations§

§

impl<V> Freeze for DualTensor<V>
where V: Freeze, <V as Differentiable>::Tangent: Freeze,

§

impl<V> RefUnwindSafe for DualTensor<V>

§

impl<V> Send for DualTensor<V>
where V: Send, <V as Differentiable>::Tangent: Send,

§

impl<V> Sync for DualTensor<V>
where V: Sync, <V as Differentiable>::Tangent: Sync,

§

impl<V> Unpin for DualTensor<V>
where V: Unpin, <V as Differentiable>::Tangent: Unpin,

§

impl<V> UnwindSafe for DualTensor<V>

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> 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, 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.