@@ -287,33 +287,6 @@ def _apply_dask_numpy(data, kernel, func):
287287 return out
288288
289289
290- def _apply_cupy (data , kernel , func ):
291- data = data .astype (cupy .float32 )
292- kernel = cupy .asarray (kernel )
293-
294- out = cupy .zeros (data .shape , dtype = data .dtype )
295- out [:] = cupy .nan
296-
297- rows , cols = data .shape
298- krows , kcols = kernel .shape
299- hrows , hcols = int (krows / 2 ), int (kcols / 2 )
300- kernel_values = cupy .zeros_like (kernel , dtype = data .dtype )
301-
302- for y in prange (rows ):
303- for x in prange (cols ):
304- # kernel values are all nans at the beginning of each step
305- kernel_values .fill (np .nan )
306- for ky in range (y - hrows , y + hrows + 1 ):
307- for kx in range (x - hcols , x + hcols + 1 ):
308- if ky >= 0 and ky < rows and kx >= 0 and kx < cols :
309- kyidx , kxidx = ky - (y - hrows ), kx - (x - hcols )
310- if kernel [kyidx , kxidx ] == 1 :
311- kernel_values [kyidx , kxidx ] = data [ky , kx ]
312- out [y , x ] = func (kernel_values )
313-
314- return out
315-
316-
317290def apply (raster , kernel , func = _calc_mean , name = 'focal_apply' ):
318291 """
319292 Returns custom function applied array using a user-created window.
@@ -322,7 +295,7 @@ def apply(raster, kernel, func=_calc_mean, name='focal_apply'):
322295 ----------
323296 raster : xarray.DataArray
324297 2D array of input values to be filtered. Can be a NumPy backed,
325- CuPy backed, or Dask with NumPy backed DataArray.
298+ or Dask with NumPy backed DataArray.
326299 kernel : numpy.ndarray
327300 2D array where values of 1 indicate the kernel.
328301 func : callable, default=xrspatial.focal._calc_mean
@@ -432,10 +405,11 @@ def apply(raster, kernel, func=_calc_mean, name='focal_apply'):
432405 # the function func must be a @ngjit
433406 mapper = ArrayTypeFunctionMapping (
434407 numpy_func = _apply_numpy ,
435- cupy_func = _apply_cupy ,
408+ cupy_func = lambda * args : not_implemented_func (
409+ * args , messages = 'apply() does not support cupy backed DataArray.' ),
436410 dask_func = _apply_dask_numpy ,
437411 dask_cupy_func = lambda * args : not_implemented_func (
438- * args , messages = 'apply() does not support dask with cupy backed DataArray.' ), # noqa
412+ * args , messages = 'apply() does not support dask with cupy backed DataArray.' ),
439413 )
440414 out = mapper (raster )(raster .data , kernel , func )
441415 result = DataArray (out ,
0 commit comments