MCPcopy Create free account
hub / github.com/dask/dask / test_chunk_shape_broadcast

Function test_chunk_shape_broadcast

dask/array/tests/test_array_core.py:6031–6064  ·  view source on GitHub ↗
(ndim)

Source from the content-addressed store, hash-verified

6029
6030@pytest.mark.parametrize("ndim", [0, 1, 3, 8])
6031def test_chunk_shape_broadcast(ndim):
6032 from functools import partial
6033
6034 def f(x, ndim=0):
6035 # Ignore `x` and return arbitrary one-element array of dimensionality `ndim`
6036 # For example,
6037 # f(x, 0) = array(5)
6038 # f(x, 1) = array([5])
6039 # f(x, 2) = array([[5]])
6040 # f(x, 3) = array([[[5]]])
6041 return np.array(5)[(np.newaxis,) * ndim]
6042
6043 array = da.from_array([1] + [2, 2] + [3, 3, 3], chunks=((1, 2, 3),))
6044 out_chunks = ((1, 1, 1),)
6045
6046 # check ``enforce_ndim`` keyword parameter of ``map_blocks()``
6047 out = array.map_blocks(partial(f, ndim=ndim), chunks=out_chunks, enforce_ndim=True)
6048
6049 if ndim != 1:
6050 with pytest.raises(ValueError, match="Dimension mismatch:"):
6051 out.compute()
6052 else:
6053 out.compute() # should not raise an exception
6054
6055 # check ``check_ndim`` keyword parameter of ``assert_eq()``
6056 out = array.map_blocks(partial(f, ndim=ndim), chunks=out_chunks)
6057 expected = np.array([5, 5, 5])
6058 try:
6059 assert_eq(out, expected)
6060 except AssertionError:
6061 assert_eq(out, expected, check_ndim=False)
6062 else:
6063 if ndim != 1:
6064 raise AssertionError("Expected a ValueError: Dimension mismatch")
6065
6066
6067def test_chunk_non_array_like():

Callers

nothing calls this directly

Calls 3

assert_eqFunction · 0.90
map_blocksMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected