Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _ocl_star_dist(a, n_rays=32):
from gputools import OCLProgram, OCLArray, OCLImage
(np.isscalar(n_rays) and 0 < int(n_rays)) or _raise(ValueError())
n_rays = int(n_rays)
src = OCLImage.from_array(a.astype(np.uint16,copy=False))
dst = OCLArray.empty(a.shape+(n_rays,), dtype=np.float32)
program = OCLProgram(path_absolute("kernels/stardist2d.cl"), build_options=['-D', 'N_RAYS=%d' % n_rays])
program.run_kernel('star_dist', src.shape, None, dst.data, src)
return dst.get()
def _ocl_star_dist3D(lbl, rays, grid=(1,1,1)):
from gputools import OCLProgram, OCLArray, OCLImage
grid = _normalize_grid(grid,3)
# if not all(g==1 for g in grid):
# raise NotImplementedError("grid not yet implemented for OpenCL version of star_dist3D()...")
res_shape = tuple(s//g for s, g in zip(lbl.shape, grid))
lbl_g = OCLImage.from_array(lbl.astype(np.uint16, copy=False))
dist_g = OCLArray.empty(res_shape + (len(rays),), dtype=np.float32)
rays_g = OCLArray.from_array(rays.vertices.astype(np.float32, copy=False))
program = OCLProgram(path_absolute("kernels/stardist3d.cl"), build_options=['-D', 'N_RAYS=%d' % len(rays)])
program.run_kernel('stardist3d', res_shape[::-1], None,
lbl_g, rays_g.data, dist_g.data,
np.int32(grid[0]),np.int32(grid[1]),np.int32(grid[2]))
return dist_g.get()