Refactors 28 functions into numpy's ufunc style#5423
Draft
drculhane wants to merge 3 commits intoBears-R-Us:mainfrom
Draft
Refactors 28 functions into numpy's ufunc style#5423drculhane wants to merge 3 commits intoBears-R-Us:mainfrom
drculhane wants to merge 3 commits intoBears-R-Us:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This may never get reviewed or merged, but it was important to me to complete it.
28 functions (abs, fabs, ceil, floor, trunc, round, sign, isfinite, isinf, isnan, sin, cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, arcsinh, arccosh, arctanh, log, log2, log10, log1p, exp, expm1) have been rewritten into a framework that supports the out and where parameters of numpy ufuncs.
The new code starts in the general vicinity of line 2979 in numpy/numeric.py, and continues for the rest of the file. Although it's a lot of text, there's also a lot of structure to it.
This class:
is used to tell the API:
Here's an example of a validation and a precompute:
A UfuncSpec object is created for each of the 28 functions.
Each of the 28 functions calls ufunc_unary something like this:
return ufunc_unary(ABS_SPEC, x, out=out, where=where)Then ufunc_unary does all of the dtype handling, broadcasting of dimensions as needed, casting of types as needed, and implementation of where and out.
It passes all the unit tests, but this has been a big enough project that I may very well have missed things.