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.The sign of the determinant is given by
\[\begin{split}\operatorname{sign}(\det x) = \begin{cases} 0 & \textrm{if } \det x = 0 \\ \frac{\det x}{|\det x|} & \textrm{otherwise} \end{cases}\end{split}\]where \(|\det x|\) is the absolute value of the determinant of
x
.When
x
is a stack of matrices, the function must compute the sign and natural logarithm of the absolute value of the determinant for each matrix in the stack.Special Cases
For real-valued floating-point operands,
If the determinant is zero, the
sign
should be0
andlogabsdet
should be-infinity
.
For complex floating-point operands,
If the determinant is
0 + 0j
, thesign
should be0 + 0j
andlogabsdet
should be-infinity + 0j
.
Note
Depending on the underlying algorithm, when the determinant is zero, the returned result may differ from
-infinity
(or-infinity + 0j
). In all cases, the determinant should be equal tosign * exp(logabsdet)
(although, again, the result may be subject to numerical precision errors).- 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
) whosefirst 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. Must have the same data type asx
.second element must have the field name
logabsdet
and must be an array containing the natural logarithm of the absolute value of the determinant for each square matrix. Ifx
is real-valued, the returned array must have a real-valued floating-point data type determined by Type Promotion Rules. Ifx
is complex, the returned array must have a real-valued floating-point data type having the same precision asx
(e.g., ifx
iscomplex64
,logabsdet
must have afloat32
data type).
Each returned array must have shape
shape(x)[:-2]
.
Notes
Changed in version 2022.12: Added complex data type support.