Jit recompile with new arguments

As usual, thanks very much for making Numba!

There is a recompile() function available on jitted functions. It would be great if it allowed the user to change the original parameters from when the function was first jitted.

In particular, I would like to be able to switch between parallel=True and parallel=False in functions that I import from external Python packages and that have been jitted one way or the other by default.

There is a hack for doing this, as explained in post #1125 (I cannot write links in my posts here). But it is a really hacky way of doing it, so I think it would be much nicer to be able to change the arguments when calling recompile() on the jitted functions.

Would this be possible to implement? Or is it too difficult and not worth the hassle?

@esc do you have an opinion on this? Thanks!

I’m not sure this is the best advice, but: every jitted function has an attribute: py_func. You can grab that to get the original Python function and then just “re-jit” it in whichever way you want (The example is a bit contrived, but you get the idea) :

In [1]: from numba import njit

In [2]: @njit
   ...: def fun(x):
   ...:     return x + 1

In [3]: fun(1)
Out[3]: 2

In [5]: njf = njit(parallel=True)(fun.py_func)

In [6]: njf(2)
/Users/vhaenel/git/numba/numba/core/typed_passes.py:329: NumbaPerformanceWarning:
The keyword argument 'parallel=True' was specified but no transformation for parallel execution was possible.

To find out why, try turning on parallel diagnostics, see https://numba.readthedocs.io/en/stable/user/parallel.html#diagnostics for help.

File "<ipython-input-2-28a5c020e544>", line 2:
def fun(x):

Out[6]: 3

I am so sorry, I have just seen you discovered the py_func approach already, apologies for the noise in this case.