New submission from Ian Ozsvald <[email protected]>:

np.sum(np.array([<booleans>]) with over 127 True values results in an incorrect
count. Using Python's sum instead produces the correct answer. np.sum gives the
correct answer for smaller counts of True values. Two examples are below - the
tipping point seems to be a list of True values that sum to 128 and multiples of
128.

Version: PyPy Nightly for today:
pypy-c-jit-68443-d5e489e07679-linux64
and numpy branch checked-out today.

Python 2.7.3 (d5e489e07679, Dec 16 2013, 23:00:17)
[PyPy 2.3.0-alpha0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``"messy" is not a judgement, but
just a fact of complicatedness''
>>>> import numpy as np
>>>> np.version
<module 'numpy.version' from
'/home/ian/Downloads/pypy-c-jit-68443-d5e489e07679-linux64/env_numpy/site-packages/numpy/version.pyc'>
>>>> np.sum(np.array([True,False]))
1
>>>> np.sum(np.array([True,False]*1000))  # Incorrect behaviour
-24
>>>> sum(np.array([True,False]))
1
>>>> sum(np.array([True,False]*1000))
1000

It feels as though the counter is a single byte (as suggested below using
array.itemsize), it counts up to 127 and then counts down back to 0 (when it
should be counting to 256 and beyond), then cycles again:

>>>> np.sum(np.array([True,False]))
1
>>>> np.sum(np.array([True,False]*127))
127
>>>> np.sum(np.array([True,False]*128))
-128
>>>> np.sum(np.array([True,False]*129))
-127
>>>> np.sum(np.array([True,False]*255))
-1
>>>> np.sum(np.array([True,False]*256))
0
>>>> np.sum(np.array([True,False]*257))
1
>>>> np.sum(np.array([True,False]*384))
-128
>>>> np.sum(np.array([True,False]*385))
-127

>>>> np.array([True,False])
array([ True, False], dtype=bool)
>>>> arr=np.array([True,False])
>>>> arr.itemsize
1

----------
nosy: +ianozsvald
status: unread -> chatting

________________________________________
PyPy bug tracker <[email protected]>
<https://bugs.pypy.org/issue1663>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to