Skip to content

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

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

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
NumPy member
charris commented May 10, 2014

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

@charris
NumPy member
charris commented May 10, 2014

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

@njsmith
NumPy member
@charris
NumPy member
charris commented May 10, 2014

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

@charris
NumPy member
charris commented May 10, 2014

Looks all ones is doable, but not completely trivial.

@charris
NumPy 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
NumPy member
@charris
NumPy 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
Something went wrong with that request. Please try again.