I am currently implementing a Python class wrapped by the Numba @jitcalss
decorator.
My problem is about writing recursive methods. I know there are ways of writing recursive methods as iterative methods as well, but in my case, I believe that recursive use helps me to write a more traceable program script. As far as I see, Numba does not directly support recursive methods declared in Numba classes. The code below does not present my case directly but it is equivalent to my problem. When I run the code, the error thrown by the Python is given below as well. Any kind of suggestion/improvement/help is welcome
import numba
spec = []
@numba.experimental.jitclass(spec)
class basicClass(object):
def __init__(self):
pass
def factorial(self,x):
if x==1:
return 1
else:
return x*self.factorial(x-1)
# MAIN BELOW
class_object = basicClass()
class_object.factorial(5)
The error is given below:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
- Resolution failure for literal arguments:
Failed in nopython mode pipeline (step: nopython frontend)
- Resolution failure for literal arguments:
Failed in nopython mode pipeline (step: nopython frontend)
compiler re-entrant to the same function signature
- Resolution failure for non-literal arguments:
None
During: resolving callee type: BoundFunction((<class 'numba.core.types.misc.ClassInstanceType'>, 'factorial') for instance.jitclass.basicClass#22839d9cf70<>)
During: typing of call at <ipython-input-7-ab7b9737001d> (16)
File "<ipython-input-7-ab7b9737001d>", line 16:
def factorial(self,x):
<source elided>
else:
return x*self.factorial(x-1)
^
- Resolution failure for non-literal arguments:
None
During: resolving callee type: BoundFunction((<class 'numba.core.types.misc.ClassInstanceType'>, 'factorial') for instance.jitclass.basicClass#22839d9cf70<>)
During: typing of call at <string> (3)
File "<string>", line 3: