Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map nested improvements #613

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cubed/primitive/blockwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,10 @@ def get_results_in_different_scope(out_coords: List[int], *, config: BlockwiseSp
out_coords_tuple = tuple(out_coords)

# get array chunks for input keys, preserving any nested list structure
args = []
get_chunk_config = partial(get_chunk, config=config)
out_key = ("out",) + out_coords_tuple # array name is ignored by key_function
in_keys = config.key_function(out_key)
for in_key in in_keys:
arg = map_nested(get_chunk_config, in_key)
args.append(arg)
name_chunk_inds = list(config.key_function(out_key))
args = map_nested(get_chunk_config, name_chunk_inds)

return config.function(*args)

Expand Down
16 changes: 12 additions & 4 deletions cubed/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def test_map_nested_iterators():
out = map_nested(inc, iter([1, 2]))
assert isinstance(out, map)
assert count == 0
assert list(out) == [2, 3]
assert next(out) == 2
assert count == 1
assert next(out) == 3
assert count == 2

# reset count
Expand All @@ -148,7 +150,9 @@ def test_map_nested_iterators():
out = out[0]
assert isinstance(out, map)
assert count == 0
assert list(out) == [2, 3]
assert next(out) == 2
assert count == 1
assert next(out) == 3
assert count == 2

# reset count
Expand All @@ -161,12 +165,16 @@ def test_map_nested_iterators():
out0 = out[0]
assert isinstance(out0, map)
assert count == 0
assert list(out0) == [2, 3]
assert next(out0) == 2
assert count == 1
assert next(out0) == 3
assert count == 2
out1 = out[1]
assert isinstance(out1, map)
assert count == 2
assert list(out1) == [4, 5]
assert next(out1) == 4
assert count == 3
assert next(out1) == 5
assert count == 4


Expand Down
Loading