#automatic-differentiation #numbers #dual #gradient #autodifferentiate #multidimentional

hyperdual

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

18 releases (4 stable)

Uses old Rust 2015

1.3.0 Jul 7, 2024
1.2.0 Feb 15, 2023
1.1.0 Jun 1, 2022
1.0.0 Mar 24, 2022
0.3.1 Jul 16, 2019

#94 in Math

Download history 346/week @ 2024-07-22 591/week @ 2024-07-29 254/week @ 2024-08-05 381/week @ 2024-08-12 322/week @ 2024-08-19 222/week @ 2024-08-26 232/week @ 2024-09-02 201/week @ 2024-09-09 192/week @ 2024-09-16 239/week @ 2024-09-23 297/week @ 2024-09-30 347/week @ 2024-10-07 159/week @ 2024-10-14 99/week @ 2024-10-21 278/week @ 2024-10-28 295/week @ 2024-11-04

897 downloads per month
Used in 6 crates (2 directly)

MIT license

40KB
1K SLoC

hyperdual Build Status

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.4500).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!((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");
}

Change log

Version 0.5.2

  • Re-add support for nalgebra Owned Vectors for structures that do not yet support const generics.
Previous Work

Dependencies

~3MB
~57K SLoC