fn

slogdet

Tensor
slogdet(A: Tensor)
source

Sign and natural log of the absolute determinant.

Returns the pair (sign,logdetA)(\mathrm{sign},\, \log|\det A|) such that

det(A)=signexp(logdetA).\det(A) \,=\, \mathrm{sign} \cdot \exp(\log|\det A|).

Numerically stable for matrices whose determinant would overflow or underflow if computed directly — for instance, large covariance matrices in log-likelihood calculations.

Parameters

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

Returns

Tensor

±1\pm 1 (or 00 for singular matrices), shape (*,).

Notes

Computed via LU as logdetA=ilogUii\log|\det A| = \sum_i \log|U_{ii}| with the sign accumulated from row swaps. Cost is O(n3)O(n^3).

Examples

>>> import lucid
>>> from lucid.linalg import slogdet
>>> sign, logabs = slogdet(lucid.tensor([[1.0, 2.0], [3.0, 4.0]]))
>>> sign, logabs
(Tensor(-1.0), Tensor(0.6931))