Expand description
Jet1Vec - multi-variable first-order forward-mode AD type.
A Jet1Vec carries a real value plus a vector of tangents (one per input
variable). A single forward pass through a function built from Jet1Vec
operations yields the value AND the full gradient — every partial
∂f/∂x_i — in one shot, without a tape.
This complements the other AD types in the crate:
Jet1— forward mode, one tangent direction.Jet2— forward mode, one direction, second order.Jet1Vec(this type) — forward mode, many directions at once, first order.AReal— reverse mode (tape-based).
The tangent vector is stored as a plain Vec<T>. Every operator is
implemented as a single fused loop over the tangent slice (no temporary
intermediate buffers), and owned-value forms reuse the left operand’s
allocation in place, so forward propagation is allocator-light and the
inner loops are autovectorizable.
Typical use: seed each input variable x_i with
Jet1Vec::variable(x_i, i, n), propagate through the function, then read
the gradient from result.dual().
use xad_rs::Jet1Vec;
// f(x, y) = x^2 * y, at (x, y) = (3, 4)
// ∂f/∂x = 2xy = 24, ∂f/∂y = x^2 = 9
let n = 2;
let x = Jet1Vec::variable(3.0, 0, n);
let y = Jet1Vec::variable(4.0, 1, n);
let f = &(&x * &x) * &y;
assert_eq!(f.real(), 36.0);
assert_eq!(f.partial(0), 24.0);
assert_eq!(f.partial(1), 9.0);This module also contains NamedJet1Vec, a named wrapper over Jet1Vec
that provides name-keyed gradient readback via a NamedForwardTape scope.
Structs§
- Jet1Vec
- Multi-variable forward-mode dual number.
- Named
Jet1 Vec - Labeled wrapper around the positional
Jet1Vectype.