You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bincount does not accept input of type > N.uint16 (Trac #225) #823
This function still errors (with uint64 on a 64-bit machine). Bincount is a candidate to convert to using the iterator with buffering, since currently it will cause a copy if the input isn't contiguous and the right type.
My C is not very good but hopefully someone with can correct the patch. The less obvious change (at least was to me) was that PyArray_ContiguousFromAny was being called with unsigned int, PyArray_INTP, rather than PyArray_UINTP.
According to the comment on the bincount code in "numpy/lib/src/_compiled_base.c", the first argument must be an array of non-negative integers (relevant lines):
* bincount accepts one, two or three arguments. The first is an array of
* non-negative integers The second, if present, is an array of weights,
Consequently I changed bincount to use unsigned ints instead of signed ints.
The patch is incorrect if the mxx and mnx functions can be used outside of bincount. In that case new functions would have to declared.
Okay, still was not that simple! I had to change one PyObject variable into PyArrayObject. This allowed to get the input dtype for PyArray?_ContiguousFromAny. Both patches need to be applied because I do not know how to get a single patch with git without redoing everything - sorry!
np.bincount(np.array([1], np.uint64))
Traceback (most recent call last):
File "<ipython-input-2-850f8c15a097>", line 1, in <module>
np.bincount(np.array([1], np.uint64))
TypeError: Cannot cast array data from dtype('uint64') to dtype('int64') according to the rule 'safe'
Activity
numpy-gitbot commentedon Oct 19, 2012
@stefanv wrote on 2006-08-03
Can be improved by changing to NPY_UINTP, but that still won't allow 64-bit integers. Is there a way to easily fix this for 32-bit systems?
numpy-gitbot commentedon Oct 19, 2012
Milestone changed to
1.1by @alberts on 2007-05-12numpy-gitbot commentedon Oct 19, 2012
Milestone changed to
Unscheduledby @cournape on 2009-03-02numpy-gitbot commentedon Oct 19, 2012
@mwiebe wrote on 2011-03-23
This function still errors (with uint64 on a 64-bit machine). Bincount is a candidate to convert to using the iterator with buffering, since currently it will cause a copy if the input isn't contiguous and the right type.
numpy-gitbot commentedon Oct 19, 2012
@bsouthey wrote on 2011-05-09
My C is not very good but hopefully someone with can correct the patch. The less obvious change (at least was to me) was that PyArray_ContiguousFromAny was being called with unsigned int, PyArray_INTP, rather than PyArray_UINTP.
According to the comment on the bincount code in "numpy/lib/src/_compiled_base.c", the first argument must be an array of non-negative integers (relevant lines):
Consequently I changed bincount to use unsigned ints instead of signed ints.
The patch is incorrect if the mxx and mnx functions can be used outside of bincount. In that case new functions would have to declared.
numpy-gitbot commentedon Oct 19, 2012
Attachment added by @bsouthey on 2011-05-09: 0001-bincount-unsigned-ints.patch
numpy-gitbot commentedon Oct 19, 2012
Attachment added by @bsouthey on 2011-05-09: 0002-Redo-bincount-signed-int-change.patch
numpy-gitbot commentedon Oct 19, 2012
@bsouthey wrote on 2011-05-09
Okay, still was not that simple! I had to change one PyObject variable into PyArrayObject. This allowed to get the input dtype for PyArray?_ContiguousFromAny. Both patches need to be applied because I do not know how to get a single patch with git without redoing everything - sorry!
ENH: add an axis argument to np.bincount
BUG: Allow any integer type in bincount (fixes numpy#823)
OmerJog commentedon Feb 6, 2019
Is this still an issue?
endolith commentedon Apr 17, 2019
@OmerJog The original example doesn't fail:
but this does:
Switched all dtypes to 32-bit unsigned integers instead of 64-bit
Updated LZ complexity estimation with speed bump and integer typing
Updated LZ complexity estimation with speed bump and integer typing
Switched all dtypes to 32-bit unsigned integers instead of 64-bit
Updated LZ complexity estimation with speed bump and integer typing
eendebakpt commentedon Aug 4, 2026
I cannot reproduce on current numpy.
mattip commentedon Sep 7, 2026
Closing as fixed.