问题描述
我想让 numba 与 scipy 特殊函数错误函数“scipy.special.erf”兼容,因为我在有限差分方案中使用这个函数,我相信使用 numba 可以加快速度。
为此,我使用 conda 安装了 numba-scipy 0.3.0,其中 should support the special function error function。
然后我构建了一个非常简单的示例,以查看是否可以使用调用 scipy.special.erf 的函数来运行 numba。代码如下:
from numba import jit
import scipy.special as sc
@jit
def f(x,y,N):
for i in range(N):
x +=sc.erf(y)
return x
print(f(1,1,1))
我在这个问题的末尾复制了错误消息。一个问题显然与错误函数调用有关,但我对究竟出了什么问题以及如何修复它感到有些茫然。非常欢迎有关此问题的任何帮助。
错误信息如下:
test.py:4: NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function "f" Failed type inference due to: No implementation of function Function(<ufunc 'erf'>) found for signature:
>>> erf(int64)
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload of function 'erf': File: numba_scipy/special/overloads.py: Line 9.
With argument(s): '(int64)':
No match.
During: resolving callee type: Function(<ufunc 'erf'>)
During: typing of call at test.py (7)
File "test.py",line 7:
def f(x,N):
<source elided>
for i in range(N):
x +=sc.erf(y)
^
@jit
test.py:4: NumbaWarning:
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "f" Failed type inference due to: cannot determine Numba type of <class 'numba.core.dispatcher.LiftedLoop'>
File "test.py",line 6:
def f(x,N):
for i in range(N):
^
@jit
/Users/*************/opt/anaconda3/lib/python3.8/site-packages/numba/core/object_mode_passes.py:177: NumbaWarning: Function "f" was compiled in object mode without forceobj=True,but has lifted loops.
File "test.py",N):
for i in range(N):
^
warnings.warn(errors.NumbaWarning(warn_msg,/Users/******************/opt/anaconda3/lib/python3.8/site-packages/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected,this is deprecated behavIoUr.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behavIoUr-when-using-jit
File "test.py",N):
for i in range(N):
^
warnings.warn(errors.NumbaDeprecationWarning(msg,
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)