-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Conversation
There was a problem hiding this 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: |
There was a problem hiding this comment.
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__')
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
@mhvk can I bother you to look over this final |
There was a problem hiding this 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.
@mhvk I added unit tests for the |
OK, looks good, merging! |
Thanks Marten!
…On Thu, Oct 25, 2018 at 5:52 PM Marten van Kerkwijk < ***@***.***> wrote:
Merged #12163 <#12163> into master.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12163 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ABKS1ikDOBwWfKIDUG4mg9PyuFtfiMetks5uolzNgaJpZM4Xacms>
.
|
__array_function__
for np.einsum
and np.block
xref #12028
These turned out to be slightly easier than I expected.