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
Singular value decomposition of complex valued matrices does not match mathematical definition #45821
Comments
xref: #45063 - conjugate transpose operator feature request |
IIUC, the current SVD documentation uses transpose because previously only real input was supported (and hence using conjugate transpose would have been unnecessary). With the new complex input support in SVD, I would suggest updating the SVD documentation to use conjugate transpose to match the mathematical definition of general SVD. While doing so, also mention that when M is real then V will be real and conjugate transpose falls back to transpose. |
Yes, please just generalize the docs, in this case it seems to be straightforward and the right thing to do. |
The current SVD implementation returns |
As far as I understand what you're saying: yes. |
I'd like to add my 2 cents to this discussion. By looking at the source code, it seems to me that the current behavior or
As the name suggests, it should create a pytorch/aten/src/ATen/native/LinearAlgebraUtils.h Lines 246 to 247 in a814231
However, the comment is wrong: the lapack's function The rest of the code keeps calling it
However, since we are creating the tensor with the wrong strides, we are effectively returning
So, it looks to me that the intention was to return There isn't much that we can to at this point without breaking compatibility, but this confusing/unexpected/nonstandard behavior of Note: in my WIP PR #45562 I fixed |
Sounds great, @antocuni! I agree we should consider deprecating torch.svd once torch.linalg.svd lands. It will also be confusing to have a method torch.Tensor.svd when both functions are in because users may not know which svd it refers to. |
This is something which I didn't think about. What should
FWIW, this is the commit which aims to fix the documentation: |
We should warn/deprecate for a release and then remove both functions for a release. Then we can consider adding torch.Tensor.svd back and mapping it to torch.linalg.svd. |
(sorry guys, I closed the issue by mistake, reopening it) |
You probably do know that |
while working on PR #45562 we realized that we can't fix |
📚 Documentation
Now when
torch.svd
supports complex input both for CPU and CUDA. Let's discuss the docs.Currently, SVD documentation is fully in agreement with the implementation. This function returns
(U, S, V)
such thatinput = U @ diag(S) @ V.T
However, the mathematical definition of SVD is the decomposition of a matrix M such that , where
V^*
is the conjugate transpose ofV
.What is the opinion on this? Should the documentation and implementation match math and be updated such that
A = U @ diag(S) @ V.T.conj()
?Link to
torch.svd
documentation.cc @ezyang @gchanan @zou3519 @bdhirsh @heitorschueroff @anjali411 @dylanbespalko @mruberry @jlin27 @vishwakftw @jianyuh @nikitaved @pearu @vincentqb
The text was updated successfully, but these errors were encountered: