You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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``.
391
391
392
392
.. note::
393
393
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.
394
394
395
+
The sign of the determinant is given by
396
+
397
+
.. math::
398
+
\operatorname{sign}(\det x) = \begin{cases}
399
+
0 & \textrm{if } \det x = 0 \\
400
+
\frac{\det x}{|\det x|} & \textrm{otherwise}
401
+
\end{cases}
402
+
403
+
where :math:`|\det x|` is the absolute value of the determinant of ``x``.
404
+
405
+
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.
406
+
407
+
**Special Cases**
408
+
409
+
For real-valued floating-point operands,
410
+
411
+
- If the determinant is zero, the ``sign`` should be ``0`` and ``logabsdet`` should be ``-infinity``.
412
+
413
+
For complex floating-point operands,
414
+
415
+
- If the determinant is ``0 + 0j``, the ``sign`` should be ``0 + 0j`` and ``logabsdet`` should be ``-infinity + 0j``.
416
+
417
+
.. note::
418
+
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 to ``sign * exp(logabsdet)`` (although, again, the result may be subject to numerical precision errors).
419
+
395
420
Parameters
396
421
----------
397
422
x: array
398
-
input array having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a real-valued floating-point data type.
423
+
input array having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a floating-point data type.
399
424
400
425
Returns
401
426
-------
402
427
out: Tuple[array, array]
403
428
a namedtuple (``sign``, ``logabsdet``) whose
404
429
405
-
- 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.
406
-
- second element must have the field name ``logabsdet`` and must be an array containing the determinant for each square matrix.
407
-
408
-
For a real matrix, the sign of the determinant must be either ``1``, ``0``, or ``-1``.
430
+
- 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. Must have the same data type as ``x``.
431
+
- 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. If ``x`` is real-valued, the returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. If ``x`` is complex, the returned array must have a real-valued floating-point data type having the same precision as ``x`` (e.g., if ``x`` is ``complex64``, ``logabsdet`` must have a ``float32`` data type).
409
432
410
-
Each returned array must have shape ``shape(x)[:-2]`` and a real-valued floating-point data type determined by :ref:`type-promotion`.
411
-
412
-
.. note::
413
-
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).
433
+
Each returned array must have shape ``shape(x)[:-2]``.
0 commit comments