Python 用numba在周期条件下切片numpy阵列

Python 用numba在周期条件下切片numpy阵列,python,numpy,numba,Python,Numpy,Numba,我有一段代码,通过在fframe上使用周期性边界条件,在fframe中添加内核 我根据这篇文章实现了周期性边界条件 它与带有@jit包装器的numba一起工作,但我没有得到任何加速。 当我添加@njit 我犯了这个错误 TypingError: Failed in nopython mode pipeline (step: nopython frontend) Invalid use of Function(<built-in function setitem>) with arg

我有一段代码,通过在fframe上使用周期性边界条件,在fframe中添加内核

我根据这篇文章实现了周期性边界条件

它与带有@jit包装器的numba一起工作,但我没有得到任何加速。 当我添加@njit

我犯了这个错误

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function setitem>) with argument(s) of 
type(s): (array(int64, 2d, C), tuple(array(int64, 2d, C) x 2), array(int32,2d, C))
 * parameterized
In definition 0:

All templates rejected with literals.


谢谢:

一个问题是randint在numba中只接受2个参数:


只要我不添加@njit,它就可以正常工作-您介意告诉我们您遇到了什么错误吗?很抱歉,我添加了错误。您可以尝试使用@jit而不是@njit吗?它可能没有njit那么快,但我敢打赌它是有效的。它与jit而不是njit一起工作,但我看不到任何速度的提高。也许用户可以帮助?实际上不是。如果删除最后一行,代码将运行。问题在于切片。我使用的numba版本是0.43.1,你能解释一下吗?我应该使用numpy random吗?
kernell = np.random.randint(0,10,(25,25))
fframe = np.random.randint(0,2,(77,77))

@njit
def init_test(frame, kernel, nn):
    dimXsp, dimYsp = kernel.shape
    dimXfr, dimYfr =frame.shape

    Xcoord = np.random.randint(0,dimXfr,nn)
    Ycoord = np.random.randint(0,dimYfr,nn)

    black = frame * 0

    for ff in prange(nn):
        sl0 = np.arange(Xcoord[ff]-dimXsp//2,Xcoord[ff]+dimXsp//2+1).reshape(-1,1)% dimXfr
        sl1 = np.arange(Ycoord[ff]-dimYsp//2,Ycoord[ff]+dimYsp//2+1).reshape(1,-1)% dimYfr

        black[sl0,sl1] = kernel

    return Xcoord, Ycoord, black