MCPcopy
hub / github.com/pydata/xarray / test_apply_dask_multiple_inputs

Function test_apply_dask_multiple_inputs

xarray/tests/test_computation.py:1287–1326  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1285@requires_dask
1286@pytest.mark.filterwarnings("ignore:Mean of empty slice")
1287def test_apply_dask_multiple_inputs() -> None:
1288 import dask.array as da
1289
1290 def covariance(x, y):
1291 return (
1292 (x - x.mean(axis=-1, keepdims=True)) * (y - y.mean(axis=-1, keepdims=True))
1293 ).mean(axis=-1)
1294
1295 rs = np.random.default_rng(42)
1296 array1 = da.from_array(rs.random((4, 4)), chunks=(2, 4))
1297 array2 = da.from_array(rs.random((4, 4)), chunks=(2, 4))
1298 data_array_1 = xr.DataArray(array1, dims=("x", "z"))
1299 data_array_2 = xr.DataArray(array2, dims=("y", "z"))
1300
1301 expected = apply_ufunc(
1302 covariance,
1303 data_array_1.compute(),
1304 data_array_2.compute(),
1305 input_core_dims=[["z"], ["z"]],
1306 )
1307 allowed = apply_ufunc(
1308 covariance,
1309 data_array_1,
1310 data_array_2,
1311 input_core_dims=[["z"], ["z"]],
1312 dask="allowed",
1313 )
1314 assert isinstance(allowed.data, da.Array)
1315 xr.testing.assert_allclose(expected, allowed.compute())
1316
1317 parallelized = apply_ufunc(
1318 covariance,
1319 data_array_1,
1320 data_array_2,
1321 input_core_dims=[["z"], ["z"]],
1322 dask="parallelized",
1323 output_dtypes=[float],
1324 )
1325 assert isinstance(parallelized.data, da.Array)
1326 xr.testing.assert_allclose(expected, parallelized.compute())
1327
1328
1329@requires_dask

Callers

nothing calls this directly

Calls 4

computeMethod · 0.95
apply_ufuncFunction · 0.90
from_arrayMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…