@@ -115,7 +115,7 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args,
115
115
{
116
116
PyObject * list = NULL , * weight = Py_None , * mlength = NULL ;
117
117
PyArrayObject * lst = NULL , * ans = NULL , * wts = NULL ;
118
- npy_intp * numbers , * ians , len , mx , mn , ans_size ;
118
+ npy_intp * numbers , * ians , * iweights , len , mx , mn , ans_size ;
119
119
npy_intp minlength = 0 ;
120
120
npy_intp i ;
121
121
double * weights , * dans ;
@@ -200,13 +200,25 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args,
200
200
if (wts == NULL ) {
201
201
goto fail ;
202
202
}
203
- weights = (double * )PyArray_DATA (wts );
204
203
if (PyArray_SIZE (wts ) != len ) {
205
204
PyErr_SetString (PyExc_ValueError ,
206
205
"The weights and list don't have the same length." );
207
206
goto fail ;
208
207
}
209
- if (PyArray_ISFLOAT (wts )) {
208
+ if (PyArray_ISINTEGER (wts )) {
209
+ iweights = (npy_intp * )PyArray_DATA (wts );
210
+ ans = (PyArrayObject * )PyArray_ZEROS (1 , & ans_size , NPY_INTP , 0 );
211
+ if (ans == NULL ) {
212
+ goto fail ;
213
+ }
214
+ ians = (npy_intp * )PyArray_DATA (ans );
215
+ NPY_BEGIN_ALLOW_THREADS ;
216
+ for (i = 0 ; i < len ; i ++ ) {
217
+ ians [numbers [i ]] += iweights [i ];
218
+ }
219
+ NPY_END_ALLOW_THREADS ;
220
+ } else if (PyArray_ISFLOAT (wts )) {
221
+ weights = (double * )PyArray_DATA (wts );
210
222
ans = (PyArrayObject * )PyArray_ZEROS (1 , & ans_size , NPY_DOUBLE , 0 );
211
223
if (ans == NULL ) {
212
224
goto fail ;
0 commit comments