Numba 在 np.astype 上无效使用 BoundFunction

Numba Invalid use of BoundFunction on np.astype

我正在尝试编译一个函数,该函数使用 numba 对图像补丁进行一些计算。这是部分代码:

@jit(nopython=True, parallel=True)
def value_at_patch(img, coords, imgsize, patch_radius):
    x_center = coords[0]; y_center = coords[1];
    r = patch_radius
    s = 2*r+1
    xvec = np.arange(x_center-r, x_center+r+1)
    xvec[xvec <= 0] = 0 #prevent negative index
    xvec = xvec.astype(int)
    yvec = np.arange(y_center-r, y_center+r+1)
    yvec[yvec <= 0] = 0
    yvec = yvec.astype(int)
    A = np.zeros((s,s))

    #do some parallel computation on A

    p = np.any(A)
    return p

我可以编译该函数,但是当我 运行 它时,我收到以下错误消息:

Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of BoundFunction(array.astype for array(float64, 1d, C)) with parameters (Function(<class 'int'>))
 * parameterized
[1] During: resolving callee type: BoundFunction(array.astype for array(float64, 1d, C))
[2] During: typing of call at <ipython-input-17-90e27ac302a8> (42)


File "<ipython-input-17-90e27ac302a8>", line 42:
def value_at_patch(img, coords, imgsize, patch_radius):
    <source elided>
    xvec[xvec <= 0] = 0 #prevent negative index
    xvec = xvec.astype(int)
    ^

我检查了 numba 文档,np.astype 应该只支持一个参数。您知道可能导致问题的原因吗?

在以下位置使用 np.int64 代替 int

xvec = xvec.astype(np.int64)

yvec = yvec.astype(np.int64)