Skip to content

ENH: Validate dispatcher functions in array_function_dispatch #12099

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 3 commits into from
Oct 8, 2018

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 6, 2018

They should have the same signature as the decorated function.

Note: eventually these checks should be optional -- we really only need them to be run as part of NumPy's test suite, not every time numpy is imported.

They should have the same signature as the decorated function.

Note: eventually these checks should be optional -- we really only need them
to be run as part of NumPy's test suite, not every time numpy is imported.
@shoyer
Copy link
Member Author

shoyer commented Oct 6, 2018

@mhvk lt would be great if you could take a look here

@charris charris changed the title Validate dispatcher functions in array_function_dispatch ENH: Validate dispatcher functions in array_function_dispatch Oct 8, 2018
@charris
Copy link
Member

charris commented Oct 8, 2018

Test failure is not relevant. Close/open to trigger new tests.

@charris charris closed this Oct 8, 2018
@charris charris reopened this Oct 8, 2018
@mhvk
Copy link
Contributor

mhvk commented Oct 8, 2018

@shoyer - this looks good. I'm only wondering whether we need the check_signature argument at all - if we're going to turn it off outside of testing, it might make more sense to start with having it always on, and then adding an if statement that uses some internal global variable that is set to True if tests are run. (More generally, not introducing the variable now allows us flexibility later on how we want to do this.)

If we do go with the keyword argument, how about verify_signature or plain verify?

Obviously, none of this is a big deal!

@shoyer
Copy link
Member Author

shoyer commented Oct 8, 2018

@mhvk I originally omitted the keyword argument, but found it handy when writing decorators for functions that forward to other implementations with signatures like *args, **kwargs, e.g., see
https://github.com/shoyer/numpy/blob/array-function-easy-impl/numpy/core/fromnumeric.py#L3383-L3392
https://github.com/shoyer/numpy/blob/array-function-easy-impl/numpy/lib/ufunclike.py#L45-L147

If we do turn this off outside of testing, we should document that verify=True does not guarantee that verification is done, unless the right global/environment variable is set. But I'll hold off on this until/when we notice an actual impact on import times.

I'll switch the keyword argument name to verify, I agree that's a little better.

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.

OK, actual examples of the keyword being useful definitely win the day! Agreed also that we should not worry about the bit of extra time unless we find it is actually significant. I think this is ready to go in, though perhaps a rebase to a single commit is a good idea.

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.

This looks perfect to me -- There should probably be an evironment variable provided that turns verification on by default. I prefer this so implementations could be kept in line with NumPy when testing without having user code break.

@shoyer
Copy link
Member Author

shoyer commented Oct 8, 2018

@hameerabbasi Yes, I agree that an environment variable would be the way to go here (especially if/when we make array_function_dispatch public API for the use of downstream libraries)

@shoyer
Copy link
Member Author

shoyer commented Oct 8, 2018

Remind me, are we OK using the "Squash and merge" workflow on GitHub? I like it because it puts everything into one atomic commit per pull request, but preserve the history of commits when reviewing a pull request (which is lost when rebasing).

I know @charris probably has opinions here.

@charris
Copy link
Member

charris commented Oct 8, 2018

Squash and merge is enabled, so we allow it.

@shoyer shoyer merged commit 2f4bc6f into numpy:master Oct 8, 2018
@shoyer shoyer deleted the array-function-dispatch-validate branch October 8, 2018 19:07
@shoyer
Copy link
Member Author

shoyer commented Oct 8, 2018

@hameerabbasi @mhvk thanks for reviewing this!

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.

4 participants