slogdet

slogdet(x: array, /) Tuple[array, array]

Returns the sign and the natural logarithm of the absolute value of the determinant of a square matrix (or a stack of square matrices) x.

Note

The purpose of this function is to calculate the determinant more accurately when the determinant is either very small or very large, as calling det may overflow or underflow.

Parameters:

x (array) – input array having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

Returns:

out (Tuple[array, array]) – a namedtuple (sign, logabsdet) whose

  • first element must have the field name sign and must be an array containing a number representing the sign of the determinant for each square matrix.

  • second element must have the field name logabsdet and must be an array containing the determinant for each square matrix.

For a real matrix, the sign of the determinant must be either 1, 0, or -1.

Each returned array must have shape shape(x)[:-2] and a floating-point data type determined by Type Promotion Rules.

Note

If a determinant is zero, then the corresponding sign should be 0 and logabsdet should be -infinity; however, depending on the underlying algorithm, the returned result may differ. In all cases, the determinant should be equal to sign * exp(logsabsdet) (although, again, the result may be subject to numerical precision errors).