在课堂上使用numba?

bux*_*bux 4 python-3.x numba

我可以在0.6 numba文档中找到关于如何在类上使用numba的一些信息:

from numba import jit, void, int_, double

# All methods must be given signatures

@jit
class Shrubbery(object):
    @void(int_, int_)
    def __init__(self, w, h):
        # All instance attributes must be defined in the initializer
        self.width = w
        self.height = h

        # Types can be explicitly specified through casts
        self.some_attr = double(1.0)

    @int_()
    def area(self):
        return self.width * self.height

    @void()
    def describe(self):
        print("This shrubbery is ", self.width,
              "by", self.height, "cubits.")
Run Code Online (Sandbox Code Playgroud)

但我没有在0.16文档中找到.是否总是可以在课堂上使用numba?

osc*_*ury 5

从版本0.23开始,有一种numba.jitclass方法.我可以说以下版本在0.26版本中有效

@numba.jitclass([('width', numba.float64), ('height', numba.float64)])
class Shrubbery(object):
    def __init__(self, w, h):
        self.width = w
        self.height = h

    def area(self):
        return self.width * self.height

shrubbery = Shrubbery(10, 20)
print(shrubbery.area())
Run Code Online (Sandbox Code Playgroud)

该文件说,只有方法和属性是允许的,所以包括describe功能可惜不是目前的工作.