Reverse mode automatic differentiation in Rust.
To use this in your crate, add the following to Cargo.toml
:
rust
[dependencies]
reverse = "0.1"
```rust use reverse::*;
fn main() { let graph = Graph::new(); let a = graph.addvar(2.5); let b = graph.addvar(14.); let c = (a.sin() + b.ln() * 3.) - 5.; let gradients = c.backward();
asserteq!(gradients.wrt(&a), 2.5f64.cos()); assert_eq!(gradients.wrt(&b), 3. / 14.); } ```