【发布时间】:2021-02-14 12:47:25
【问题描述】:
@jit(nopython=True)
def f1(x, y):
#if y is None:
# y = x
y[0] = 0
x[0] = 0
return x
@jit(nopython=True)
def f2(x, y):
if y is None:
y = x
#y[0] = 0
x[0] = 0
return x
x = np.zeros(5, dtype='complex128')
f1(x, x.real)
f2(x, x.real)
如果我们在f1 或f2 中取消注释,则会引发以下错误。请注意,y 永远不会是 None,因此 y = x 永远不应执行。此外,无论是否未注释,以下都不会失败:
f1(x, x)
f2(x, x)
f1(x.real, x.real)
f2(x.real, x.real)
是我遗漏了什么,还是 Numba 错误?
File "<ipython-input-117-a1d860b39413>", line 1, in <module>
f2(x, x.real)
File "D:\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 415, in _compile_for_args
error_rewrite(e, 'typing')
File "D:\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 358, in error_rewrite
reraise(type(e), e, None)
File "D:\Anaconda\lib\site-packages\numba\core\utils.py", line 80, in reraise
raise value.with_traceback(tb)
TypingError: Cannot unify array(float64, 1d, A) and array(complex128, 1d, C) for 'y.2',
defined at <ipython-input-115-c97d2a6dc56c> (13)
File "<ipython-input-115-c97d2a6dc56c>", line 13:
def f2(x, y):
<source elided>
y = x
y[0] = 0
^
During: typing of assignment at <ipython-input-115-c97d2a6dc56c> (13)
【问题讨论】:
标签: python python-3.x numpy jit numba