#4859·pyodide

NumPy: `numpy.linalg.LinAlgError` not thrown

Author: henryiiiCreated Jun 10, 2024Updated Aug 6, 2026
Labelsbug

Bug

The following code:

python
import numpy as np

A = np.array([[1,-2j],[2j,5]])
print(np.linalg.cholesky(A))

B = np.array([[1,3],[2,4]])
np.linalg.cholesky(B)

Produces an error on normal CPython, just like the docs state it should.

pytb
[[1.+0.j 0.+0.j]
 [0.+2.j 1.+0.j]]
Traceback (most recent call last):
  File "/Users/henryschreiner/git/webpages/iscinumpy.gitlab.io/np.py", line 7, in <module>
    np.linalg.cholesky(B)
  File "/usr/local/lib/python3.12/site-packages/numpy/linalg/linalg.py", line 779, in cholesky
    r = gufunc(a, signature=signature, extobj=extobj)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/numpy/linalg/linalg.py", line 115, in _raise_linalgerror_nonposdef
    raise LinAlgError("Matrix is not positive definite")
numpy.linalg.LinAlgError: Matrix is not positive definite

Pyodide does not get the exception, though, and instead just sets NaN's.

To Reproduce

On https://pyodide.org/en/stable/console.html

pycon
>>> import numpy as np
>>> A = np.array([[1,-2j],[2j,5]])
>>> print(np.linalg.cholesky(A))
[[1.+0.j 0.+0.j]
 [0.+2.j 1.+0.j]]
>>> B = np.array([[1,3],[2,4]])
>>> np.linalg.cholesky(B)
array([[nan, nan],
       [nan, nan]])

The same code produces an error outside a pyodide.

Expected behavior

It should throw numpy.linalg.LinAlgError.

Additional context

See https://github.com/scikit-hep/iminuit/pull/995, this is breaking iminuit's test suite.