#number #dual #hyperdual #gradient #autodifferentiate

dual_num

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

10 releases

0.2.7 Apr 3, 2019
0.2.6 Mar 1, 2019
0.2.5 Feb 4, 2019
0.2.4 Jan 28, 2019
0.1.1 Jun 5, 2017

#18 in Value formatting

Download history 49/week @ 2018-12-20 4/week @ 2018-12-27 13/week @ 2019-01-03 25/week @ 2019-01-10 10/week @ 2019-01-17 11/week @ 2019-01-24 14/week @ 2019-01-31 13/week @ 2019-02-07 2/week @ 2019-02-14 15/week @ 2019-02-21 35/week @ 2019-02-28 7/week @ 2019-03-07 6/week @ 2019-03-14 112/week @ 2019-03-21 14/week @ 2019-03-28

92 downloads per month
Used in 1 crate

MIT license

27KB
768 lines

dual_num Build Status

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

Usage

extern crate dual_num;

use dual_num::{Dual, Hyperdual, Float, differentiate, U3};

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.4500).abs() < 1e-16, "wrong derivative");

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

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

Dependencies

~3MB
~50K SLoC