Skip to content

Commit 996111c

Browse files
lezcanokgryte
andauthored
Make the writing of the factorisations in linalg more uniform (#220)
* Added explicit formulae for the factorisations Added properties of the returned matrices in the main description and the return section Uniform: Always say "(or a stack of matrices)" rather than repeating the properties of the matrices. E.g. Do not write "a square matrix (or a stack of square matrices)" but simply "a square matrix (or stack of matrices)" Uniform: Prefer "Returns" over "Computes" at the start of every description. Uniform: Prefer "decomposition" over "factorization" * Remove backticks from equations The presentation of equations will be fixed in a follow-up PR including TeX rendering support. * Add qualifier * Update copy * Remove line break * Add qualifiers Co-authored-by: Athan <kgryte@gmail.com>
1 parent 5ecbce4 commit 996111c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

spec/extensions/linear_algebra_functions.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Accordingly, the standardization process affords the opportunity to reduce inter
7878
(function-linalg-cholesky)=
7979
### linalg.cholesky(x, /, *, upper=False)
8080

81-
Returns the Cholesky decomposition of a symmetric positive-definite matrix (or a stack of symmetric positive-definite matrices) `x`.
81+
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).
8282

8383
<!-- NOTE: once complex numbers are supported, each square matrix must be Hermitian. -->
8484

