Crate hyperdual

Expand description

Dual Numbers

Fully-featured Dual Number implementation with features for automatic differentiation of multivariate vectorial functions into gradients.

Usage

``````extern crate hyperdual;

use hyperdual::{Dual, Hyperdual, Float, differentiate};

fn main() {
// find partial derivative at x=4.0
let univariate = differentiate(4.0f64, |x| x.sqrt() + Dual::from_real(1.0));
assert!((univariate - 0.25).abs() < 1e-16, "wrong derivative");

// find the partial derivatives of a multivariate function
let x: Hyperdual<f64, 3> = Hyperdual::from_slice(&[4.0, 1.0, 0.0]);
let y: Hyperdual<f64, 3> = Hyperdual::from_slice(&[5.0, 0.0, 1.0]);

let multivariate = x * x + (x * y).sin() + y.powi(3);
assert!((multivariate[0] - 141.91294525072763).abs() < 1e-13, "f(4, 5) incorrect");
assert!((multivariate[1] - 10.04041030906696).abs() < 1e-13, "df/dx(4, 5) incorrect");
assert!((multivariate[2] - 76.63232824725357).abs() < 1e-13, "df/dy(4, 5) incorrect");

// You may also use the new Const approach (both U* and Const<*> use the const generics)
let x: Hyperdual<f64, 3> = Hyperdual::from_slice(&[4.0, 1.0, 0.0]);
let y: Hyperdual<f64, 3> = Hyperdual::from_slice(&[5.0, 0.0, 1.0]);

let multivariate = x * x + (x * y).sin() + y.powi(3);
assert!((multivariate[0] - 141.91294525072763).abs() < 1e-13, "f(4, 5) incorrect");
assert!((multivariate[1] - 10.04041030906696).abs() < 1e-13, "df/dx(4, 5) incorrect");
assert!((multivariate[2] - 76.63232824725357).abs() < 1e-13, "df/dy(4, 5) incorrect");
}``````

Structs

An allocator based on `ArrayStorage` and `VecStorage` for statically-sized and dynamically-sized matrices respectively.
Dim of dynamically-sized algebraic entities.
Dual Number structure

Constants

The constant dimension 0 .
The constant dimension 1.
The constant dimension 2 .
The constant dimension 3 .
The constant dimension 4 .
The constant dimension 5 .
The constant dimension 6 .
The constant dimension 7 .
The constant dimension 8 .
The constant dimension 9 .
The constant dimension 10 .
The constant dimension 11 .
The constant dimension 12 .
The constant dimension 13 .
The constant dimension 14 .
The constant dimension 15 .
The constant dimension 16 .
The constant dimension 17 .
The constant dimension 18 .
The constant dimension 19 .
The constant dimension 20 .
The constant dimension 21 .
The constant dimension 22 .
The constant dimension 23 .
The constant dimension 24 .
The constant dimension 25 .
The constant dimension 26 .
The constant dimension 27 .
The constant dimension 28 .
The constant dimension 29 .
The constant dimension 30 .
The constant dimension 31 .
The constant dimension 32 .
The constant dimension 33 .
The constant dimension 34 .
The constant dimension 35 .
The constant dimension 36 .
The constant dimension 37 .
The constant dimension 38 .
The constant dimension 39 .
The constant dimension 40 .
The constant dimension 41 .
The constant dimension 42 .
The constant dimension 43 .
The constant dimension 44 .
The constant dimension 45 .
The constant dimension 46 .
The constant dimension 47 .
The constant dimension 48 .
The constant dimension 49 .
The constant dimension 50 .
The constant dimension 51 .
The constant dimension 52 .
The constant dimension 53 .
The constant dimension 54 .
The constant dimension 55 .
The constant dimension 56 .
The constant dimension 57 .
The constant dimension 58 .
The constant dimension 59 .
The constant dimension 60 .
The constant dimension 61 .
The constant dimension 62 .
The constant dimension 63 .
The constant dimension 64 .
The constant dimension 65 .
The constant dimension 66 .
The constant dimension 67 .
The constant dimension 68 .
The constant dimension 69 .
The constant dimension 70 .
The constant dimension 71 .
The constant dimension 72 .
The constant dimension 73 .
The constant dimension 74 .
The constant dimension 75 .
The constant dimension 76 .
The constant dimension 77 .
The constant dimension 78 .
The constant dimension 79 .
The constant dimension 80 .
The constant dimension 81 .
The constant dimension 82 .
The constant dimension 83 .
The constant dimension 84 .
The constant dimension 85 .
The constant dimension 86 .
The constant dimension 87 .
The constant dimension 88 .
The constant dimension 89 .
The constant dimension 90 .
The constant dimension 91 .
The constant dimension 92 .
The constant dimension 93 .
The constant dimension 94 .
The constant dimension 95 .
The constant dimension 96 .
The constant dimension 97 .
The constant dimension 98 .
The constant dimension 99 .
The constant dimension 100 .
The constant dimension 101 .
The constant dimension 102 .
The constant dimension 103 .
The constant dimension 104 .
The constant dimension 105 .
The constant dimension 106 .
The constant dimension 107 .
The constant dimension 108 .
The constant dimension 109 .
The constant dimension 110 .
The constant dimension 111 .
The constant dimension 112 .
The constant dimension 113 .
The constant dimension 114 .
The constant dimension 115 .
The constant dimension 116 .
The constant dimension 117 .
The constant dimension 118 .
The constant dimension 119 .
The constant dimension 120 .
The constant dimension 121 .
The constant dimension 122 .
The constant dimension 123 .
The constant dimension 124 .
The constant dimension 125 .
The constant dimension 126 .
The constant dimension 127 .

Traits

A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()` elements of type `T`.
Trait implemented by any type that can be used as a dimension. This includes type-level integers and `Dyn` (for dimensions not known at compile-time).
Trait implemented exclusively by type-level integers.
Generic trait for floating point numbers
Trait implemented by `Dyn`.
Trait implemented by `Dyn` and type-level integers different from `U1`.
The base trait for numeric types, covering `0` and `1` values, comparisons, basic numeric operations, and string conversion.
Defines a multiplicative identity element for `Self`.
Defines an additive identity element for `Self`.