Differentiable

Trait Differentiable 

Source
pub trait Differentiable {
    type Inner;

    // Required methods
    fn var(x: Self::Inner) -> Self;
    fn cst(x: Self::Inner) -> Self;
    fn value(&self) -> &Self::Inner;
    fn deriv(&self) -> &Self::Inner;
    fn from_tuple(x: Self::Inner, dx: Self::Inner) -> Self;
    fn into_tuple(self) -> (Self::Inner, Self::Inner);
}
Expand description

Trait for any number-like structure that implements automatic foward differentiation.

A variable should start with unit derivative, and a constant should have a zero derivative.

§Examples

let x = DFloat32::var(14.0);

assert_eq!(*x.value(), 14.0);
assert_eq!(*x.deriv(),  1.0);

let c = DFloat32::cst(3.14);

assert_eq!(*c.value(), 3.14);
assert_eq!(*c.deriv(),  0.0);

let y = c * x * x; // y = c * x^2

assert_eq!(*y.deriv(), 2.0 * 3.14 * 14.0);

Required Associated Types§

Source

type Inner

Inner type, that can be used to construct a new differentiable variable of constant.

Required Methods§

Source

fn var(x: Self::Inner) -> Self

Creates a new variable, whose derivative will propagate.

Source

fn cst(x: Self::Inner) -> Self

Creates a new constant, whose derivative will not propagate, since a constant has a zero derivative.

Source

fn value(&self) -> &Self::Inner

Returns the inner value of this number.

Usually, this is the same value as if no derivative were ever computed.

Source

fn deriv(&self) -> &Self::Inner

Returns the derivative of this number.

Source

fn from_tuple(x: Self::Inner, dx: Self::Inner) -> Self

Creates a new number from tuple.

Source

fn into_tuple(self) -> (Self::Inner, Self::Inner)

Destructures self into a tuple.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§