How to use Python Class with Numba

风格不统一 提交于 2019-12-12 04:17:03

问题


I have Numba 0.24 and it supports classes.

When I try to build the simplest class I can imagine I find an error! What's happening?

from numba import jitclass
@jitclass
class foo:
    x = 2
bar = foo()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-3e0fd8d4bd2b> in <module>()
      3 class foo:
      4     x = 2
----> 5 bar = foo()

TypeError: wrap() missing 1 required positional argument: 'cls'

Am I missing something here?


回答1:


You need to specify a spec:

spec = [('x', nb.int64)]
@nb.jitclass(spec)
class foo(object):
    def __init__(self):
        self.x = 2

bar = foo()
print bar.x

Take a look at the docs. At this point class variables are not supported. You have to use instance variables.



来源:https://stackoverflow.com/questions/35776154/how-to-use-python-class-with-numba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!