numba / numba

NumPy aware dynamic Python compiler using LLVM
https://numba.pydata.org/
BSD 2-Clause "Simplified" License
9.6k stars 1.11k forks source link

`sign` with complex values does not match numpy 2.0 #9633

Open eriknw opened 2 days ago

eriknw commented 2 days ago

Reporting a bug

NumPy 2 changes how np.sign handles complex numbers: https://numpy.org/doc/stable/release/2.0.0-notes.html#change-in-how-complex-sign-is-calculated

Numba 0.60 was not updated to match. Here is an illustration:

In [1]: import numpy as np

In [2]: import numba

In [3]: np.__version__
Out[3]: '2.0.0'

In [4]: numba.__version__
Out[4]: '0.60.0'

In [5]: @numba.njit
   ...: def f(a):
   ...:     return np.sign(a)
   ...:

In [6]: np.sign(1 + 1j)
Out[6]: np.complex128(0.7071067811865475+0.7071067811865475j)

In [7]: f(1 + 1j)
Out[7]: (1+0j)
gmarkall commented 2 days ago

Thanks for the report!

Though Numba can work with NumPy 2.0, its semantics are still aligned with NumPy 1.x. The next release, 0.61 is planned to be semantically compatible with NumPy 2.0 (release plans are in https://github.com/numba/numba/issues/9540).

I'll keep this open and label it as a NumPy 2.0 issue so we can track support for this.