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
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>
Copy file name to clipboardexpand all lines: spec/extensions/linear_algebra_functions.md
+24-22
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ Accordingly, the standardization process affords the opportunity to reduce inter
78
78
(function-linalg-cholesky)=
79
79
### linalg.cholesky(x, /, *, upper=False)
80
80
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).
82
82
83
83
<!-- NOTE: once complex numbers are supported, each square matrix must be Hermitian. -->
84
84
@@ -90,13 +90,13 @@ Returns the Cholesky decomposition of a symmetric positive-definite matrix (or a
90
90
91
91
-**upper**: _bool_
92
92
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`.
94
94
95
95
#### Returns
96
96
97
97
-**out**: _<array>_
98
98
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`.
100
100
101
101
(function-linalg-cross)=
102
102
### 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
126
126
(function-linalg-det)=
127
127
### linalg.det(x, /)
128
128
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`.
130
130
131
131
#### Parameters
132
132
@@ -170,9 +170,9 @@ Returns the specified diagonals of a matrix (or a stack of matrices) `x`.
170
170
(function-linalg-eigh)=
171
171
### linalg.eigh(x, /)
172
172
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).
174
174
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 -->
176
176
177
177
#### Parameters
178
178
@@ -186,8 +186,8 @@ Returns the eigenvalues and eigenvectors of a symmetric matrix (or a stack of sy
186
186
187
187
- a namedtuple (`eigenvalues`, `eigenvectors`) whose
188
188
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)`.
191
191
192
192
Each returned array must have the same floating-point data type as `x`.
193
193
@@ -204,7 +204,7 @@ as it requires complex number support.
204
204
(function-linalg-eigvalsh)=
205
205
### linalg.eigvalsh(x, /)
206
206
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`.
208
208
209
209
<!-- NOTE: once complex number support, each matrix must be Hermitian -->
210
210
@@ -233,7 +233,7 @@ as it requires complex number support.
233
233
(function-linalg-inv)=
234
234
### linalg.inv(x, /)
235
235
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`.
237
237
238
238
#### Parameters
239
239
@@ -327,7 +327,7 @@ Raises a square matrix (or a stack of square matrices) `x` to an integer power `
327
327
(function-linalg-matrix_rank)=
328
328
### linalg.matrix_rank(x, /, *, rtol=None)
329
329
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).
331
331
332
332
#### Parameters
333
333
@@ -353,7 +353,7 @@ Alias for {ref}`function-matrix-transpose`.
353
353
(function-linalg-outer)=
354
354
### linalg.outer(x1, x2, /)
355
355
356
-
Computes the outer product of two vectors `x1` and `x2`.
356
+
Returns the outer product of two vectors `x1` and `x2`.
357
357
358
358
#### Parameters
359
359
@@ -374,7 +374,7 @@ Computes the outer product of two vectors `x1` and `x2`.
374
374
(function-linalg-pinv)=
375
375
### linalg.pinv(x, /, *, rtol=None)
376
376
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`.
378
378
379
379
#### Parameters
380
380
@@ -395,7 +395,7 @@ Computes the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of square ma
395
395
(function-linalg-qr)=
396
396
### linalg.qr(x, /, *, mode='reduced')
397
397
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).
399
399
400
400
#### Parameters
401
401
@@ -405,7 +405,7 @@ Computes the qr factorization of a matrix (or a stack of matrices), where `q` is
405
405
406
406
-**mode**: _Literal\[ 'reduced', 'complete' ]_
407
407
408
-
-factorization mode. Should be one of the following modes:
408
+
-decomposition mode. Should be one of the following modes:
409
409
410
410
-`'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)`.
411
411
-`'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
418
418
419
419
- a namedtuple `(q, r)` whose
420
420
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`.
422
422
- 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`.
423
423
424
424
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
476
476
(function-linalg-svd)=
477
477
### linalg.svd(x, /, *, full_matrices=True)
478
478
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.
480
480
481
481
#### Parameters
482
482
@@ -486,24 +486,26 @@ Computes the singular value decomposition `A = USVh` of a matrix (or a stack of
486
486
487
487
-**full_matrices**: _bool_
488
488
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`.
- 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`.
498
500
- 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`.
500
502
501
503
Each returned array must have the same floating-point data type as `x`.
502
504
503
505
(function-linalg-svdvals)=
504
506
### linalg.svdvals(x, /)
505
507
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`.
0 commit comments