use load_from_data_pointer() instead error in Numba

34 Views Asked by At

Using Numba on one of my function in nopython=True mode is giving me following error

Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x7f7f38074970>.
Failed in nopython mode pipeline (step: native lowering)
use load_from_data_pointer() instead
During: resolving callee type: type(CPUDispatcher(<function locate_photon_cell_by_tree at 0x7f7faf9dd2d0>))

Here is the function in question

@njit
def locate_photon_cell_by_tree(r, z, c, grid):
    """
    Given r and z and start from c, find out a cell containing (r,z).
    """
    NMAX = 1e6

    found = False
    cout = c

    for j in range(int(NMAX)):
        if ((cout['xmin']**2 <= r <= cout['xmax']**2) and 
            (cout['ymin']    <= z <= cout['ymax'])):
            if (cout['children'][0] == 0):
                found = True
                break
                # return cout, found
            
            flag = True
            non_zero_indices = np.nonzero(cout['children'])[0]
            child_indices = cout['children'][non_zero_indices]

            idx = np.where((grid[child_indices]['xmin']**2 <= r) &
                           (r <= grid[child_indices]['xmax']**2) &
                           (grid[child_indices]['ymin'] <= z) &
                           (z <= grid[child_indices]['ymax']))[0]
            
            if idx.size > 0:
                cout = grid[child_indices[idx[0]]]
                flag = False
                break

            # for index in child_indices:
            #     if ((grid[index]['xmin']**2 <= r <= grid[index]['xmax']**2) and 
            #         (grid[index]['ymin']    <= z <= grid[index]['ymax'])):
            #         cout = grid[index]
            #         flag = False
            #         break
            
            if (flag):
                # cout = None
                break
                # return cout, found
        else:
            if cout['parent'] is not None:
                cout = grid[cout['parent']]
            else:
                # cout = None
                break
                # return cout, found
    
    # cout = None
    return cout, found

It is a basic function that takes a point in 2-D space (r,z) and recursively finds the cell which contains it in a quadtree. In my program each cell is a structured numpy array, with fields which contains it's spatial information and information about its parent and children in the tree.

I tried looking it up, apparently this is a bug in Numba. I want to understand two things: what is the cause of this behavior and are there any workarounds to it?

0

There are 0 best solutions below