dxpr
Differentiable expression templates in Rust.
Examples
At runtime:
use *;
let x = 4;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
At compile time:
use ;
const X: i32 = 4;
const A: = var;
const EXPRESSION: = -A;
const VALUE: i32 = EXPRESSION.eval;
assert_eq!;
// Rust currently can't compare pointers to constants at compile time, so no compile-time autodiff at the moment
// Plans in the works to fix this with the ability to manually specify a "variable ID."
// Either way, your `build.rs` could easily evaluate an arbitrary expression and write it, unevaluated, to a file.
We can reuse an expression without copying any variables by calling eval or grad on a reference:
use *;
let x = 4;
let a = var;
let expression = -a;
assert_eq!;
assert_eq!;
assert_eq!;
// still movable the last time:
assert_eq!;
// can't use it again: ------ `expression` moved due to this method call
// /* bad! */ assert_eq!(-4, expression.eval());
// ^^^^^^^^^^ value used here after move
To do:
- Interoperability with builtin constants
IndexandRangeBoundoperators (i.e.a[b]anda..b)