TensorPlay
API reference
latest (dev)
Copy
View Markdown

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 ↗
tensorplay.autograd.forward_ad.exit_dual_level(*, level: int | None = None) → None[source]

Exits a forward grad level.

This deletes all the tangents associated with this level. Only exiting the most recently entered level is allowed.

#

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 tensor with tangent attached as its forward gradient. The tangent can be recovered with unpack_dual().

Given a function f whose jacobian is J, this computes the Jacobian-vector product (jvp) between J and a given vector v:

>>> # 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) where primal is a view of tensor’s primal and tangent is tensor’s tangent (None when tensor carries no tangent at level).

On this page

Ask DeepWiki