Skip to content

Commit 35baedc

Browse files
authored
Add complex number support to linalg.solve (#566)
1 parent 32de395 commit 35baedc

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

spec/API_specification/array_api/linalg.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -414,23 +414,34 @@ def slogdet(x: array, /) -> Tuple[array, array]:
414414
"""
415415

416416
def solve(x1: array, x2: array, /) -> array:
417-
"""
418-
Returns the solution to the system of linear equations represented by the well-determined (i.e., full rank) linear matrix equation ``AX = B``.
417+
r"""
418+
Returns the solution of a square system of linear equations with a unique solution.
419+
420+
Let ``x1`` equal :math:`A` and ``x2`` equal :math:`B`. If the promoted data type of ``x1`` and ``x2`` is real-valued, let :math:`\mathbb{K}` be the set of real numbers :math:`\mathbb{R}`, and, if the promoted data type of ``x1`` and ``x2`` is complex-valued, let :math:`\mathbb{K}` be the set of complex numbers :math:`\mathbb{C}`.
421+
422+
This function computes the solution :math:`X \in\ \mathbb{K}^{m \times k}` of the **linear system** associated to :math:`A \in\ \mathbb{K}^{m \times m}` and :math:`B \in\ \mathbb{K}^{m \times k}` and is defined as
423+
424+
.. math::
425+
AX = B
426+
427+
This system of linear equations has a unique solution if and only if :math:`A` is invertible.
419428
420429
.. note::
421-
Whether an array library explicitly checks whether an input array is full rank is implementation-defined.
430+
Whether an array library explicitly checks whether ``x1`` is invertible is implementation-defined.
431+
432+
When ``x1`` and/or ``x2`` is a stack of matrices, the function must compute a solution for each matrix in the stack.
422433
423434
Parameters
424435
----------
425436
x1: array
426-
coefficient array ``A`` having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Must be of full rank (i.e., all rows or, equivalently, columns must be linearly independent). Should have a real-valued floating-point data type.
437+
coefficient array ``A`` having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Must be of full rank (i.e., all rows or, equivalently, columns must be linearly independent). Should have a floating-point data type.
427438
x2: array
428-
ordinate (or "dependent variable") array ``B``. If ``x2`` has shape ``(M,)``, ``x2`` is equivalent to an array having shape ``(..., M, 1)``. If ``x2`` has shape ``(..., M, K)``, each column ``k`` defines a set of ordinate values for which to compute a solution, and ``shape(x2)[:-1]`` must be compatible with ``shape(x1)[:-1]`` (see :ref:`broadcasting`). Should have a real-valued floating-point data type.
439+
ordinate (or "dependent variable") array ``B``. If ``x2`` has shape ``(M,)``, ``x2`` is equivalent to an array having shape ``(..., M, 1)``. If ``x2`` has shape ``(..., M, K)``, each column ``k`` defines a set of ordinate values for which to compute a solution, and ``shape(x2)[:-1]`` must be compatible with ``shape(x1)[:-1]`` (see :ref:`broadcasting`). Should have a floating-point data type.
429440
430441
Returns
431442
-------
432443
out: array
433-
an array containing the solution to the system ``AX = B`` for each square matrix. The returned array must have the same shape as ``x2`` (i.e., the array corresponding to ``B``) and must have a real-valued floating-point data type determined by :ref:`type-promotion`.
444+
an array containing the solution to the system ``AX = B`` for each square matrix. The returned array must have the same shape as ``x2`` (i.e., the array corresponding to ``B``) and must have a floating-point data type determined by :ref:`type-promotion`.
434445
"""
435446

436447
def svd(x: array, /, *, full_matrices: bool = True) -> Union[array, Tuple[array, ...]]:

0 commit comments

Comments
 (0)