Qu

jacobian

Builtin index · REPL & diagnostics

jacobian(f, x)

Input: f, x · Output: no output

What it is

Takes a function f and a point x (number, vector, or matrix), and returns the full Jacobian matrix of f at x as an m x n matrix, where J[i][j] is the derivative of output component i with respect to input component j. Both x and f(x) are flattened in column-major order, so a matrix argument is indexed down its columns. Unlike grad, this takes the *function* rather than an already-computed tracked loss, and does the track/wrt plumbing itself. It runs one forward pass and m backward passes — reverse mode yields one row per sweep, so this is cheapest when the output is smaller than the input. f must reach its result through arithmetic and the autodiff-aware builtins; indexing the argument or calling stop_grad detaches it from the tape and raises an error rather than silently returning zeros. A 1 x 1 result reads back as a plain number, following the same collapse every 1 x 1 matrix gets language-wide. Added in v0.3.0

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
jacobian(f, x)
f —f must reach its result through arithmetic and the autodiff-aware builtins.
x number, vector, or matrixTakes a function f and a point x (number, vector, or matrix), and returns the full Jacobian matrix of f at x as an m x n matrix, where J[i][j] is the derivative of output component i with respect to input component j.
not documented yetUnlike grad, this takes the *function* rather than an already-computed tracked loss, and does the track/wrt plumbing itself. It runs one forward pass and m backward passes — reverse mode yields one row per sweep, so this is cheapest when the output is smaller than the input. Added in v0.3.0.

Examples

No documentation example calls this form yet. The REPL & diagnostics chapter is where one belongs.

How it works

These take a FUNCTION, unlike grad above, which takes an already-tracked loss. Both shapes are kept: grad's is the one a training loop wants (the loss is computed once and several things read it), and this one is what a caller who just wants a derivative at a point wants. They share the tape and eval_grad_seeded; neither is a reimplementation of the other.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.