diff options
author | Skipper Seabold <jsseabold@gmail.com> | 2011-06-02 12:44:44 -0400 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2012-03-04 13:25:55 -0700 |
commit | 40f0844846a9d7665616b142407a3d74cb65a040 (patch) | |
tree | de3c25ba0dffeac73120e7b0fb07534382e2c03e /numpy/lib/src | |
parent | 0b400cbe4bc80139d0fe88a327d4f7c3b75ecc0f (diff) | |
download | numpy-40f0844846a9d7665616b142407a3d74cb65a040.tar.gz |
ENH: Allow bincount to accept empty arrays.
Diffstat (limited to 'numpy/lib/src')
-rw-r--r-- | numpy/lib/src/_compiled_base.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index 82343fc35..a66e5da4c 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -124,16 +124,29 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) kwlist, &list, &weight, &mlength)) { goto fail; } + lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1); if (lst == NULL) { goto fail; } len = PyArray_SIZE(lst); + type = PyArray_DescrFromType(NPY_INTP); + + /* handle empty list */ if (len < 1) { - PyErr_SetString(PyExc_ValueError, - "The first argument cannot be empty."); - goto fail; + if (mlength == Py_None) { + minlength = 0; + } + else if (!(minlength = PyArray_PyIntAsIntp(mlength))) { + goto fail; + } + if (!(ans = PyArray_Zeros(1, &minlength, type, 0))){ + goto fail; + } + Py_DECREF(lst); + return ans; } + numbers = (npy_intp *) PyArray_DATA(lst); mxi = mxx(numbers, len); mni = mnx(numbers, len); @@ -157,7 +170,6 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) ans_size = minlength; } } - type = PyArray_DescrFromType(NPY_INTP); if (weight == Py_None) { ans = (PyArrayObject *)PyArray_Zeros(1, &ans_size, type, 0); if (ans == NULL) { |