You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[[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_nonposdefraise 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.
Unfortunately, I think this is very hard for us to fix without webassembly getting support for floating point exception modes. This would require a whole process with the wasm committees. Probably someone should inquire whether it's a change they'd consider...
np.linalg.cholesky uses np.errstate. Inside Pyodide np.errstate (or np.seterr) will never raise an exception because of lack of floating point exception support in webassembly. This was noted in Issues with exception raising after setting numpy.errstate #156 for example. I have seen cases where np.errstate + try/catch is used for control flow and you sometimes end-up in a very confusing code branch.
As a potential work-around (likely not applicable in iminuit but maybe useful in other cases) scipy.linalg.cholesky does raise an exception on the same data inside Pyodide:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/lib/python3.12/site-packages/scipy/linalg/_decomp_cholesky.py", line 88, in cholesky
c, lower = _cholesky(a, lower=lower, overwrite_a=overwrite_a, clean=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/scipy/linalg/_decomp_cholesky.py", line 36, in _cholesky
raise LinAlgError("%d-th leading minor of the array is not positive "
numpy.linalg.LinAlgError: 2-th leading minor of the array is not positive definite
Activity
hoodmane commentedon Jun 10, 2024
Unfortunately, I think this is very hard for us to fix without webassembly getting support for floating point exception modes. This would require a whole process with the wasm committees. Probably someone should inquire whether it's a change they'd consider...
henryiii commentedon Jun 11, 2024
Maybe NumPy should check for NaN in situations like this if running on WASM?
lesteve commentedon Jun 23, 2024
Just for explicitness:
np.linalg.choleskyusesnp.errstate. Inside Pyodidenp.errstate(ornp.seterr) will never raise an exception because of lack of floating point exception support in webassembly. This was noted in Issues with exception raising after setting numpy.errstate #156 for example. I have seen cases wherenp.errstate+ try/catch is used for control flow and you sometimes end-up in a very confusing code branch.lesteve commentedon Jun 23, 2024
As a potential work-around (likely not applicable in iminuit but maybe useful in other cases)
scipy.linalg.choleskydoes raise an exception on the same data inside Pyodide:agriyakhetarpal commentedon Jun 23, 2024
I have noticed the same problem when running the test suite for
statsmodelsand xfailed for now: statsmodels/statsmodels#9270Shorten note about pyodide/pyodide#4859
agriyakhetarpal commentedon Aug 6, 2026
This will be fixed in NumPy 2.6, via numpy/numpy#32036.
Skip wasm-unsupported SciPy tests and avoid destructor abort