@@ -90,13 +90,13 @@ Returns the Cholesky decomposition of a symmetric positive-definite matrix (or a
9090

9191
- **upper**: _bool_
9292

93-
- If `True`, the result must be the upper-triangular Cholesky factor. If `False`, the result must be the lower-triangular Cholesky factor. Default: `False`.
93+
- 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`.
9494

9595
#### Returns
9696

9797
- **out**: _&lt;array&gt;_
9898

99-
- an array containing the Cholesky factors for each square matrix. The returned array must have a floating-point data type determined by {ref}`type-promotion` and shape as `x`.
99+
- 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`.
100100

101101
(function-linalg-cross)=
102102
### linalg.cross(x1, x2, /, *, axis=-1)
@@ -126,7 +126,7 @@ Returns the cross product of 3-element vectors. If `x1` and `x2` are multi-dimen
126126
(function-linalg-det)=
127127
### linalg.det(x, /)
128128

129-
Returns the determinant of a square matrix (or stack of square matrices) `x`.
129+
Returns the determinant of a square matrix (or a stack of square matrices) `x`.
130130

131131
#### Parameters
132132

@@ -170,9 +170,9 @@ Returns the specified diagonals of a matrix (or a stack of matrices) `x`.
170170
(function-linalg-eigh)=
171171
### linalg.eigh(x, /)
172172

173-
Returns the eigenvalues and eigenvectors of a symmetric matrix (or a stack of symmetric matrices) `x`.
173+
Returns the eigenvalues and eigenvectors x = QLQᵀ of a symmetric matrix (or a stack of symmetric matrices) `x`, where `Q` is an orthogonal matrix (or a stack of matrices) and `L` is a vector (or a stack of vectors).
174174

175-
<!-- NOTE: once complex number support, each matrix must be Hermitian -->
175+
<!-- NOTE: once complex number support, each matrix must be Hermitian and the returned Q unitary. We might also want to make the dtype of `eigenvalues` unconditionally real -->
176176

177177
#### Parameters
178178

@@ -186,8 +186,8 @@ Returns the eigenvalues and eigenvectors of a symmetric matrix (or a stack of sy
186186

187187
- a namedtuple (`eigenvalues`, `eigenvectors`) whose
188188

189-
- first element must have the field name `eigenvalues` and must be an array consisting of computed eigenvalues. The array containing the eigenvalues must have shape `(..., M)`.
190-
- second element have have the field name `eigenvectors` and must be an array where the columns of the inner most matrices contain the computed eigenvectors. The array containing the eigenvectors must have shape `(..., M, M)`.
189+
- first element must have the field name `eigenvalues` (corresponding to `L` above) and must be an array consisting of computed eigenvalues. The array containing the eigenvalues must have shape `(..., M)`.
190+
- second element have have the field name `eigenvectors` (corresponding to `Q` above) and must be an array where the columns of the inner most matrices contain the computed eigenvectors. These matrices must be orthogonal. The array containing the eigenvectors must have shape `(..., M, M)`.
191191

192192
Each returned array must have the same floating-point data type as `x`.
193193

@@ -204,7 +204,7 @@ as it requires complex number support.
204204
(function-linalg-eigvalsh)=
205205
### linalg.eigvalsh(x, /)
206206

207-
Computes the eigenvalues of a symmetric matrix (or a stack of symmetric matrices) `x`.
207+
Returns the eigenvalues of a symmetric matrix (or a stack of symmetric matrices) `x`.
208208

209209
<!-- NOTE: once complex number support, each matrix must be Hermitian -->
210210

@@ -233,7 +233,7 @@ as it requires complex number support.
233233
(function-linalg-inv)=
234234
### linalg.inv(x, /)
235235

236-
Computes the multiplicative inverse of a square matrix (or a stack of square matrices) `x`.
236+
Returns the multiplicative inverse of a square matrix (or a stack of square matrices) `x`.
237237

238238
#### Parameters
239239

@@ -327,7 +327,7 @@ Raises a square matrix (or a stack of square matrices) `x` to an integer power `
327327
(function-linalg-matrix_rank)=
328328
### linalg.matrix_rank(x, /, *, rtol=None)
329329

330-
Computes the rank (i.e., number of non-zero singular values) of a matrix (or a stack of matrices).
330+
Returns the rank (i.e., number of non-zero singular values) of a matrix (or a stack of matrices).
331331

332332
#### Parameters
333333

@@ -353,7 +353,7 @@ Alias for {ref}`function-matrix-transpose`.
353353
(function-linalg-outer)=
354354
### linalg.outer(x1, x2, /)
355355

356-
Computes the outer product of two vectors `x1` and `x2`.
356+
Returns the outer product of two vectors `x1` and `x2`.
357357

358358
#### Parameters
359359

@@ -374,7 +374,7 @@ Computes the outer product of two vectors `x1` and `x2`.
374374
(function-linalg-pinv)=
375375
### linalg.pinv(x, /, *, rtol=None)
376376

377-
Computes the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of square matrices) `x`.
377+
Returns the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of matrices) `x`.
378378

379379
#### Parameters
380380

@@ -395,7 +395,7 @@ Computes the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of square ma
395395
(function-linalg-qr)=
396396
### linalg.qr(x, /, *, mode='reduced')
397397

398-
Computes the qr factorization of a matrix (or a stack of matrices), where `q` is an orthonormal matrix (or a stack of matrices) and `r` is an upper-triangular matrix (or a stack of matrices).
398+
Returns the qr decomposition x = QR of a matrix (or a stack of matrices) `x`, where `Q` is an orthonormal matrix (or a stack of matrices) and `R` is an upper-triangular matrix (or a stack of matrices).
399399

400400
#### Parameters
401401

@@ -405,7 +405,7 @@ Computes the qr factorization of a matrix (or a stack of matrices), where `q` is
405405

406406
- **mode**: _Literal\[ 'reduced', 'complete' ]_
407407

408-
- factorization mode. Should be one of the following modes:
408+
- decomposition mode. Should be one of the following modes:
409409

410410
- `'reduced'`: compute only the leading `K` columns of `q`, such that `q` and `r` have dimensions `(..., M, K)` and `(..., K, N)`, respectively, and where `K = min(M, N)`.
411411
- `'complete'`: compute `q` and `r` with dimensions `(..., M, M)` and `(..., M, N)`, respectively.
@@ -418,7 +418,7 @@ Computes the qr factorization of a matrix (or a stack of matrices), where `q` is
418418

419419
- a namedtuple `(q, r)` whose
420420

421-
- first element must have the field name `q` and must be an array whose shape depends on the value of `mode` and contain orthonormal matrices. If `mode` is `'complete'`, the array must have shape `(..., M, M)`. If `mode` is `'reduced'`, the array must have shape `(..., M, K)`, where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same size as those of the input `x`.
421+
- first element must have the field name `q` and must be an array whose shape depends on the value of `mode` and contain matrices with orthonormal columns. If `mode` is `'complete'`, the array must have shape `(..., M, M)`. If `mode` is `'reduced'`, the array must have shape `(..., M, K)`, where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same size as those of the input array `x`.
422422
- second element must have the field name `r` and must be an array whose shape depends on the value of `mode` and contain upper-triangular matrices. If `mode` is `'complete'`, the array must have shape `(..., M, M)`. If `mode` is `'reduced'`, the array must have shape `(..., K, N)`, where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same size as those of the input `x`.
423423

424424
Each returned array must have a floating-point data type determined by {ref}`type-promotion`.
@@ -476,7 +476,7 @@ Returns the solution to the system of linear equations represented by the well-d
476476
(function-linalg-svd)=
477477
### linalg.svd(x, /, *, full_matrices=True)
478478

479-
Computes the singular value decomposition `A = USVh` of a matrix (or a stack of matrices) `x`.
479+
Returns the singular value decomposition A = USVh of a matrix (or a stack of matrices) `x` where `U` is a matrix (or a stack of matrices) with orthonormal columns, `S` is a vector of non-negative numbers (or stack of vectors), and `Vh` is a matrix (or a stack of matrices) with orthonormal rows.
480480

481481
#### Parameters
482482

@@ -486,24 +486,26 @@ Computes the singular value decomposition `A = USVh` of a matrix (or a stack of
486486

487487
- **full_matrices**: _bool_
488488

489-
- If `True`, compute full-sized `u` and `vh`, such that `u` has shape `(..., M, M)` and `vh` has shape `(..., N, N)`. If `False`, compute on the leading `K` singular vectors, such that `u` has shape `(..., M, K)` and `vh` has shape `(..., K, N)` and where `K = min(M, N)`. Default: `True`.
489+
- If `True`, compute full-sized `U` and `Vh`, such that `U` has shape `(..., M, M)` and `Vh` has shape `(..., N, N)`. If `False`, compute on the leading `K` singular vectors, such that `U` has shape `(..., M, K)` and `Vh` has shape `(..., K, N)` and where `K = min(M, N)`. Default: `True`.
490490

491491
#### Returns
492492

493-
- **out**: _Tuple\[ &lt;array&gt;, &lt;array&gt;, &lt;array&gt; ]_
493+
<!-- NOTE: once complex number support, each U, Vh must be unitary and we might want to make the returned dtype of `S` unconditionally real -->
494+
495+
- **out**: _Union\[ &lt;array&gt;, Tuple\[ &lt;array&gt;, ... ] ]_
494496

495497
- a namedtuple `(u, s, vh)` whose
496498

497-
- first element must have the field name `u` and must be an array whose shape depends on the value of `full_matrices` and contain unitary array(s) (i.e., the left singular vectors). The left singular vectors must be stored as columns. If `full_matrices` is `True`, the array must have shape `(..., M, M)`. If `full_matrices` is `False`, the array must have shape `(..., M, K)`, where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`.
499+
- first element must have the field name `u` and must be an array whose shape depends on the value of `full_matrices` and contain matrices with orthonormal columns (i.e., the columns are left singular vectors). If `full_matrices` is `True`, the array must have shape `(..., M, M)`. If `full_matrices` is `False`, the array must have shape `(..., M, K)`, where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`.
498500
- second element must have the field name `s` and must be an array with shape `(..., K)` that contains the vector(s) of singular values of length `K`. For each vector, the singular values must be sorted in descending order by magnitude, such that `s[..., 0]` is the largest value, `s[..., 1]` is the second largest value, et cetera. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`.
499-
- third element must have the field name `vh` and must be an array whose shape depends on the value of `full_matrices` and contain unitary array(s) (i.e., the right singular vectors). The right singular vectors must be stored as rows (i.e., the array is the adjoint). If `full_matrices` is `True`, the array must have shape `(..., N, N)`. If `full_matrices` is `False`, the array must have shape `(..., K, N)` where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`.
501+
- third element must have the field name `vh` and must be an array whose shape depends on the value of `full_matrices` and contain orthonormal rows (i.e., the rows are the right singular vectors and the array is the adjoint). If `full_matrices` is `True`, the array must have shape `(..., N, N)`. If `full_matrices` is `False`, the array must have shape `(..., K, N)` where `K = min(M, N)`. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`.
500502

501503
Each returned array must have the same floating-point data type as `x`.
502504

503505
(function-linalg-svdvals)=
504506
### linalg.svdvals(x, /)
505507

506-
Computes the singular values of a matrix (or a stack of matrices) `x`.
508+
Returns the singular values of a matrix (or a stack of matrices) `x`.
507509

508510
#### Parameters
509511

0 commit comments

Comments
 (0)