|
13 | 13 | from xrspatial import trim
|
14 | 14 | from xrspatial import crop
|
15 | 15 | from xrspatial.zonal import regions
|
| 16 | +from xrspatial.utils import doesnt_have_cuda |
| 17 | + |
16 | 18 |
|
17 | 19 | from xrspatial.tests.general_checks import create_test_raster
|
18 | 20 |
|
@@ -169,26 +171,35 @@ def check_results(backend, df_result, expected_results_dict):
|
169 | 171 | np.testing.assert_allclose(df_result[col], expected_results_dict[col])
|
170 | 172 |
|
171 | 173 |
|
172 |
| -@pytest.mark.parametrize("backend", ['numpy', 'dask+numpy']) |
| 174 | +@pytest.mark.parametrize("backend", ['numpy', 'dask+numpy', 'cupy']) |
173 | 175 | def test_default_stats(backend, data_zones, data_values_2d, result_default_stats):
|
| 176 | + if backend == 'cupy' and doesnt_have_cuda(): |
| 177 | + pytest.skip("CUDA Device not Available") |
174 | 178 | df_result = stats(zones=data_zones, values=data_values_2d)
|
175 | 179 | check_results(backend, df_result, result_default_stats)
|
176 | 180 |
|
177 | 181 |
|
178 |
| -@pytest.mark.parametrize("backend", ['numpy', 'dask+numpy']) |
| 182 | +@pytest.mark.parametrize("backend", ['numpy', 'dask+numpy', 'cupy']) |
179 | 183 | def test_zone_ids_stats(backend, data_zones, data_values_2d, result_zone_ids_stats):
|
| 184 | + if backend == 'cupy' and doesnt_have_cuda(): |
| 185 | + pytest.skip("CUDA Device not Available") |
180 | 186 | zone_ids, expected_result = result_zone_ids_stats
|
181 |
| - df_result = stats(zones=data_zones, values=data_values_2d, zone_ids=zone_ids) |
| 187 | + df_result = stats(zones=data_zones, values=data_values_2d, |
| 188 | + zone_ids=zone_ids) |
182 | 189 | check_results(backend, df_result, expected_result)
|
183 | 190 |
|
184 | 191 |
|
185 |
| -@pytest.mark.parametrize("backend", ['numpy']) |
| 192 | +@pytest.mark.parametrize("backend", ['numpy', 'cupy']) |
186 | 193 | def test_custom_stats(backend, data_zones, data_values_2d, result_custom_stats):
|
187 |
| - # ---- custom stats (NumPy only) ---- |
| 194 | + # ---- custom stats (NumPy and CuPy only) ---- |
| 195 | + if backend == 'cupy' and doesnt_have_cuda(): |
| 196 | + pytest.skip("CUDA Device not Available") |
| 197 | + |
188 | 198 | custom_stats = {
|
189 | 199 | 'double_sum': _double_sum,
|
190 | 200 | 'range': _range,
|
191 | 201 | }
|
| 202 | + |
192 | 203 | nodata_values, zone_ids, expected_result = result_custom_stats
|
193 | 204 | df_result = stats(
|
194 | 205 | zones=data_zones, values=data_values_2d, stats_funcs=custom_stats,
|
@@ -219,7 +230,8 @@ def test_percentage_crosstab_2d(backend, data_zones, data_values_2d, result_perc
|
219 | 230 | @pytest.mark.parametrize("backend", ['numpy', 'dask+numpy'])
|
220 | 231 | def test_crosstab_3d(backend, data_zones, data_values_3d, result_crosstab_3d):
|
221 | 232 | layer, zone_ids, expected_result = result_crosstab_3d
|
222 |
| - df_result = crosstab(zones=data_zones, values=data_values_3d, zone_ids=zone_ids, layer=layer) |
| 233 | + df_result = crosstab(zones=data_zones, values=data_values_3d, |
| 234 | + zone_ids=zone_ids, layer=layer) |
223 | 235 | check_results(backend, df_result, expected_result)
|
224 | 236 |
|
225 | 237 |
|
|
0 commit comments