Sign & Log-Det

Shipping
matrix_slogdet

Numerically stable log-determinant: returns sign and ln|det A| separately

Signature

Inputs

  • aSignal|ArrayrequiredA square 2-D matrix.

Outputs

  • signScalarThe sign of the determinant: $+1$, $-1$, or $0$ if singular.
  • ln_abs_detScalarThe natural log of the absolute determinant, $\ln|\det A|$.

Description

Sign & Log-Det computes the determinant in a numerically stable, overflow-safe form: it returns the sign (, , or when singular) and on separate output ports. This mirrors numpy's slogdet and is the recommended way to reason about determinants of large or ill-scaled matrices, where the raw determinant would overflow to or underflow to .

To recover the ordinary determinant, combine the outputs as . Both outputs are dimensionless scalars, and the computation runs through the MKL LAPACK backend.

Mathematics

Examples

Reconstructing the determinant

For a large positive-definite covariance matrix whose determinant is astronomically small, sign reads and ln_abs_det reads a large negative number. Their combination reproduces without ever underflowing to literal .

Applications

  • Gaussian / multivariate-normal log-likelihoods, which need $\ln\det\Sigma$ directly.
  • Comparing determinants across many matrices in the log domain to avoid overflow.
  • Robust singularity detection via the $0$ sign flag.

Neat

Working in the log domain keeps determinants of high-dimensional covariance matrices finite where the raw value would overflow floating point.

The sign is factored out cleanly, so a negative or singular determinant is unambiguous even when $|\det A|$ spans hundreds of orders of magnitude.

Known issues

For a singular matrix `sign` is $0$ and `ln_abs_det` is $-\infty$; downstream nodes should guard against the infinite log.

The two outputs must be recombined via $\text{sign}\cdot e^{\ln|\det|}$ to get a plain determinant — a single-port reading is incomplete.

See also

log-determinantslogdetlinear-algebralapackmklstateless