Skip to content

Commit 66ae571

Browse files
Add support for integers
1 parent 03003a4 commit 66ae571

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

numpy/core/src/multiarray/compiled_base.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args,
115115
{
116116
PyObject *list = NULL, *weight = Py_None, *mlength = NULL;
117117
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;
119119
npy_intp minlength = 0;
120120
npy_intp i;
121121
double *weights , *dans;
@@ -200,13 +200,25 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args,
200200
if (wts == NULL) {
201201
goto fail;
202202
}
203-
weights = (double *)PyArray_DATA(wts);
204203
if (PyArray_SIZE(wts) != len) {
205204
PyErr_SetString(PyExc_ValueError,
206205
"The weights and list don't have the same length.");
207206
goto fail;
208207
}
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);
210222
ans = (PyArrayObject *)PyArray_ZEROS(1, &ans_size, NPY_DOUBLE, 0);
211223
if (ans == NULL) {
212224
goto fail;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy