mlx.core.linalg.slogdet#
- slogdet(a: array, *, stream: None | Stream | Device = None) Tuple[array, array]#
Compute the sign and natural log of the absolute value of the determinant of a square matrix.
This function supports arrays with at least 2 dimensions. When the input has more than two dimensions, the sign and log-absolute-determinant are computed for each matrix in the last two dimensions.
For a singular matrix,
signis 0 andlogabsdetis-inf.The determinant can be reconstructed as
det = sign * exp(logabsdet). This is more numerically stable than computing the determinant directly for matrices with large or small determinants.- Parameters:
- Returns:
- The
signandlogabsdetof the determinant.
signis -1, 0, or +1.logabsdetis the natural log of the absolute value of the determinant.
- The
- Return type:
Example
>>> A = mx.array([[1., 2.], [3., 4.]]) >>> sign, logabsdet = mx.linalg.slogdet(A, stream=mx.cpu) >>> sign array(-1, dtype=float32) >>> logabsdet array(0.693147, dtype=float32)