Skip to content
class

DetBackward

DetBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the determinant det⁡(A)\det(A).

Implements Jacobi's formula by reusing differentiable primitives (inv_op, mT_op, mul_op, broadcast_to_op) so the backward sub-graph is itself differentiable — second-order gradients (Hessians) work without additional code.

Both inputs and outputs are saved: AA is required to form (A−1)⊤(A^{-1})^\top in the backward and det⁡(A)\det(A) is the scalar multiplicative factor.

Math

d=det⁡(A),g=∂L∂d, d = \det(A), \qquad g = \frac{\partial L}{\partial d}, ∂L∂A=broadcast(d⋅g,  shape(A))  ⊙  (A−1)⊤. \frac{\partial L}{\partial A} = \mathrm{broadcast}(d \cdot g,\; \text{shape}(A)) \;\odot\; (A^{-1})^\top.

Shape

  • A: (..., N, N).
  • grad_out: (...,) (matches forward output shape).
  • Output gradient: (..., N, N).

References

Petersen & Pedersen, The Matrix Cookbook (2012), §9.2.1. Magnus & Neudecker, Matrix Differential Calculus (3rd ed.), §8.4.

See Also

InvBackward : Used internally to form (A−1)⊤(A^{-1})^\top.

Attributes

schema_v1OpSchema
"det", one input, AmpPolicy::KeepInput to prevent AMP downcasting before the inverse call.
saved_inputs_[0]Storage
Storage of the input matrix AA.
saved_output_Storage
Storage of the scalar (per-batch) determinant det⁡(A)\det(A).

Instance methods

2
fn

apply

→std::vector<Storage>
int apply(int grad_out)

Compute the gradient {∂L/∂A} from the upstream scalar gradient.

Parameters

grad_outStorage
Upstream gradient ∂L/∂det⁡\partial L/\partial \det with shape matching out_shape_.

Returns

std::vector<Storage>

Single-entry vector {∂L/∂A} aligned with the one differentiable input slot.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

The same gradient, recorded, with its factors recomputed from A.