numba否定了正确的结果,这是一个错误吗?

时间:2019-01-23 06:40:45

标签: python numpy numba

更新我已经在另一个win10中对其进行了测试,但是一切都很好。

我将在问题电脑中重新安装anaconda。

update2 我已经重新安装了anaconda。 numba首先工作;但是,问题在一天后再次出现,WTF。


以下简化示例,这浪费了一天的时间:

Python 3.7.2 (default, Jan  2 2019, 17:07:39) [MSC v.1915 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numba as nb

In [2]: import numpy as np

In [3]: nb.__version__
Out[3]: '0.39.0'

In [4]: np.__version__
Out[4]: '1.15.1'

In [5]: @nb.njit("f8[:](f8[:], f8)")
   ...: def fast_ema(value: np.ndarray, decay: float) -> np.ndarray:
   ...:     ema = np.empty_like(value)
   ...:     avg = 0.0
   ...:     for i in range(len(value)):
   ...:         avg = avg * decay + value[i] * (1 - decay)
   ...:         ema[i] = avg
   ...:     return ema
   ...:         

In [6]: def slow_ema(value: np.ndarray, decay: float) -> np.ndarray:
   ...:     ema = np.empty_like(value)
   ...:     avg = 0.0
   ...:     for i in range(len(value)):
   ...:         avg = avg * decay + value[i] * (1 - decay)
   ...:         ema[i] = avg
   ...:     return ema
   ...:     

In [7]: value = np.arange(10, dtype='f8')

In [9]: fast_ema(value, 0.5)
Out[9]: 
array([ 0.        , -0.5       , -1.25      , -2.125     , -3.0625    ,
       -4.03125   , -5.015625  , -6.0078125 , -7.00390625, -8.00195312])

In [10]: slow_ema(value, 0.5)
Out[10]: 
array([0.        , 0.5       , 1.25      , 2.125     , 3.0625    ,
       4.03125   , 5.015625  , 6.0078125 , 7.00390625, 8.00195312])

In [11]: Out[9].dtype
Out[11]: dtype('float64')

In [12]: Out[10].dtype
Out[12]: dtype('float64')

0 个答案:

没有答案