jacobian(func: Callable[..., Tensor], inputs: Tensor | tuple[Tensor, ...], create_graph: bool = False, strict: bool = False, vectorize: bool = False)Compute the Jacobian matrix of func with respect to each input.
The Jacobian of a vector-valued function is
Lucid evaluates it row-by-row by repeated reverse-mode
backward passes — one per output element — seeding each pass
with a one-hot cotangent so the resulting input gradient is
exactly the corresponding Jacobian row. The cost therefore
scales with the output dimension ; prefer vjp
when only is needed and jvp when only
is needed.
Parameters
funccallableA function mapping
Tensor inputs to a Tensor (or
tuple of Tensor). Must be differentiable w.r.t. each
positional input.Input tensor(s) at which the Jacobian is evaluated. They
are silently promoted to
requires_grad=True if needed.create_graphbool= FalseIf
True the Jacobian itself is differentiable, enabling
higher-order derivatives (e.g. building hessian on
top). Defaults to False.strictbool= FalseReserved for stricter shape/dtype validation. Currently
unused.
vectorizebool= FalseReserved for a future vmap-based implementation. Currently
unused.
Returns
Notes
Reverse-mode differentiation makes the cost per row ; the full Jacobian therefore costs . For square or wide Jacobians () forward-mode would be cheaper — Lucid does not yet ship a forward-mode implementation, so this routine is preferred for tall Jacobians ().
Examples
>>> import lucid
>>> from lucid.autograd import jacobian
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> def f(x):
... return x * x
>>> J = jacobian(f, x)
>>> J.shape
(3, 3)