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

Function test_stack

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

Source from the content-addressed store, hash-verified

591
592
593def test_stack():
594 a, b, c = (
595 Array(
596 graph_from_arraylike(object(), chunks=(2, 3), shape=(4, 6), name=name),
597 name,
598 chunks=(2, 3),
599 dtype="f8",
600 shape=(4, 6),
601 )
602 for name in "ABC"
603 )
604
605 s = stack([a, b, c], axis=0)
606
607 colon = slice(None, None, None)
608
609 assert s.shape == (3, 4, 6)
610 assert s.chunks == ((1, 1, 1), (2, 2), (3, 3))
611 assert s.chunksize == (1, 2, 3)
612 assert s.dask[(s.name, 0, 1, 0)] == (getitem, ("A", 1, 0), (None, colon, colon))
613 assert s.dask[(s.name, 2, 1, 0)] == (getitem, ("C", 1, 0), (None, colon, colon))
614 assert same_keys(s, stack([a, b, c], axis=0))
615
616 s2 = stack([a, b, c], axis=1)
617 assert s2.shape == (4, 3, 6)
618 assert s2.chunks == ((2, 2), (1, 1, 1), (3, 3))
619 assert s2.chunksize == (2, 1, 3)
620 assert s2.dask[(s2.name, 0, 1, 0)] == (getitem, ("B", 0, 0), (colon, None, colon))
621 assert s2.dask[(s2.name, 1, 1, 0)] == (getitem, ("B", 1, 0), (colon, None, colon))
622 assert same_keys(s2, stack([a, b, c], axis=1))
623
624 s2 = stack([a, b, c], axis=2)
625 assert s2.shape == (4, 6, 3)
626 assert s2.chunks == ((2, 2), (3, 3), (1, 1, 1))
627 assert s2.chunksize == (2, 3, 1)
628 assert s2.dask[(s2.name, 0, 1, 0)] == (getitem, ("A", 0, 1), (colon, colon, None))
629 assert s2.dask[(s2.name, 1, 1, 2)] == (getitem, ("C", 1, 1), (colon, colon, None))
630 assert same_keys(s2, stack([a, b, c], axis=2))
631
632 pytest.raises(ValueError, lambda: stack([]))
633 pytest.raises(ValueError, lambda: stack([a, b, c], axis=3))
634
635 assert set(b.dask.keys()).issubset(s2.dask.keys())
636
637 assert stack([a, b, c], axis=-1).chunks == stack([a, b, c], axis=2).chunks
638
639
640def test_stack_zero_size():

Callers

nothing calls this directly

Calls 6

ArrayClass · 0.90
graph_from_arraylikeFunction · 0.90
stackFunction · 0.90
same_keysFunction · 0.90
setClass · 0.85
keysMethod · 0.45

Tested by

no test coverage detected