Failed NumPy array broadcasting with Numba

Numba has a @guvectorize decorator that can compile Python code into a generalized ufunc to run on GPU.

So here I have such a function:

@guvectorize([(float32[:,:], float32[:], float32[:])], '(m, n), (f)->(f)', target='cuda')
def getVolSpaceGpu(intersectionPt, xflat, volSpace):
    for i in range(len(intersectionPt)):
        pt = intersectionPt[i]
        nearestGrid = ((xgrid - pt[0])**2 + (ygrid - pt[1])**2 + (zgrid - pt[2])**2).argmin()
        volSpace[nearestGrid] = volSpace[nearestGrid] + 1

    return volSpace

However, running it like this:

global xgrid
global ygrid
global zgrid

global xflat

xgrid = np.arange(-10, 10, 0.1).astype('float32')
ygrid = np.arange(-10, 10, 0.1).astype('float32')
zgrid = np.arange(-1, 5, 0.1).astype('float32')

xgrid, ygrid,zgrid = np.meshgrid(xgrid,ygrid,zgrid)
xflat = xgrid.flatten()
volSpace = np.zeros_like(xflat)

ans = getVolSpaceGPU(intersectionPt, xflat, volSpace)

где intersectionPt is just an array of 3D coordinates (eg intersectionPt = np.array([[1, 2, 3], [4, 5, 6]])Я получаю следующую ошибку:

TypingError: Failed at nopython (nopython frontend)
Invalid usage of - with parameters (array(float32, 1d, A), float32)

Как я могу продолжить отсюда?

0 ответов

Другие вопросы по тегам