MAINT: Removed duplicated code around ufunc->identity#8952
Conversation
numpy/core/src/umath/reduction.h
Outdated
There was a problem hiding this comment.
This stopped being public API in 3626d0c, despite the name suggesting it is - so this change is fine
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
This used to be True when used internally, and 1 when viewed externally.
The upshot is that this fixes #8860.
Ideally, we'd use True for functions like logical_or, and 1 for functions like add
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
Previously, we cached these values in a static variable. Is this something we should keep doing?
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
Could include the ufunc name in the error message, but really we should merge
#8876 before that to pick the right name.
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
assign_identity was never anything but this operation
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
Moving this check to occur first makes cleanup a little easier.
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
I don't think this behaviour is justified, but this is a maintenance commit, so for now, we should leave it in
7dded6e to
802e447
Compare
|
It would seem a function to assign the identity is not in itself a crazy idea, as it allows one to calculate it based on |
I think you're confusing "assign" and "calculate" here. A function to calculate the identity from the |
|
Yes, I meant it in the calculate sense, and wondered whether that was ever intended since the function was passed |
You're correct, I overlooked this. AFAICT, these pointers are for implementing loop-specific behaviour, so would match the "different identity for different dtype" cases. If we do want this in future, I think it should be performed at a higher level - as a The only situation I can construct where loop-specific identities would be useful is if For all the numeric types, casting is sufficient to produce the different values |
|
I think you're right it would mostly be useful to make things dtype-dependent (including perhaps structured arrays). In any case, it seems the code as is doesn't really allow that, and the current PR does not preclude adding that later. |
|
@mhvk: Any more comments? Does this look ready to merge to you? |
|
I'm still on an observing run, and while this all looks OK, I haven't really thought more about it, so it may be good to have someone else have a look. |
|
☔ The latest upstream changes (presumably #8876) made this pull request unmergeable. Please resolve the merge conflicts. |
5192858 to
81b5d9e
Compare
|
Any chance someone could take a look at this? |
|
Needs rebase. |
|
Relatedly, what happened to @homu? |
81b5d9e to
fb2f67c
Compare
|
Man, kdiff3 was awful for rebasing that. Sorted now. |
e2fed71 to
551a12d
Compare
There didn't seem to be any value to a `assign_identity` function - all we actually care about is the value to assign. This also fixes numpy#8860 as a side-effect, and paves the way for: * easily adding more values (numpy#7702) * using the identity in more places (numpy#834)
551a12d to
31fd25d
Compare
|
@charris: Does this one look ready? |
|
@charris: Ping |
mhvk
left a comment
There was a problem hiding this comment.
This does all look OK, so unless @charris or @jaimefrio objects in the next day or so, I'll merge.
Just to be sure, am I correct to assume that given NPY_NOEXPORT, we do not have to worry about anyone using this directly?
|
You can see it was removed from the API in this commit |
|
@mhvk: looks like there are no objections |
|
OK, merged! |
There didn't seem to be any value to a
assign_identityfunction - all weactually care about is the value to assign.
This paves the way for:
This also fixes #8860 as a side-effect, but introduces a different problem elsewhere:
np.add.reduce(np.array([], object))- previouslyFalse, now0(good)np.logical_or.reduce(np.array([], object))- previouslyFalse, now0(not so good)The latter of these is fixed by #8955 which can be merged after this PR.
This seems to be better behaviour, since at least
0is whatnp.logical_or.identityreturns. In a future commit, I think we should distinguish betweenTrueand1in the identity, but I don't want to change too much at once, so I'm leaving that for another PR