Nopython mode inside loop

Hi,

I am solving a life-cycle model. For every point in the state-space, I need to solve a bellman equation. The maximization routine takes a njit objective function and returns the maximum point. The routine is written in njit mode. The problem is, inside for loops, I need to define the objective function and do the maximization.

Here is a sudo-code

@njit
def solve_period():
for x in x_grid:

@njit
def obj()
GoldenSearch(obj, args)

Numba returns an error saying that it does not recognize the obj function. GoldenSearch() is njit compiled and works outside the loop. I need to use it inside the for loops since I am optimizing at every point in the state-space. I also want to make it fast since I have muli-level for loops in the solve_period() function.

Is there a way to make it work?

I’m not sure why that doesn’t work, @Mehrdad_Esfahani. In principle, there is no issue with passing jitted functions to jitted functions: https://numba.pydata.org/numba-doc/dev/user/faq.html

Unless you’re using a very old version of numba, that is (<0.39).