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

refactor: improve broadcasting logic readability #2359

Merged
merged 11 commits into from
Apr 6, 2023

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Apr 5, 2023

This PR splits the continuation in broadcasting into separate closures that we can more easily refactor.

@agoose77 agoose77 marked this pull request as ready for review April 5, 2023 15:36
@codecov
Copy link

codecov bot commented Apr 5, 2023

Codecov Report

Merging #2359 (8e45e63) into main (6a24ed0) will increase coverage by 0.00%.
The diff coverage is 87.69%.

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/_broadcasting.py 89.43% <87.69%> (+0.10%) ⬆️

@agoose77 agoose77 temporarily deployed to docs-preview April 5, 2023 18:53 — with GitHub Actions Inactive
@agoose77 agoose77 requested a review from jpivarski April 5, 2023 22:37
Comment on lines +1010 to 1040
def continuation():
# Any EmptyArrays?
if any(x.is_unknown for x in contents):
return broadcast_any_unknown()

# Any NumpyArrays with ndim != 1?
elif any(x.is_numpy and x.purelist_depth != 1 for x in contents):
return broadcast_any_nd_numpy()

# Any IndexedArrays?
elif any((x.is_indexed and not x.is_option) for x in contents):
return broadcast_any_indexed()

# Any UnionArrays?
elif any(x.is_union for x in contents):
return broadcast_any_union()

# Any option-types?
elif any(x.is_option for x in contents):
return broadcast_any_option()

# Any list-types?
elif any(x.is_list for x in contents):
return broadcast_any_list()

# Any RecordArrays?
elif any(x.is_record for x in contents):
return broadcast_any_record()

else:
raise ak._errors.wrap_error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, this is the summary, the high-level overview of how broadcasting works. Splitting it out like this really helps to see this big picture! (And it's safer in that it limits variable scope.)

@agoose77 agoose77 merged commit 29f89d8 into main Apr 6, 2023
@agoose77 agoose77 deleted the agoose7/refactor-broadcast-readability branch April 6, 2023 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants