Change numpy.bitwise_and.identity from 1 to None #4696

Closed
xflr6 opened this Issue May 10, 2014 · 8 comments

Comments

Projects
None yet
3 participants
@xflr6

xflr6 commented May 10, 2014

I would normally expect numpy.bitwise_and.identity to be 0xFFFF...

The current behaviour with 1 looks very suprising to me:
np.bitwise_and.reduce([0b1111]) == 0b1

I also doubt its usefulness: Why use bitwise_and.reduce to only process the last bit? np.bitwise_and.reduce([0b1111, 0b1010, 0b1110]) == 0b0 instead of 0b1010, also making it inconsistent with np.bitwise_and.accumulate([0b1111, 0b1010, 0b1110])[-1],
see also http://isntagramm.com/questions/21050875/numpy-bitwise-and-reduce-behaving-unexpectedly

Is it correct that just setting identity to None would fix these cases?

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris May 10, 2014

Member

Yeah, that looks like a bug. I think None would work and have the same effect.

Member

charris commented May 10, 2014

Yeah, that looks like a bug. I think None would work and have the same effect.

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris May 10, 2014

Member

Have the same effect as 0xffff... that is. The 0xffff... is harder to make type dependent.

Member

charris commented May 10, 2014

Have the same effect as 0xffff... that is. The 0xffff... is harder to make type dependent.

@njsmith

This comment has been minimized.

Show comment
Hide comment
@njsmith

njsmith May 10, 2014

Member

I guess 0xfff... would be better in that it would give the correct answer
for bitwise_and.reduce([]). But if 0xfff... doesn't work then None would be
much better than the current situation!
On 10 May 2014 20:06, "Charles Harris" notifications@github.com wrote:

Have the same effect as 0xffff... that is. The 0xffff... is harder to
make type dependent.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/4696#issuecomment-42751126
.

Member

njsmith commented May 10, 2014

I guess 0xfff... would be better in that it would give the correct answer
for bitwise_and.reduce([]). But if 0xfff... doesn't work then None would be
much better than the current situation!
On 10 May 2014 20:06, "Charles Harris" notifications@github.com wrote:

Have the same effect as 0xffff... that is. The 0xffff... is harder to
make type dependent.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/4696#issuecomment-42751126
.

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris May 10, 2014

Member

We could try -1, which I think will be cast correctly for unsigned types.

Member

charris commented May 10, 2014

We could try -1, which I think will be cast correctly for unsigned types.

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris May 10, 2014

Member

Looks all ones is doable, but not completely trivial.

Member

charris commented May 10, 2014

Looks all ones is doable, but not completely trivial.

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris May 10, 2014

Member

That's ugly code. Believe it of not, 0, and 1 are obtained by converting boolean object instances to numbers.

Member

charris commented May 10, 2014

That's ugly code. Believe it of not, 0, and 1 are obtained by converting boolean object instances to numbers.

@njsmith

This comment has been minimized.

Show comment
Hide comment
@njsmith

njsmith May 10, 2014

Member

I think I knew that actually :-(

Another thing to put on the list for when we get around to rewriting
ufuncs...
On 10 May 2014 21:22, "Charles Harris" notifications@github.com wrote:

That's ugly code. Believe it of not, 0, and 1 are obtained by converting
boolean object instances to numbers.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/4696#issuecomment-42753233
.

Member

njsmith commented May 10, 2014

I think I knew that actually :-(

Another thing to put on the list for when we get around to rewriting
ufuncs...
On 10 May 2014 21:22, "Charles Harris" notifications@github.com wrote:

That's ugly code. Believe it of not, 0, and 1 are obtained by converting
boolean object instances to numbers.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/4696#issuecomment-42753233
.

@charris

This comment has been minimized.

Show comment
Hide comment
@charris

charris Mar 13, 2016

Member

Closing, see #7373.

Member

charris commented Mar 13, 2016

Closing, see #7373.

@charris charris closed this Mar 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment