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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With