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§
Required Methods§
Sourcefn cst(x: Self::Inner) -> Self
fn cst(x: Self::Inner) -> Self
Creates a new constant, whose derivative will not propagate, since a constant has a zero derivative.
Sourcefn value(&self) -> &Self::Inner
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.
Sourcefn from_tuple(x: Self::Inner, dx: Self::Inner) -> Self
fn from_tuple(x: Self::Inner, dx: Self::Inner) -> Self
Creates a new number from tuple.
Sourcefn into_tuple(self) -> (Self::Inner, Self::Inner)
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.