MCPcopy Index your code
hub / github.com/elrnv/autodiff

github.com/elrnv/autodiff @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
247 symbols 305 edges 10 files 6 documented · 2%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

autodiff

An auto-differentiation library.

On crates.io On docs.rs Build status

Currently supported features:

  • [x] Forward auto-differentiation

  • [ ] Reverse auto-differentiation

To compute a derivative with respect to a variable using this library:

  1. create a variable of type F, which implements the Float trait from the num-traits crate.

  2. compute your function using this variable as the input.

  3. request the derivative from this variable using the deriv method.

Disclaimer

This library is a work in progress and is not ready for production use.

Examples

The following example differentiates a 1D function defined by a closure.

    // Define a function `f(x) = e^{-0.5*x^2}`.
    let f = |x: FT<f64>| (-x * x / F1::cst(2.0)).exp();

    // Differentiate `f` at zero.
    println!("{}", diff(f, 0.0)); // prints `0`

To compute the gradient of a function, use the function grad as follows:

    // Define a function `f(x,y) = x*y^2`.
    let f = |x: &[FT<f64>]| x[0] * x[1] * x[1];

    // Differentiate `f` at `(1,2)`.
    let g = grad(f, &vec![1.0, 2.0]);
    println!("({}, {})", g[0], g[1]); // prints `(4, 4)`

Compute a specific derivative of a multi-variable function:

     // Define a function `f(x,y) = x*y^2`.
     let f = |v: &[FT<f64>]| v[0] * v[1] * v[1];

     // Differentiate `f` at `(1,2)` with respect to `x` (the first unknown) only.
     let v = vec![
         F1::var(1.0), // Create a variable.
         F1::cst(2.0), // Create a constant.
     ];
     println!("{}", f(&v).deriv()); // prints `4`

Features

Support for approx, cgmath and nalgebra via the approx, cgmath and na feature flags respectively.

License

This repository is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT License (LICENSE-MIT or https://opensource.org/licenses/MIT)

at your option.

Acknowledgements

This library started as a fork of rust-ad.

Extension points exported contracts — how you extend this code

DualEq (Interface)
Compare the values and derivatives of two dual numbers for equality. [3 implementers]
src/forward_autodiff.rs

Core symbols most depended-on inside this repo

real
called by 10
src/nalgebra.rs
imaginary
called by 10
src/nalgebra.rs
is_zero
called by 9
src/forward_autodiff.rs
into
called by 4
src/forward_autodiff.rs
sqrt
called by 4
src/forward_autodiff.rs
min
called by 3
src/forward_autodiff.rs
pow
called by 3
src/forward_autodiff.rs
sqrt
called by 3
src/nalgebra.rs

Shape

Method 224
Function 21
Class 1
Interface 1

Languages

Rust100%

Modules by API surface

src/forward_autodiff.rs141 symbols
src/nalgebra.rs79 symbols
src/cgmath.rs8 symbols
src/approx.rs7 symbols
src/simba.rs5 symbols
tests/autodiff.rs4 symbols
src/bytemuck.rs1 symbols
examples/quadratic.rs1 symbols
examples/multi_quadratic.rs1 symbols

For agents

$ claude mcp add autodiff \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact