8000 ENH: `__array_function__` for `np.einsum` and `np.block` by shoyer · Pull Request #12163 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: __array_function__ for np.einsum and np.block #12163

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

Merged
merged 6 commits into from
Oct 26, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MAINT: add comment explaining _block_dispatcher
  • Loading branch information
shoyer authored Oct 19, 2018
commit 024c728ef42d12a2bf10ce3b44791301c4d66f80
3 changes: 3 additions & 0 deletions numpy/core/shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ def _block(arrays, max_depth, result_ndim, depth=0):


def _block_dispatcher(arrays):
# Use type(...) is list to match the behavior of np.block(), which special
# cases list specifically rather than allowing for generic iterables or
# tuple. Also, we know that list.__array_function__ will never exist.
if type(arrays) is list:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if we'll be breaking backward compatibility by doing this. Maybe isinstance(arrays, collections.Iterable) and not hasattr(arrays, '__array_function__')?

Copy link
Member Author

Choose a reason for hiding this comment

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

My reasoning for picking type(arrays) is list is that it matches np.block(), which hard codes list (not even tuple). And we know that list.__array_function__ will never exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, in that case ignore my comment. I was worried about the case where we might be inadvertently supporting other kinds of containers in the function but not the dispatcher. A comment would be nice, in any case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a comment is definitely a good idea here. Done!

for subarrays in arrays:
for subarray in _block_dispatcher(subarrays):
Expand Down
0