Skip to content

np.linalg.svd with hermitian=True does not properly sort singular values #15462

@shoyer

Description

@shoyer

Reproducing code example:

svd with hermitian=True (introduced by @eric-wieser in #12693) has a bug with the order of singular values:

import numpy as np

a = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]])
u, s, v = np.linalg.svd(a, hermitian=True)
print(s)

Outputs: [1.41421356e+00 6.07153217e-18 1.41421356e+00]

Per the contract of svd, the singular values should be sorted in descending order, but they aren't here. That's because we simply reverse the order of eigenvalues than sorting, which only suffices if all eigenvalues happen to be positive.

Numpy/Python version information:

1.17.5 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions