🚚 Mady have new home! 👉MadyLab
MADY is open source tool for ahead-of-time automatic differentiation. In addition to ahead-of-time differentiation, MADY also provide some basic math structures, functions and operations with differentiation support.
-
Ahead-of-time gen
generate by proc-macro
-
Static
no tree or graph struct in runtime, just normal function call
-
Multithreading
because it's just a normal function, no hacky code or unsafe
-
Fast
just static code, llvm can optimize all the code
- functions:
min,max - operations:
add,sub,mul,div
First, set up project and add mady as dependency in your Cargo.yml
[dependencies]
mady = "version here"or
cargo add madyWrite a simple fn (only differentiation support operation/function can be used)
fn simple(a:isize, b:isize)-> isize{
a + b
}Finally, add #[derive_grad()] (attribute macro) to your function.
// isize here, because the input grad type of simple is isize
#[derive_grad(isize, isize)]
fn simple(a:isize, b:isize)-> isize{
a + b
}expect output
fn simple(a:isize, b:isize)-> isize{
a + b
}
fn grad_simple(a:isize, b:isize)-> (isize,(isize,isize)){
(a + b, (1, 1))
}To use unsupported function like sin, add fn named grad_{{fn name}}.
impl GradSin for f64 {
fn grad_sin(self) -> self {
self.cos()
}
}