-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add SVD function specification #114
Conversation
I checked that we have this capability (added in cupy/cupy#3247), so it's straightforward for us to support it: |
|
There's an incompatibility between NumPy and PyTorch missed in number of values returned for |
So it turns out not as straightforward, but is still possible on both CUDA and HIP, see cupy/cupy#4628. btw, we could also note the support for complex numbers will land in the next version (like what we discussed in the eigensolver PR #113). The nice point of SVD is that |
Updated this PR based on the above feedback and meeting discussions. Reordered the output values to follow NumPy |
Updated this PR to return an array, rather than a tuple, when |
Co-authored-by: Leo Fang <leofang@bnl.gov>
Co-authored-by: Leo Fang <leofang@bnl.gov>
Co-authored-by: Leo Fang <leofang@bnl.gov>
Co-authored-by: Leo Fang <leofang@bnl.gov>
Why does Should this flag be dropped for |
Good question @IvanYashchuk. No/fewer boolean keywords would make the design better, that is probably how we'd design it if starting from scratch. I do see that I like the idea of dropping |
The signature |
I think in reality it depends on how things are implemented at the low level. Taking CUDA as an example, this function In fact, I think this interface dates way back to Lapack's But, if we take into account decades of familiarity in numerical routines I don't think changing the API is a good idea, though I don't have strong opinion. |
I'm also in favor of @IvanYashchuk's proposal to have a separate API which only returns singular values. Regarding whether an implementation reuses the same routine for both |
I've updated this proposal (and OP) to no longer include the |
0607525
to
138e963
Compare
Thanks, @leofang, for the review! This PR is ready for merge... |
This PR
Notes
NumPy and Torch order the returned tuple
(u, s, v)
, while TF orders as(s, u, v)
. This proposal follows NumPy.NumPy et al provide a
compute_uv
keyword to indicate whether to return the left and right singular vectors along with the singular values. This proposal omits such a keyword, in favor of a separatesvdvals
specification (see gh-160). This is to promote consistency witheig
andeigvals
and minimize polymorphism within the set of linagl APIs.By default, NumPy computes full matrixes, while TF and Torch do not. This proposal follows NumPy and sets the
full_matrices
keyword argument default asTrue
.MXNet does not currently support any keyword arguments.
Dask currently supports a
coerce_signs
keyword argument to indicate whether or not to apply sign coercion to singular vectors in order to maintain deterministic results. It is alone in this regard.This proposal follows NumPy, Torch, MXNet, JAX, and TF in supporting stacks of matrices. CuPy and Dask do not currently support providing stacks.
NumPy currently supports a
hermitian
keyword argument for speeding up computation; however, it is alone in doing this.TF (and LAPACK) returns both the left and right singular vectors in columns. NumPy returns the left singular vectors in rows (i.e., NumPy returns the adjoint). This proposal follows NumPy.