带numba的周期性条件下的滑动

2024-10-04 01:28:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我根据这篇文章实现了周期性边界条件 slicing numpy array in periodic conditions

它与带有@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.

我如何在numba中处理周期性边界条件的索引切片

“”“

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

“”“

谢谢:)


Tags: innprandomnnarraykernelframeff