thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

bincount does not accept input of type > N.uint16 (migrated from Trac #225) #832

Open thouis opened 11 years ago

thouis commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/225 Reported 2006-08-03 by atmention:stefanv, assigned to atmention:teoliphant.

Under r2944:

In [22]: N.bincount(N.array([1],N.uint16))
Out[22]: array([0, 1])

In [23]: N.bincount(N.array([1],N.uint32))
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent call last)

/home/stefan/work/scipy/hough/<ipython console>

TypeError: array cannot be safely cast to required type
thouis commented 11 years ago

Comment in Trac by atmention:stefanv, 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?

thouis commented 11 years ago

Comment in Trac by atmention:alberts, 2007-05-12

thouis commented 11 years ago

Comment in Trac by atmention:cournape, 2009-03-02

thouis commented 11 years ago

Comment in Trac by atmention:mwiebe, 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.

thouis commented 11 years ago

Comment in Trac by atmention:bsouthey, 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): * 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.

thouis commented 11 years ago

Attachment in Trac by atmention:bsouthey, 2011-05-09: 0001-bincount-unsigned-ints.patch

thouis commented 11 years ago

Attachment in Trac by atmention:bsouthey, 2011-05-09: 0002-Redo-bincount-signed-int-change.patch

thouis commented 11 years ago

Comment in Trac by atmention:bsouthey, 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'''!