Skip to content

Commit 660ed01

Browse files
authored
Add complex number support to linalg.cholesky (#443)
* Add equations * Fix syntax * Update description and equations * Comment out MathJax config * Remove config due to failing build This config does not seem to be needed. SymPy does not include it in its docs. Seems fine for us to omit, as well, given that it causes builds to fail. * Use raw string * Remove backlash
1 parent 3049999 commit 660ed01

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

spec/API_specification/array_api/linalg.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@
22
from .constants import inf
33

44
def cholesky(x: array, /, *, upper: bool = False) -> array:
5-
"""
6-
Returns the lower (upper) Cholesky decomposition x = LLᵀ (x = UᵀU) of a symmetric positive-definite matrix (or a stack of matrices) ``x``, where ``L`` is a lower-triangular matrix or a stack of matrices (``U`` is an upper-triangular matrix or a stack of matrices).
5+
r"""
6+
Returns the lower (upper) Cholesky decomposition of a complex Hermitian or real symmetric positive-definite matrix ``x``.
77
8-
..
9-
NOTE: once complex numbers are supported, each square matrix must be Hermitian.
8+
If ``x`` is real-valued, let :math:`\mathbb{K}` be the set of real numbers $\mathbb{R}$, and, if ``x`` is complex-valued, let $\mathbb{K}$ be the set of complex numbers $\mathbb{C}$.
9+
10+
The lower **Cholesky decomposition** of a complex Hermitian or real symmetric positive-definite matrix :math:`x \in\ \mathbb{K}^{n \times n}` is defined as
11+
12+
.. math::
13+
x = LL^{H} \qquad \text{L $\in\ \mathbb{K}^{n \times n}$}
14+
15+
where :math:`L` is a lower triangular matrix and :math:`L^{H}` is the conjugate transpose when :math:`L` is complex-valued and the transpose when :math:`L` is real-valued.
16+
17+
The upper Cholesky decomposition is defined similarly
18+
19+
.. math::
20+
x = UU^{H} \qquad \text{U $\in\ \mathbb{K}^{n \times n}$}
21+
22+
where :math:`U` is an upper triangular matrix.
23+
24+
When ``x`` is a stack of matrices, the function must compute the Cholesky decomposition for each matrix in the stack.
1025
1126
.. note::
12-
Whether an array library explicitly checks whether an input array is a symmetric positive-definite matrix (or a stack of matrices) is implementation-defined.
27+
Whether an array library explicitly checks whether an input array is Hermitian or a symmetric positive-definite matrix (or a stack of matrices) is implementation-defined.
1328
1429
Parameters
1530
----------
1631
x: array
17-
input array having shape ``(..., M, M)`` and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a real-valued floating-point data type.
32+
input array having shape ``(..., M, M)`` and whose innermost two dimensions form square complex Hermitian or real symmetric positive-definite matrices. Should have a floating-point data type.
1833
upper: bool
19-
If ``True``, the result must be the upper-triangular Cholesky factor ``U``. If ``False``, the result must be the lower-triangular Cholesky factor ``L``. Default: ``False``.
34+
If ``True``, the result must be the upper-triangular Cholesky factor :math:`U`. If ``False``, the result must be the lower-triangular Cholesky factor :math:`L`. Default: ``False``.
2035
2136
Returns
2237
-------
2338
out: array
24-
an array containing the Cholesky factors for each square matrix. If ``upper`` is ``False``, the returned array must contain lower-triangular matrices; otherwise, the returned array must contain upper-triangular matrices. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion` and must have the same shape as ``x``.
39+
an array containing the Cholesky factors for each square matrix. If ``upper`` is ``False``, the returned array must contain lower-triangular matrices; otherwise, the returned array must contain upper-triangular matrices. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have the same shape as ``x``.
2540
"""
2641

2742
def cross(x1: array, x2: array, /, *, axis: int = -1) -> array:

spec/conf.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,7 @@
5050
napoleon_custom_sections = [('Returns', 'params_style')]
5151
default_role = 'code'
5252

53-
# Mathjax configuration
54-
mathjax_config = {
55-
'tex2jax': {
56-
'inlineMath': [ ["\\(","\\)"] ],
57-
'displayMath': [["\\[","\\]"] ],
58-
},
59-
}
60-
53+
# Mathjax configuration:
6154
mathjax3_config = {
6255
"tex": {
6356
"inlineMath": [['\\(', '\\)']],

0 commit comments

Comments
 (0)