I'm trying to compile a function that does some computation on an image patch using numba. Here is part of the code:
@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
I'm able to compile the function, but when I run it, I get the following error message:
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)
^
I checked the numba documentation and np.astype should be supported with just one argument. Do you know what could be causing the problem?
Use np.int64
in place of int
in following places:
xvec = xvec.astype(np.int64)
yvec = yvec.astype(np.int64)