4 releases

Uses new Rust 2021

0.8.0 Jan 7, 2022
0.7.2 Jan 2, 2022
0.7.1 Dec 31, 2021
0.7.0 Dec 31, 2021
Download history 13/week @ 2022-08-18 19/week @ 2022-08-25 15/week @ 2022-09-01 22/week @ 2022-09-08 8/week @ 2022-09-15 15/week @ 2022-09-22 28/week @ 2022-09-29 21/week @ 2022-10-06 5/week @ 2022-10-13 15/week @ 2022-10-20 26/week @ 2022-10-27 30/week @ 2022-11-03 21/week @ 2022-11-10 24/week @ 2022-11-17 10/week @ 2022-11-24 6/week @ 2022-12-01

67 downloads per month
Used in 4 crates (3 directly)

Apache-2.0

3KB

RustAD - Rust Auto-Differentiation

Crates.io lib.rs.io docs

A restrictive WIP beginnings of a library attempting to implement auto-differentiation in Rust.

Why would I use this over <insert library>? You wouldn't, not yet anyway. I'd say wait until support for ndarray is more comprehensive, then this becomes probably the most convenient Rust AutoDiff library.

It's all messy be warned.

Status

  • Forward Auto-differentiation
  • Reverse Auto-differentiation
  • Numerical primitives (e.g. f32, u32 etc.) support*
  • limited° ndarray support*
  • limited° nalgebra support*
  • if, if else and else support
  • for, while and loop support

*typeof (e.g. decltype) not being currently implemented in Rust makes support more difficult.

°Support limited to the basic blas-like operations.

Application

Auto-differentiation is implemented via 2 attribute procedural macros, e.g.

#[rust_ad::forward_autodiff]
fn multi(x: f32, y: f32) -> f32 {
    let a = x.powi(2i32);
    let b = x * 2f32;
    let c = 2f32 / y;
    let f = a + b + c;
    return f;
}
fn main() {
    let (f, der_x, der_y) = rust_ad::forward!(multi, 3f32, 5f32);
    assert_eq!(f, 15.4f32);
    assert_eq!(der_x, 8f32);
    assert_eq!(der_y, -0.08f32);
}
#[rust_ad::reverse_autodiff]
fn multi(x: f32, y: f32) -> f32 {
    let a = x.powi(2i32);
    let b = x * 2f32;
    let c = 2f32 / y;
    let f = a + b + c;
    return f;
}
fn main() {
    let (f, der_x, der_y) = rust_ad::reverse!(multi, 3f32, 5f32);
    assert_eq!(f, 15.4f32);
    assert_eq!(der_x, 8f32);
    assert_eq!(der_y, -0.08f32);
}

Dependencies

~560KB