Skip to content

Commit 7d9752f

Browse files
authored
Add complex number support to linalg.pinv (#564)
1 parent fdfa5bd commit 7d9752f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

spec/API_specification/array_api/linalg.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,36 @@ def outer(x1: array, x2: array, /) -> array:
313313
"""
314314

315315
def pinv(x: array, /, *, rtol: Optional[Union[float, array]] = None) -> array:
316-
"""
316+
r"""
317317
Returns the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of matrices) ``x``.
318318
319+
The pseudo-inverse of a matrix :math:`A`, denoted :math:`A^{+}`, is defined as the matrix that "solves" the least-squares problem :math:`Ax = b` (i.e., if :math:`\overline{x}` is a solution, then :math:`A^{+}` is the matrix such that :math:`\overline{x} = A^{+}b`).
320+
321+
While the pseudo-inverse can be defined algebraically, one can understand the pseudo-inverse via singular value decomposition (SVD). Namely, if
322+
323+
.. math::
324+
A = U \Sigma V^H
325+
326+
is a singular decomposition of :math:`A`, then
327+
328+
.. math::
329+
A^{+} = U \Sigma^{+} V^H
330+
331+
where :math:`U` and :math:`V^H` are orthogonal matrices, :math:`\Sigma` is a diagonal matrix consisting of :math:`A`'s singular values, and :math:`\Sigma^{+}` is then a diagonal matrix consisting of the reciprocals of :math:`A`'s singular values, leaving zeros in place. During numerical computation, only elements larger than a small tolerance are considered nonzero, and all others replaced by zeros.
332+
333+
When ``x`` is a stack of matrices, the function must compute the pseudo-inverse for each matrix in the stack.
334+
319335
Parameters
320336
----------
321337
x: array
322-
input array having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a real-valued floating-point data type.
338+
input array having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a floating-point data type.
323339
rtol: Optional[Union[float, array]]
324340
relative tolerance for small singular values. Singular values approximately less than or equal to ``rtol * largest_singular_value`` are set to zero. If a ``float``, the value is equivalent to a zero-dimensional array having a real-valued floating-point data type determined by :ref:`type-promotion` (as applied to ``x``) and must be broadcast against each matrix. If an ``array``, must have a real-valued floating-point data type and must be compatible with ``shape(x)[:-2]`` (see :ref:`broadcasting`). If ``None``, the default value is ``max(M, N) * eps``, where ``eps`` must be the machine epsilon associated with the real-valued floating-point data type determined by :ref:`type-promotion` (as applied to ``x``). Default: ``None``.
325341
326342
Returns
327343
-------
328344
out: array
329-
an array containing the pseudo-inverses. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion` and must have shape ``(..., N, M)`` (i.e., must have the same shape as ``x``, except the innermost two dimensions must be transposed).
345+
an array containing the pseudo-inverse(s). The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have shape ``(..., N, M)`` (i.e., must have the same shape as ``x``, except the innermost two dimensions must be transposed).
330346
"""
331347

332348
def qr(x: array, /, *, mode: Literal['reduced', 'complete'] = 'reduced') -> Tuple[array, array]:

0 commit comments

Comments
 (0)