将np.argsort与numba结合使用时遇到一些问题。
输入坐标是由坐标组成的二维数组,需要按逆时针方式对其进行排序。所有变量都是float64和numy数组的。
@jit
def sortVertices(coord):
yr = coord[:, 1]
xc = coord[:, 0]
xl = np.array([xc.size])
yl = np.array([yr.size])
center_xc = np.sum(xc)/xl
center_yr = np.sum(yr)/yl
theta = np.arctan2(yr-center_yr, xc-center_xc) * 180.0 / np.pi
indices = np.argsort(theta)
x = xc[indices]
y = yr[indices]
coord_new = np.vstack((x, y)).T
return coord_new
我更新了numba。错误:
NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function sortVertices failed at nopython mode lowering due to: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function make_quicksort_impl.<locals>.run_quicksort at 0x1298bc9d8>) found for signature:
run_quicksort(array(float64, 1d, C))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'register_jitable.<locals>.wrap.<locals>.ov_wrap': File: numba/core/extending.py: Line 150.
With argument(s): '(array(float64, 1d, C))':
Rejected as the implementation raised a specific error:
AttributeError: 'function' object has no attribute 'get_call_template'
raised from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numba/core/types/functions.py:511\
谢谢。