【发布时间】:2020-01-13 03:45:44
【问题描述】:
我需要创建一个set 作为jitclass 属性,并且它必须以空开头:
import numba as nb
@nb.jitclass([('foo', nb.types.Set(nb.f8))])
class Bar:
def __init__(self):
self.foo = set()
b = Bar()
但它失败了,因为 numba 不知道临时 set 变量包含的对象的类型:
Failed in nopython mode pipeline (step: nopython frontend)
Cannot infer the type of variable '$0.2' (temporary variable),
have imprecise type: set(undefined).
这可行:
import numba as nb
@nb.jitclass([('foo', nb.types.Set(nb.f8))])
class Bar:
def __init__(self):
self.foo = {0.}
self.foo.clear()
b = Bar()
但是解决方案真的很丑。有没有更好的方法来初始化空的set?
我正在使用 Python 3.6 和 Numba 0.45.1
【问题讨论】:
-
这似乎是一个“功能请求”,可能也属于numba issue tracker。
-
是的,我希望能找到类似numba.typed.Dict.empty() 的东西,但从 Numba 0.64 开始,他们仍然说这是一个实验性功能。所以有一个“numba.typed.Set.empty()”需要更长的时间。