Skip to content

Add SVD function specification #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 12, 2021
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions spec/API_specification/linear_algebra_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,35 @@ TODO
TODO

(function-svd)=
### svd()
### svd(x, /, *, compute_uv=True, full_matrices=True)

TODO
Computes the singular value decomposition `A = USV` of a matrix (or stack of matrices) `x`.

#### Parameters

- **x**: _<array>_

- input array having shape `(..., M, N)` and whose innermost two dimensions form matrices on which to perform singular value decomposition. Must have a data type of either `float32` or `float64`.

- **compute_uv**: _bool_

- If `True`, compute the left and right singular vectors and return as `u` and `v`, respectively. Default: `True`.

- **full_matrices**: _bool_

- If `True`, compute full-sized `u` and `v`, such that `u` has shape `(..., M, M)` and `v` has shape `(..., N, N)`. If `False`, compute on the leading `K` singular vectors, such that `u` has shape `(..., M, K)` and `v` has shape `(..., N, K)` and where `K = min(M, N)`. This option must be ignored if `compute_uv` is `False`. Default: `True`.

#### Returns

- **out**: _Union\[ <array>, Tuple\[ <array>, ... ] ]_

- if `compute_uv` is `False`, an array having shape `(..., K)` and containing the vector(s) containing the singular values. For each vector, the values must be sorted in descending order according to 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 size as those of the input `x`.

- if `compute_uv` is `True`, a namedtuple `(u, s, v)` whose

- first element 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 size as those of the input `x`.
- second element must be an array having shape `(..., K)` and contain the vector(s) containing the singular values. For each vector, the values must be sorted in descending order according to 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 size as those of the input `x`.
- third element 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 size as those of the input `x`.

(function-trace)=
### trace(x, /, *, axis1=0, axis2=1, offset=0)
Expand Down