MCPcopy Index your code
hub / github.com/pydata/xarray / test_dot_align_coords

Method test_dot_align_coords

xarray/tests/test_dataarray.py:4393–4430  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4391 da.dot(dm3.values) # type: ignore[type-var]
4392
4393 def test_dot_align_coords(self) -> None:
4394 # GH 3694
4395
4396 x = np.linspace(-3, 3, 6)
4397 y = np.linspace(-3, 3, 5)
4398 z_a = range(4)
4399 da_vals = np.arange(6 * 5 * 4).reshape((6, 5, 4))
4400 da = DataArray(da_vals, coords=[x, y, z_a], dims=["x", "y", "z"])
4401
4402 z_m = range(2, 6)
4403 dm_vals1 = range(4)
4404 dm1 = DataArray(dm_vals1, coords=[z_m], dims=["z"])
4405
4406 with xr.set_options(arithmetic_join="exact"):
4407 with pytest.raises(
4408 ValueError, match=r"cannot align.*join.*exact.*not equal.*"
4409 ):
4410 da.dot(dm1)
4411
4412 da_aligned, dm_aligned = xr.align(da, dm1, join="inner")
4413
4414 # nd dot 1d
4415 actual1 = da.dot(dm1)
4416 expected_vals1 = np.tensordot(da_aligned.values, dm_aligned.values, (2, 0))
4417 expected1 = DataArray(expected_vals1, coords=[x, da_aligned.y], dims=["x", "y"])
4418 assert_equal(expected1, actual1)
4419
4420 # multiple shared dims
4421 dm_vals2 = np.arange(20 * 5 * 4).reshape((20, 5, 4))
4422 j = np.linspace(-3, 3, 20)
4423 dm2 = DataArray(dm_vals2, coords=[j, y, z_m], dims=["j", "y", "z"])
4424 da_aligned, dm_aligned = xr.align(da, dm2, join="inner")
4425 actual2 = da.dot(dm2)
4426 expected_vals2 = np.tensordot(
4427 da_aligned.values, dm_aligned.values, axes=([1, 2], [1, 2])
4428 )
4429 expected2 = DataArray(expected_vals2, coords=[x, j], dims=["x", "j"])
4430 assert_equal(expected2, actual2)
4431
4432 def test_matmul(self) -> None:
4433 # copied from above (could make a fixture)

Callers

nothing calls this directly

Calls 6

dotMethod · 0.95
DataArrayClass · 0.90
assert_equalFunction · 0.90
linspaceMethod · 0.80
arangeMethod · 0.80
alignMethod · 0.80

Tested by

no test coverage detected