如何解决将 numba-scipy 用于特殊功能的问题
我想让 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 举报,一经查实,本站将立刻删除。