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

Function test_map_blocks

dask/array/tests/test_array_core.py:1553–1578  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1551
1552
1553def test_map_blocks():
1554 x = np.arange(400).reshape((20, 20))
1555 d = from_array(x, chunks=(7, 7))
1556
1557 e = d.map_blocks(inc, dtype=d.dtype)
1558
1559 assert d.chunks == e.chunks
1560 assert_eq(e, x + 1)
1561
1562 e = d.map_blocks(inc, token="increment")
1563 assert e.name.startswith("increment-")
1564
1565 assert d.map_blocks(inc, token="foo").name != d.map_blocks(dec, token="foo").name
1566
1567 d = from_array(x, chunks=(10, 10))
1568 e = d.map_blocks(lambda x: x[::2, ::2], chunks=(5, 5), dtype=d.dtype)
1569
1570 assert e.chunks == ((5, 5), (5, 5))
1571 assert_eq(e, x[::2, ::2])
1572
1573 d = from_array(x, chunks=(8, 8))
1574 e = d.map_blocks(
1575 lambda x: x[::2, ::2], chunks=((4, 4, 2), (4, 4, 2)), dtype=d.dtype
1576 )
1577
1578 assert_eq(e, x[::2, ::2])
1579
1580
1581def test_map_blocks2():

Callers

nothing calls this directly

Calls 5

from_arrayFunction · 0.90
assert_eqFunction · 0.90
reshapeMethod · 0.80
arangeMethod · 0.45
map_blocksMethod · 0.45

Tested by

no test coverage detected