Reputation: 7789
I can found in 0.6 numba documentation some informations about how to use 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.")
But i don't found in 0.16 documentation. Is it always possible to use numba on classes ?
Upvotes: 4
Views: 3525
Reputation: 1166
As of version 0.23 there is a numba.jitclass
method. I can say that the following works in version 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())
The documentation says that only methods and properties are allowed, so including the describe
function will unfortunately not work at the moment.
Upvotes: 6
Reputation: 46
The last thing I heard about numba
class support was that they temporarily removed it since 0.12
Upvotes: 3