Skip to content

scipy.linalg.pinvh gives incorrect results #12515

@abhinavnatarajan

Description

@abhinavnatarajan

scipy.linalg.pinvh (computing the Moore-Penrose pseduoinverse) gives numerically incorrect results which do not satisfy the Moore-Penrose conditions. The results substantially differ from the output of scipy.linalg.pinv for the following Hermitian matrix.

Reproducing code example:

import numpy as np
from scipy.linalg import pinvh, pinv

x = np.array([[1,-1, 0], [-1, 2, -1], [0, -1, 1]])
y1 = pinvh(x)
y2 = pinv(x)

np.allclose(np.matmul(np.matmul(x, y1), x), x) # true
np.allclose(np.matmul(np.matmul(y1, x), y1), y1) # false
np.allclose(np.conjugate(np.matmul(x, y1)), np.matmul(x, y1)) # true
np.allclose(np.conjugate(np.matmul(y1, x)), np.matmul(y1, x)) #true

np.allclose(np.matmul(np.matmul(x, y2), x), x) # true
np.allclose(np.matmul(np.matmul(y2, x), y2), y2) # true
np.allclose(np.conjugate(np.matmul(x, y2)), np.matmul(x, y2)) # true
np.allclose(np.conjugate(np.matmul(y2, x)), np.matmul(y2, x)) #true

The analytically computed eigenvalues of this matrix are 3, 1, and 0. The reported eigenvalues from eigvals and eigvalsh are 3, 1, and -3.36770206e-17+0.j, or 3, 1, and 3.92505363e-17 respectively.

Scipy/Numpy/Python version information:

1.4.1 1.18.1 sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.linalg

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions