Is this intended behaviour

Note: I tried this in a jupyter notebook
Once a particular @jit decorated function raises an error with a particular type, it always raises an error. Below is what i did and saw this behaviour

import numba

@numba.njit
def func(n):
    a = np.array([n])
    return a.sum()
func(1)

The above code raises the following error as expected

In [3]: func(1)

TypingError Traceback (most recent call last)
in
----> 1 func(1)

J:\Softwares\Anaconda\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
413 e.patch_message(msg)
414
→ 415 error_rewrite(e, ‘typing’)
416 except errors.UnsupportedError as e:
417 # Something unsupported is present in the user code, add help info

J:\Softwares\Anaconda\lib\site-packages\numba\core\dispatcher.py in error_rewrite(e, issue_type)
356 raise e
357 else:
→ 358 reraise(type(e), e, None)
359
360 argtypes =

J:\Softwares\Anaconda\lib\site-packages\numba\core\utils.py in reraise(tp, value, tb)
78 value = tp()
79 if value.traceback is not tb:
—> 80 raise value.with_traceback(tb)
81 raise value
82

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
NameError: name ‘np’ is not defined

Which is expected. But, now if i import numpy and try again…it doesn’t work.

import numpy as np

>>> func(1.2)  #This works
1.2

>>> func(1)
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-6-9ed089a72395> in <module>
----> 1 func(1)

J:\Softwares\Anaconda\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
    413                 e.patch_message(msg)
    414
--> 415             error_rewrite(e, 'typing')
    416         except errors.UnsupportedError as e:
    417             # Something unsupported is present in the user code, add help info

J:\Softwares\Anaconda\lib\site-packages\numba\core\dispatcher.py in error_rewrite(e, issue_type)
    356                 raise e
    357             else:
--> 358                 reraise(type(e), e, None)
    359
    360         argtypes = []

J:\Softwares\Anaconda\lib\site-packages\numba\core\utils.py in reraise(tp, value, tb)
     78         value = tp()
     79     if value.__traceback__ is not tb:
---> 80         raise value.with_traceback(tb)
     81     raise value
     82

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
NameError: name 'np' is not defined

I understand that numba cache’s ones user calls it . Here, it took int in the first case and cached the function and the same is called everytime and this causes error because numba runs jit decorated functions separately with no interference from python. But, is it possible to reevaluate a particular type argument without having to re-decorate the original function? I assume, all the evaluated types are also cleared if we redecorate the original function?

Yes, you have to redefine the function for this to work.

1 Like