BUG: np.linalg.svd(..., hermitian=True) returns non-unitary vh#31347
BUG: np.linalg.svd(..., hermitian=True) returns non-unitary vh#31347EarlMilktea wants to merge 2 commits into
np.linalg.svd(..., hermitian=True) returns non-unitary vh#31347Conversation
Explicitly remove 0 from eigenvalue signs to ensure that vh is unitary
sign contains zero here as x @ x = [[1, 0], [0, 0]].
|
MEMO: I suspect two CI failures are not related to this PR. |
| s, u = eigh(a) | ||
| sgn = sign(s) | ||
| # avoid zero sign | ||
| sgn = np.where(sgn == 0, 1, sgn) |
There was a problem hiding this comment.
Thanks, can we assume that -0 isn't a thing and just use signbit instead of sign?
There was a problem hiding this comment.
I personally prefer my approach to make the result predictable...
There was a problem hiding this comment.
well, there's a performance penalty with this approach
There was a problem hiding this comment.
Yeah, but if we aren't sure (I dunno yet), there is already sorting, etc. going on, so it shouldn't actually matter (where just always feels slightly awkward to me, I guess).
There was a problem hiding this comment.
Anyway, I think it's probably good. But @WarrenWeckesser might have a quick thought and know this a bit better.
There was a problem hiding this comment.
Thank you all for comments. Let me know if there are any updates.
PR summary
Currently
np.linalg.svdcan return non-unitaryvhdue to sign 0 appearing when input array is singular.This PR fixes the issue.
AI Disclosure
I've used ChatGPT to ensure that my PR is following the guideline. No codes are generated by AI.