Describe the bug
balanced_allocation raises TypeError: Implicit conversion to a NumPy array is not allowed when called on a dask+cupy raster.
File "xrspatial/balanced_allocation.py", line 359, in balanced_allocation
float(np.sum(fric_weight[alloc == sid]))
^^^^^^^^^^^^^^^^^^^^^^^^^
cupy/_core/core.pyx:1581: TypeError
Root cause: _extract_sources calls da.unique(data).compute(), which on a dask+cupy array returns a cupy array. np.sort(uniq[mask]) does not convert, so source_ids stays cupy. Downstream, source_ids[best_idx] in _allocate_biased produces a cupy alloc, and the masked fric_weight[alloc == sid] tries an implicit numpy conversion.
Expected behavior
balanced_allocation should return a valid allocation raster for all four backends (numpy, cupy, dask+numpy, dask+cupy), matching the test test_two_sources_uniform_friction.
Reproduction
pytest xrspatial/tests/test_balanced_allocation.py::test_two_sources_uniform_friction
The [dask+cupy] parametrization fails; the other three pass.
Fix
Force source_ids to numpy at the end of _extract_sources so all downstream indexing produces numpy arrays.
Describe the bug
balanced_allocationraisesTypeError: Implicit conversion to a NumPy array is not allowedwhen called on a dask+cupy raster.Root cause:
_extract_sourcescallsda.unique(data).compute(), which on a dask+cupy array returns a cupy array.np.sort(uniq[mask])does not convert, sosource_idsstays cupy. Downstream,source_ids[best_idx]in_allocate_biasedproduces a cupyalloc, and the maskedfric_weight[alloc == sid]tries an implicit numpy conversion.Expected behavior
balanced_allocationshould return a valid allocation raster for all four backends (numpy, cupy, dask+numpy, dask+cupy), matching the testtest_two_sources_uniform_friction.Reproduction
The
[dask+cupy]parametrization fails; the other three pass.Fix
Force
source_idsto numpy at the end of_extract_sourcesso all downstream indexing produces numpy arrays.