17 releases (7 breaking)
0.8.0  Jan 7, 2022 

0.7.1  Dec 31, 2021 
#2 in #autodifferentiation
60 downloads per month
16KB
176 lines
RustAD  Rust AutoDifferentiation
A restrictive WIP beginnings of a library attempting to implement autodifferentiation 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 Autodifferentiation
 Reverse Autodifferentiation
 Numerical primitives (e.g.
f32
,u32
etc.) support*  limited° ndarray support*
 limited° nalgebra support*

if
,if else
andelse
support 
for
,while
andloop
support
*typeof
(e.g. decltype
) not being currently implemented in Rust makes support more difficult.
°Support limited to the basic blaslike operations.
Application
Autodifferentiation is implemented via 2 attribute procedural macros, e.g.
fn multi_test() {
let (f, (der_x, der_y)) = forward!(multi, 3f32, 5f32);
assert_eq!(f, 15.4f32);
assert_eq!(der_x, 8f32);
assert_eq!(der_y, 0.08f32);
/// f = x^2 + 2x + 2/y
/// δxy=5 = 2x + 2
/// δyx=3 = 2
#[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 multi_test() {
let (f, (der_x, der_y)) = reverse!(multi, (3f32, 5f32), (1f32));
assert_eq!(f, 15.4f32);
assert_eq!(der_x, 8f32);
assert_eq!(der_y, 0.08f32);
/// f = x^2 + 2x + 2/y
/// δxy=5 = 2x + 2
/// δyx=3 = 2
#[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;
}
}
Dependencies
~2MB
~44K SLoC