#numerical #automatic #macro #proc #syntax #peroxide #automatic-derivative

macro peroxide-ad

Proc macro for automatic differenitation of Peroxide

8 releases

0.3.0 Jan 25, 2021
0.2.1 Jan 12, 2021
0.1.4 Aug 1, 2020
0.1.3 Jul 31, 2020

#51 in #numerical

Download history 8570/week @ 2024-07-20 7837/week @ 2024-07-27 10363/week @ 2024-08-03 10873/week @ 2024-08-10 13761/week @ 2024-08-17 16750/week @ 2024-08-24 8986/week @ 2024-08-31 7216/week @ 2024-09-07 7311/week @ 2024-09-14 7307/week @ 2024-09-21 6185/week @ 2024-09-28 7715/week @ 2024-10-05 6187/week @ 2024-10-12 6069/week @ 2024-10-19 3951/week @ 2024-10-26 3575/week @ 2024-11-02

20,695 downloads per month
Used in 20 crates (via peroxide)

MIT/Apache

42KB
138 lines

Peroxide-ad

Automatic differentiation toolbox for Peroxide

Usage

Modify your Cargo.toml as follows.

[dependencies]
peroxide = "0.30"

Useful macros

  • #[ad_function] macro generates {}_grad, {}_hess from Fn(f64) -> f64 automatically.
    • {}_grad : gradient of function {}
    • {}_hess : hessian of function {}
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    f(2f64).print();        // x^3     = 8
    f_grad(2f64).print();   // 3 * x^2 = 12
    f_hess(2f64).print();   // 6 * x   = 12
}

#[ad_function]              // generates f_grad, f_hess
fn f(x: f64) -> f64 {
    x.powi(3)               // x^3
}

Dependencies

~1.5MB
~37K SLoC