forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: Allow comparisons with and between any python integers
This implements comparisons between NumPy integer arrays and arbitrary valued Python integers when weak promotion is enabled. To achieve this: * I allow abstract DTypes (with small bug fixes) to register as loops (`ArrayMethods`). This is fine, you just need to take more care. It does muddy the waters between promotion and not a bit if the result DType would also be abstract. (For the specific case it doesn't, but in general it does.) * A new `resolve_descriptors_raw` function, which does the same job as `resolve_descriptors` but I pass it this scalar argument (can be expanded, but starting small). * This only happens *when available*, so there are some niche paths were this cannot be used (`ufunc.at` and the explicit resolution function right now), we can deal with those by keeping the previous rules (things will just raise trying to convert). * The function also gets the actual `arrays.dtype` instances while I normally ensure that we pass in dtypes already cast to the correct DType class. (The reason is that we don't define how to cast the abstract DTypes as of now, and even if we did, it would not be what we need unless the dtype instance actually had the value information.) * There are new loops added (for combinations!), which: * Use the new `resolve_descriptors_raw` (a single function dealing with everything) * Return the current legacy loop when that makes sense. * Return an always true/false loop when that makes sense. * To achieve this, they employ a hack/trick: `get_loop()` needs to know the value, but only `resolve_descriptors_raw()` does right now, so this is encoded on whether we use the `np.dtype("object")` singleton or a fresh instance! (Yes, probably ugly, but avoids channeling things to more places.) Additionally, there is a promoter to say that Python integer comparisons can just use `object` dtype (in theory weird if the input then wasn't a Python int, but that is breaking promises).
- Loading branch information
Showing
12 changed files
with
634 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.