【发布时间】:2020-06-21 19:31:15
【问题描述】:
与numba 一起工作时,我偶然发现了非常意想不到的行为。我创建了一个nb.njit 函数,在其中我试图创建int8 numpy 数组的nb.typed.List,所以我尝试创建一个对应的numba 类型。
nb.int8[:] # type of the list elements
所以,我通过 lsttype 关键字将此类型设置为 nb.typed.List。
l = nb.typed.List(lsttype=nb.int8[:]) # list of int8 numpy ndarrays
我得到的是:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(class(int8), slice<a:b>)
There are 16 candidate implementations:
- Of which 16 did not match due to:
Overload in function 'getitem': File: <built-in>: Line <N/A>.
With argument(s): '(class(int8), slice<a:b>)':
No match.
我想这意味着numba 正在尝试对nb.int8 类型对象进行切片,就好像它不理解符号一样。
所以,我尝试了另一种方式,创建一个 np.int8 类型的空数组,并使用 nb.typeof 函数。
nb.typeof(np.array([], dtype=np.int8))
它返回了:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'typeof' of type Module(<module 'numba' from '/Users/.../venv37/lib/python3.7/site-packages/numba/__init__.py'>)
这个我不明白! numba怎么看不到自己?
最小的例子很简单:
import numba as nb
import numpy as np
@nb.njit
def v():
print(nb.typeof(np.array([], dtype=np.int8)))
v()
所以我尝试使用相同的功能,但没有@nb.njit。
并打印出来!
array(int8, 1d, C)
另外,我尝试在函数中导入 numba,因为它看不到模块,但它产生了:
numba.core.errors.UnsupportedError: Failed in nopython mode pipeline (step: analyzing bytecode)
Use of unsupported opcode (IMPORT_NAME) found
我也尝试重新安装和更新numba 和numpy。
这是什么诡计?
【问题讨论】: