Skip to content

Commit e471e8a

Browse files
asmeurerkgryte
andauthored
Clarify matmul error conditions and fix linalg docs (#282)
* Fix the input description for cholesky() * Add some additional error cases for @ and matmul Also use more consistent variable names for the shapes in the error cases. * Fix the output shape for qr(mode='complete').r * Clarify what K equals in the svd and svdvals specifications * Use consistent naming conventions * Use consistent naming conventions * Use consistent naming conventions * Restore changes Co-authored-by: Athan <[email protected]>
1 parent c08d302 commit e471e8a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

spec/API_specification/array_object.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,9 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
883883
#### Raises
884884
885885
- if either `self` or `other` is a zero-dimensional array.
886-
- if `self` is a one-dimensional array having shape `(N)`, `other` is a one-dimensional array having shape `(M)`, and `N != M`.
886+
- if `self` is a one-dimensional array having shape `(K)`, `other` is a one-dimensional array having shape `(L)`, and `K != L`.
887+
- if `self` is a one-dimensional array having shape `(K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.
888+
- if `self` is an array having shape `(..., M, K)`, `other` is a one-dimensional array having shape `(L)`, and `K != L`.
887889
- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.
888890
889891
(method-__mod__)=

spec/API_specification/linear_algebra_functions.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
5252
#### Raises
5353

5454
- if either `x1` or `x2` is a zero-dimensional array.
55-
- if `x1` is a one-dimensional array having shape `(N)`, `x2` is a one-dimensional array having shape `(M)`, and `N != M`.
55+
- if `x1` is a one-dimensional array having shape `(K)`, `x2` is a one-dimensional array having shape `(L)`, and `K != L`.
56+
- if `x1` is a one-dimensional array having shape `(K)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
57+
- if `x1` is an array having shape `(..., M, K)`, `x2` is a one-dimensional array having shape `(L)`, and `K != L`.
5658
- if `x1` is an array having shape `(..., M, K)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
5759

5860
(function-matrix-transpose)=

spec/extensions/linear_algebra_functions.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Whether an array library explicitly checks whether an input array is a symmetric
9090

9191
- **x**: _&lt;array&gt;_
9292

93-
- input array having shape `(..., M, M)` and whose innermost two dimensions form square matrices. Should have a floating-point data type.
93+
- input array having shape `(..., M, M)` and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a floating-point data type.
9494

9595
- **upper**: _bool_
9696

@@ -431,7 +431,7 @@ Whether an array library explicitly checks whether an input array is a full colu
431431
- a namedtuple `(Q, R)` whose
432432

433433
- 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`.
434-
- 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`.
434+
- 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, N)`. 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`.
435435

436436
Each returned array must have a floating-point data type determined by {ref}`type-promotion`.
437437

@@ -516,7 +516,7 @@ Returns a singular value decomposition A = USVh of a matrix (or a stack of matri
516516
- a namedtuple `(U, S, Vh)` whose
517517

518518
- 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`.
519-
- 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`.
519+
- 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`, where `K = min(M, N)`. 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`.
520520
- 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`.
521521

522522
Each returned array must have the same floating-point data type as `x`.
@@ -536,7 +536,7 @@ Returns the singular values of a matrix (or a stack of matrices) `x`.
536536

537537
- **out**: _&lt;array&gt;_
538538

539-
- 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`. The returned array must have the same floating-point data type as `x`.
539+
- an array with shape `(..., K)` that contains the vector(s) of singular values of length `K`, where `K = min(M, N)`. 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`. The returned array must have the same floating-point data type as `x`.
540540

541541
(function-linalg-tensordot)=
542542
### linalg.tensordot(x1, x2, /, *, axes=2)

0 commit comments

Comments
 (0)