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
ENH: Add bitwise_and identity #7373
Conversation
The identity for bitwise_xor is zero.
c139e5e
to
6f8fdd7
Compare
* UFunc has unit of 0, and the order of operations can be reordered | ||
* This case allows reduction with multiple axes at once. | ||
* UFunc has unit of -1, and the order of operations can be reordered | ||
* This case allows reduction with multiple axes at once. Intended for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That last sentence is not strictly necessary. There could potentially be other ufuncs that use this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be others, but I could not think of any. Hence the bit of explanation as to why this otherwise useless macro is there. I suppose it could be "Introduced" instead of "Intended".
Nice! Last week I went to a "Hacker Garten" event, and spent an hour or so introducing NumPy to one of the "hacker gardeners", and this came up in the "easy fix" issue list. We spent about 10 minutes seeing if it would be a good fit for his first PR, which it obviously wasn't. |
For reference, the other option is #7061 which uses
We can choose what to use as the return value in that case, if any, or raise an error. |
Hmmm forgot about that. I admit the object cases are always a little weird. But that is also the case for half the current identities. For non-object, to me this option is "obviously right". |
6f8fdd7
to
12b9a26
Compare
Updated tests. |
@madphysicist The |
Good point. I rescind my comment. |
Testing with |
Current value is 1, which only works for the low order bit. Use -1 instead. Closes numpy#7060.
- test values - test identity for bitwise_or, bitwise_xor, bitwise_and
4680656
to
3ed543e
Compare
OK, works, so squashing that commit into others. The only open questions is what to do with empty object arrays. Because non-empty object arrays do not use the identity, it might be most consistent to raise an error in that case, but currently the identity is returned. |
The identity has changed from 1 to -1.
2e621ef
to
9653c05
Compare
Thanks. @jaimefrio since you already looked at it, do you have a preference whether we should -1 return for empty object arrays, or rather make the identity "crash" on object arrays if used? I can't make up my mind and either way has its downsides ;). |
I guess I prefer erroring out on empty object arrays because "in the face of ambiguity refuse to guess". But it doesn't seem hugely important either way. |
Note that erroring out will reguire a deprecation cycle, so is probably independent of this PR. |
In that case, I guess we should put this in as a bug fix and then open an issue about the other stuff? Will merge in a bit if nothing crops up. |
OK, thanks Chuck! Will open an issue about the object identity. |
@xflr6 Thanks for the heads up. |
Couple of simple fixes for the bitwise operators.
Still needs tests, so do not merge.