我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用numba.guvectorize()。
def convolve_laplacien2_gu(image, index, out_image): nx, ny = image.shape for j in range(1,ny-1): out_image[j-1] = np.abs(4*image[index[0],j]-image[index[0]-1,j]-image[index[0]+1,j] -image[index[0],j-1]-image[index[0],j+1]) #@numba.guvectorize(['(float64[:,:], int64[:], int64[:], float64[:])'], '(nx, ny),(),()->()', target='parallel', nopython=True) #def convolve_laplacien2_gu(image, i, j, out_image): # nx, ny = image.shape # out_image[0] = np.abs(4*image[i[0],j[0]]-image[i[0]-1,j[0]]-image[i[0]+1,j[0]] # -image[i[0],j[0]-1]-image[i[0],j[0]+1]) #@numba.jit #def convolve_laplacien2(image): # height, width = image.shape # out_image = np.empty((height-2,width-2)) # i = np.arange(1, height-1)[:, np.newaxis] # j = np.arange(1, width-1)[np.newaxis, :] # convolve_laplacien2_gu(image, i, j, out_image) # # On renormalise l'image : # valmax = np.max(out_image) # valmax = max(1.,valmax)+1.E-9 # out_image *= 1./valmax # return out_image