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

Skip to content

BUG: np.linalg.svd hangs forever on a square >=3x3 matrix containing 'inf' #32591

Description

@OttoJHTX

Describe the issue:

np.linalg.svd never returns when given a square float64 matrix of order >= 3 containing at least one inf alongside finite entries. It spins at 100% CPU inside dgesdd indefinitely(observed > 1 hour on a 3x3).

It is a hang, not slowness. A Python-level timeout (signal.SIGALRM) cannot
interrupt it, because control never returns to the interpreter. only an OS-level kill stops the process.

The same numpy version (2.4.2) built against linux arm64 / OpenBLAS returns in ~3 ms for
the case below.

Related behaviour is already handled correctly: a matrix containing nan, or
one that is entirely 'inf', raises "LinAlgError: SVD did not converge" on
both backends. It is the mix of 'inf' and finite values that hangs.

Reproduce the code example:

python
import numpy as np

A = np.array([[np.inf, 1.0, 1.0],
              [1.0,    1.0, 1.0],
              [1.0,    1.0, 1.0]])

np.linalg.svd(A)   

Error message:

No error and no traceback, the process never returns.

Python and NumPy Versions:

numpy 2.4.2
3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0]

Runtime Environment:

[{'numpy_version': '2.4.2',
'python': '3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ]',
'uname': uname_result(system='Darwin', release='25.6.0',
machine='arm64')},
{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
'found': ['ASIMDHP', 'ASIMDDP'],
'not_found': ['ASIMDFHM']}},
{'ignore_floating_point_errors_in_matmul': True}]

np.show_config() build dependencies:

blas:   name: accelerate, detection method: system
lapack: name: accelerate, detection method: system
compilers: clang 15.0.0

macOS 26.6.2 (build 25G83), Apple silicon (arm64).

Linux control: python:3.12-slim container, pip install numpy==2.4.2
(scipy-openblas wheel), same script, every case returns or raises in ms.

How does this issue affect you or how did you find it:

Found via statsmodels, where an ARIMA fit whose optimizer diverges builds a
non-finite approximate Hessian and passes it to np.linalg.pinv. On OpenBLAS
that surfaces as a ConvergenceWarning and a usable result; on Accelerate the
process hangs forever.

The practical impact is that any library computing a pseudo-inverse or SVD on
optimizer output can hang unkillably on macOS, with no warning, no traceback,
and no way to time out from Python. Callers cannot defend against it without
checking np.isfinite on every matrix before every call.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions