在 类 上使用 numba?
Use numba on classes?
我可以在 0.6 numba 文档中找到一些关于如何使用的信息 numba on classes:
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.")
但我没有在 0.16 documentation 中找到。是否总是可以在 类 上使用 numba?
我最后听说 numba
class 支持 是他们 temporarily removed it since 0.12
从 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())
documentation 表示只允许使用方法和属性,因此不幸的是,包括 describe
功能目前无法使用。
我可以在 0.6 numba 文档中找到一些关于如何使用的信息 numba on classes:
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.")
但我没有在 0.16 documentation 中找到。是否总是可以在 类 上使用 numba?
我最后听说 numba
class 支持 是他们 temporarily removed it since 0.12
从 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())
documentation 表示只允许使用方法和属性,因此不幸的是,包括 describe
功能目前无法使用。