Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: np.linalg.svd(..., hermitian=True) returns non-unitary vh (#31347)#31459

Merged
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31347
May 18, 2026
Merged

BUG: np.linalg.svd(..., hermitian=True) returns non-unitary vh (#31347)#31459
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31347

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented May 18, 2026

Backport of #31347.

  • Explicitly remove 0 from eigenvalue signs to ensure that vh is unitary.
  • Add Hermitian SVD test that has 0 as a singular value.

PR summary

Currently np.linalg.svd can return non-unitary vh due to sign 0 appearing when input array is singular.
This PR fixes the issue.

>>> import numpy as np
>>> res = np.linalg.svd(np.array([[1, 0], [0, 0]]), hermitian=True)
>>> res.Vh
array([[1., 0.],
       [0., 0.]])

AI Disclosure

I've used ChatGPT to ensure that my PR is following the guideline. No codes are generated by AI.

…umpy#31347)

* Explicitly remove 0 from eigenvalue signs to ensure that vh is unitary.
* Add Hermitian SVD test that has 0 as a singular value.
@charris charris added this to the 2.4.6 release milestone May 18, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels May 18, 2026
@charris charris merged commit 0c72b0b into numpy:maintenance/2.4.x May 18, 2026
73 checks passed
@charris charris deleted the backport-31347 branch May 18, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants