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

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

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,C))
[2] During: typing of call at <ipython-input-17-90e27ac302a8> (42)


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

我检查了numba文档,只有一个参数支持np.astype。您知道什么可能导致问题吗?

ziqi_wangshuai 回答:Numba在np.astype上无效使用BoundFunction

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

xvec = xvec.astype(np.int64)

yvec = yvec.astype(np.int64)
本文链接:https://www.f2er.com/3158365.html

大家都在问