MCPcopy
hub / github.com/dask/dask / test_stack

Function test_stack

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…