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

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 13, 2018

xref #12028

These turned out to be slightly easier than I expected.

Copy link
Contributor

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

One minor comment here.

@@ -499,7 +499,16 @@ def _block(arrays, max_depth, result_ndim, depth=0):
return _atleast_nd(arrays, result_ndim)


# TODO: support array_function_dispatch
def _block_dispatcher(arrays):
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!

@shoyer
Copy link
Member Author

shoyer commented Oct 23, 2018

@mhvk can I bother you to look over this final array_function_dispatch PR? :)

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

This looks OK, and hence approved, though arguably the one for block is sufficiently non-trivial that tests might be useful. But it does look fine.

@shoyer
Copy link
Member Author

shoyer commented Oct 25, 2018

@mhvk I added unit tests for the block dispatcher.

@mhvk
Copy link
Contributor

mhvk commented Oct 26, 2018

OK, looks good, merging!

@mhvk mhvk merged commit 5946502 into numpy:master Oct 26, 2018
@shoyer shoyer deleted the einsum-dispatch branch October 26, 2018 01:04
@shoyer
Copy link
Member Author

shoyer commented Oct 26, 2018 via email

@charris charris changed the title ENH: __array_function__ for np.einsum and np.block ENH: __array_function__ for np.einsum and np.block Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants