fn

det

Tensor
det(x: Tensor)
source

Compute the determinant of a square matrix.

For a square matrix ARn×nA \in \mathbb{R}^{n \times n} returns the scalar det(A)\det(A). The determinant is the signed volume of the parallelepiped spanned by the rows (or columns) of AA; it is non-zero if and only if AA is invertible.

Parameters

xTensor
Square matrix of shape (*, n, n).

Returns

Tensor

Determinant of shape (*,) (one scalar per batch entry).

Notes

Computed as the product of the diagonal of UU from PA=LUPA = LU together with the sign of the row-permutation PP. Cost is O(n3)O(n^3).

For numerically large matrices det(A)\det(A) can overflow or underflow easily — prefer slogdet which returns (sign,logdetA)(\mathrm{sign},\,\log|\det A|) and is stable across scales.

Examples

>>> import lucid
>>> from lucid.linalg import det
>>> det(lucid.tensor([[1.0, 2.0], [3.0, 4.0]]))
Tensor(-2.0)