Hi, I have a question regarding how I can use numba optimally in the following situation. Assume I have a class defined as follows :
class MyClass:
def __init__(self, a, b):
self.a = a
self.b = b
def mymethod(self, x):
*do some complicated computations which involve self.a and self.b*
To use numba, it seems to me I can either put a @jitclass in the above code (and give a specification for the types of each field), or do something like :
@jit
def aux(x, a, b):
*do some complicated computations which involve a and b*
class MyClass:
def __init__(self, a, b):
self.a = a
self.b = b
def mymethod(self, x):
return aux(x, self.a, self.b)
To have an idea of how these two approaches perform, I chose a value for a and b (say a=0.1 and b=1), created an instance of MyClass with these, and did the comparison. I was also curious to know how they would perform compared to doing
@jit
myfunction(x):
*do the complicated computations involving a and b,
replacing everywhere a by 0.1 and b by 1*
And in both cases I get a significant loss of performance compared to this last piece of code. So my question is : is there any way to, each time I create a new instance of MyClass, compile a function tailored to the values given for a and b, so that when I call myobject.mymethod(x)
, I get something as fast as the last piece of code ?
Thanks in advance for your help !