TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.autograd.forward_ad.make_dual

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)

On this page

Ask DeepWiki