autodiff
Luna-Flow/autodiff computes exact first derivatives of ordinary MoonBit
programs by forward-mode automatic differentiation. A program written
against the Luna Flow traits is run on dual numbers with
, and the derivative appears in the
component. The repository provides the dual-number type, scalar drivers,
checked domains for division and square roots, gradients and Jacobians over
linear-algebra vectors, and derivatives of luna-poly polynomials.
This manual documents version 0.2.0 on MoonBit 0.10.
Packages
| Package | Import path | Role | Pages |
|---|---|---|---|
autodiff | Luna-Flow/autodiff | one-stop facade: Dual, diff, value_and_diff, re-exported traits | API · tutorial · design |
dual | Luna-Flow/autodiff/dual | the Dual[T] type, its arithmetic, rules and instances | API · tutorial · design |
forward | Luna-Flow/autodiff/forward | scalar drivers diff and value_and_diff | API · tutorial · design |
core | Luna-Flow/autodiff/core | algebraic facade: Dual and the luna-generic structure traits | API · tutorial · design |
elementary | Luna-Flow/autodiff/elementary | analytic facade: Dual and the arithmetic function traits | API · tutorial · design |
checked | Luna-Flow/autodiff/checked | checked facade: DivChecked, SqrtChecked, context and errors | API · tutorial · design |
linalg | Luna-Flow/autodiff/linalg | gradients and Jacobians over linear-algebra/immut | API · tutorial · design |
poly | Luna-Flow/autodiff/poly | derivatives of dense and univariate sparse luna-poly polynomials | API · tutorial · design |
Two more packages have no manual pages. examples holds five small
functions (basic_diff_example, square_diff_example, gradient_example,
jacobian_example, polynomial_derivative_example) that show each layer in
a few lines; read src/examples/examples.mbt.
tests is the black-box test suite of all packages, including the
linear-algebra and luna-poly integration tests. The
architecture guide shows how the packages depend on each
other, and the repository conventions record the naming
rules of this manual.
Reading paths
New to automatic differentiation. Start with the autodiff tutorial, then the dual tutorial, which compares dual numbers with finite differences.
Using the library. Import Luna-Flow/autodiff and keep the
autodiff API and dual API at hand; add
the linalg tutorial or the
poly tutorial for vectors and polynomials, and the
checked tutorial when failures must be values.
Contributing. Read the dual design for the algebra, the derivative rules and the error bounds that every new operation must respect, then the architecture guide and the design page of the package you change.
Installation
moon add Luna-Flow/autodiff@0.2.0
The bridges need their libraries too: moon add Luna-Flow/linear-algebra
for linalg and moon add Luna-Flow/luna-poly for poly.
Toolchain
The code and the examples in this manual require MoonBit moonc 0.10 or
newer and the moon.mod / moon.pkg manifest format. The test suite runs
on the wasm-gc, wasm, js and native targets.
Validation
moon check --target all
./run_test.sh
moon info