小编Kri*_*ika的帖子

Numba 在 np.astype 上使用 BoundFunction 无效

我正在尝试编译一个函数,该函数使用 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
Run Code Online (Sandbox Code Playgroud)

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

Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of BoundFunction(array.astype for array(float64, 1d, C)) …
Run Code Online (Sandbox Code Playgroud)

jit numpy python-3.x numba

5
推荐指数
1
解决办法
3086
查看次数

标签 统计

jit ×1

numba ×1

numpy ×1

python-3.x ×1