| 4007 | |
| 4008 | |
| 4009 | def test_blockwise_concatenate(): |
| 4010 | x = da.ones((4, 4, 4), chunks=(2, 2, 2)) |
| 4011 | y = da.ones((4, 4), chunks=(2, 2)) |
| 4012 | |
| 4013 | def f(a, b): |
| 4014 | assert isinstance(a, np.ndarray) |
| 4015 | assert isinstance(b, np.ndarray) |
| 4016 | |
| 4017 | assert a.shape == (2, 4, 4) |
| 4018 | assert b.shape == (4, 4) |
| 4019 | |
| 4020 | return (a + b).sum(axis=(1, 2)) |
| 4021 | |
| 4022 | z = da.blockwise(f, "i", x, "ijk", y, "jk", concatenate=True, dtype=x.dtype) |
| 4023 | assert_eq(z, np.ones(4) * 32) |
| 4024 | |
| 4025 | z = da.blockwise(add, "ij", y, "ij", y, "ij", concatenate=True, dtype=x.dtype) |
| 4026 | assert_eq(z, np.ones((4, 4)) * 2) |
| 4027 | |
| 4028 | def f(a, b, c): |
| 4029 | assert isinstance(a, np.ndarray) |
| 4030 | assert isinstance(b, np.ndarray) |
| 4031 | assert isinstance(c, np.ndarray) |
| 4032 | |
| 4033 | assert a.shape == (4, 2, 4) |
| 4034 | assert b.shape == (4, 4) |
| 4035 | assert c.shape == (4, 2) |
| 4036 | |
| 4037 | return np.ones(2) |
| 4038 | |
| 4039 | z = da.blockwise( |
| 4040 | f, "j", x, "ijk", y, "ki", y, "ij", concatenate=True, dtype=x.dtype |
| 4041 | ) |
| 4042 | assert_eq(z, np.ones(4), check_shape=False) |
| 4043 | |
| 4044 | |
| 4045 | def test_common_blockdim(): |