在
nopython=True
模式下对我的一个函数使用 Numba 会出现以下错误
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>))
这里是有问题的功能
@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
这是一个基本函数,它在二维空间 (r,z) 中取一个点,然后递归地在四叉树中找到包含它的单元格。在我的程序中,每个单元格都是一个结构化的 numpy 数组,其字段包含它的空间信息以及有关其在树中的父项和子项的信息。
我试着查了一下,显然这是 Numba 中的一个bug。我想了解两件事:这种行为的原因是什么,是否有任何解决方法?