A restrictive WIP beginnings of a library attempting to implement auto-differentiation in Rust.
Why would I use this over \
It's all messy be warned.
f32
, u32
etc.) support*if
, if else
and else
supportfor
, 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.
Auto-differentiation is implemented via 2 attribute procedural macros, e.g.
```rust
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, derx, dery) = rustad::forward!(multi, 3f32, 5f32);
asserteq!(f, 15.4f32);
asserteq!(derx, 8f32);
asserteq!(dery, -0.08f32);
}
rust
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, derx, dery) = rustad::reverse!(multi, 3f32, 5f32); asserteq!(f, 15.4f32); asserteq!(derx, 8f32); asserteq!(dery, -0.08f32); } ```