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

fix: minor optimizations for ufuncs #771

Merged
merged 1 commit into from
Jul 29, 2022
Merged

Conversation

henryiii
Copy link
Member

Discovered minor improvements when preparing teaching material for next week.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@github-actions github-actions bot added the needs changelog Might need a changelog entry label Jul 28, 2022
if ufunc is np.equal and method == "__call__" and len(inputs) == 2:
return ufunc(np.asarray(inputs[0]), np.asarray(inputs[1]), **kwargs) # type: ignore[no-any-return]
# Avoid infinite recursion
raw_inputs = [np.asarray(x) for x in inputs]
Copy link
Member Author

@henryiii henryiii Jul 28, 2022

Choose a reason for hiding this comment

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

This allows us to avoid special casing ==; it was recursing before.

Comment on lines -118 to +119
(result,) = kwargs.pop("out", [np.empty(self.shape, self.dtype)])
(result,) = (
kwargs.pop("out")
if "out" in kwargs
else [np.empty(self.shape, self.dtype)]
)
Copy link
Member Author

@henryiii henryiii Jul 28, 2022

Choose a reason for hiding this comment

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

Avoids a temporary useless allocation if out is set.

@henryiii henryiii merged commit 21347de into develop Jul 29, 2022
@henryiii henryiii deleted the henryiii/fix/optimize_ufunc branch July 29, 2022 01:56
@henryiii henryiii removed the needs changelog Might need a changelog entry label Sep 17, 2022
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.

1 participant