Skip to content

eggzec/ad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

144 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ad

Fast, transparent first- and second-order automatic differentiation for Python

Tests Documentation Ruff

codecov Quality Gate Status License: BSD-3

PyPI Downloads Python versions

Overview

The ad package allows you to easily and transparently perform first- and second-order automatic differentiation. Advanced math involving trigonometric, logarithmic, hyperbolic, and related functions can be evaluated directly using the ad.admath submodule.

All base numeric types are supported (int, float, complex, etc.). The package is designed so underlying numeric types interact as they normally do during calculations. In practice, ad behaves like a lightweight wrapper that tracks derivatives while preserving standard numeric behavior.

From the Wikipedia entry on Automatic differentiation:

"AD exploits the fact that every computer program, no matter how complicated, executes a sequence of elementary arithmetic operations (addition, subtraction, multiplication, division, etc.) and elementary functions (exp, log, sin, cos, etc.). By applying the chain rule repeatedly to these operations, derivatives of arbitrary order can be computed automatically, and accurate to working precision."

See the package documentation for details and examples.

Main Features

  • Transparent calculations with derivatives, requiring little or no modification to existing code (including NumPy-based code).
  • Broad mathematical operation support, including most functions from math and cmath, plus convenience trigonometric, hyperbolic, and logarithmic helpers (csc, acoth, ln, etc.). Comparison operators follow the same rules as the wrapped numeric values.
  • Seamless real and complex arithmetic through ad.admath counterparts.
  • Automatic gradient and Hessian function generator for optimization workflows with scipy.optimize via gh(your_func_here).
  • Linear algebra routines in ad.linalg similar to NumPy's linalg, without LAPACK dependency.

Linear Algebra Routines

Decompositions

  • chol: Cholesky decomposition
  • lu: LU decomposition
  • qr: QR decomposition

Solving equations and matrix inversion

  • solve: General solver for linear systems
  • lstsq: Least-squares solver for linear systems
  • inv: Multiplicative inverse of a matrix

Installation

uv pip install ad

Requires Python 3.10+. See the full installation guide.

Documentation

License

BSD-3-Clause.

About

Fast, transparent calculations of first and second-order automatic differentiation for Python

Resources

License

Stars

Watchers

Forks

Contributors

Languages