latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.autograd.forward_ad API
Functions 4
enter_dual_level
functionFull reference ↗- tensorplay.autograd.forward_ad.enter_dual_level() int[source]
Enters a new forward grad level and returns its index.
This level can be used to make and unpack dual Tensors to compute forward gradients. Levels cannot nest: entering while another level is active raises, so all forward AD computation happens inside one level.
exit_dual_level
functionFull reference ↗make_dual
functionFull reference ↗- tensorplay.autograd.forward_ad.make_dual(tensor: Tensor, tangent: Tensor, *, level: int | None = None) Tensor[source]
Associates a tensor value with its tangent to create a “dual tensor”.
The result is a new tensor aliased to
tensorwithtangentattached as its forward gradient. The tangent can be recovered withunpack_dual().Given a function
fwhose jacobian isJ, this computes the Jacobian-vector product (jvp) betweenJand a given vectorv:>>> # xdoctest: +SKIP("Undefined variables") >>> with dual_level(): ... inp = make_dual(x, v) ... out = f(inp) ... y, jvp = unpack_dual(out)
unpack_dual
functionFull reference ↗- tensorplay.autograd.forward_ad.unpack_dual(tensor: Tensor, *, level: int | None = None) UnpackedDualTensor[source]
Unpacks a dual tensor into its primal value and forward gradient.
Returns
(primal, tangent)whereprimalis a view oftensor’s primal andtangentistensor’s tangent (Nonewhentensorcarries no tangent atlevel).
Help improve this page
Found an error, an unclear step, or a missing example?

