Skip to main content

Crate numra_autodiff

Crate numra_autodiff 

Source
Expand description

Automatic differentiation for Numra: forward-mode and reverse-mode.

This crate provides two AD modes:

  • Forward-mode (Dual): Augments values with directional derivatives. Cost: O(n) passes for n inputs. Best when outputs >> inputs.
  • Reverse-mode (reverse::Var): Tape-based computation graph with backward pass. Cost: O(m) passes for m outputs. Best when inputs >> outputs (optimization).

§Forward-mode example

use numra_autodiff::{Dual, gradient};

let grad = gradient(|x: &[Dual<f64>]| x[0] * x[0] + x[1] * x[1], &[3.0, 4.0]);
assert!((grad[0] - 6.0).abs() < 1e-12); // df/dx0 = 2*x0 = 6
assert!((grad[1] - 8.0).abs() < 1e-12); // df/dx1 = 2*x1 = 8

§Reverse-mode example

use numra_autodiff::reverse::grad;

let g = grad(|x| x[0].clone() * x[0].clone() + x[1].clone() * x[1].clone(), &[3.0, 4.0]);
assert!((g[0] - 6.0).abs() < 1e-12);
assert!((g[1] - 8.0).abs() < 1e-12);

Author: Moussa Leblouba Date: 9 February 2026 Modified: 2 May 2026

Re-exports§

pub use bridge::gradient_closure;
pub use bridge::model_jacobian_closure;
pub use dual::Dual;
pub use gradient::gradient;
pub use gradient::jacobian;

Modules§

bridge
Bridge utilities for connecting autodiff with optimization.
dual
Dual number type for forward-mode automatic differentiation.
gradient
Gradient and Jacobian computation via forward-mode AD.
reverse
Reverse-mode automatic differentiation via tape-based computation graph.
tape
Computation graph (Wengert list) for reverse-mode AD.