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
After applying numba.njit to a function, float division behavior is no longer that of NumPy, but the one of Python:
# coding: utf-8
import numpy as np
from numba import njit
def func_ok(a, b):
c = np.sin(a * b)
return np.divide(a - b, c)
numba_func_ok = njit(func_ok)
def func_fail(a, b):
c = np.sin(a * b)
return (a - b) / c
numba_func_fail = njit(func_fail)
if __name__ == '__main__':
print(func_ok(0., 0.)) # nan
print(numba_func_ok(0., 0.)) # nan
print(func_fail(0., 0.)) # nan
print(numba_func_fail(0., 0.)) # ZeroDivisionError
My workaround is to use numpy.divide, which luckily is supported in nopython mode.
The text was updated successfully, but these errors were encountered:
astrojuanlu
changed the title
Float division is no longer IEEE754 after njit
Float division is no longer IEEE 754 after njit
Jun 23, 2015
Unfortunately we can't implement both semantics at the same time. We chose to implement the Python semantics over scalars and the Numpy semantics over Numpy arrays.
We could provide a mechanism to disable raising zero division errors. This would also have a performance benefit for those who are willing to deal with the NaN.
After applying
numba.njit
to a function, float division behavior is no longer that of NumPy, but the one of Python:My workaround is to use
numpy.divide
, which luckily is supported innopython
mode.The text was updated successfully, but these errors were encountered: