* arr_bincount is registered as bincount. * * 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, * which must be promotable to double. Call these arguments list and * weight. Both must be one-dimensional with len(weight) == len(list). If * weight is not present then bincount(list)[i] is the number of
| 110 | * output array. |
| 111 | */ |
| 112 | NPY_NO_EXPORT PyObject * |
| 113 | arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args, |
| 114 | Py_ssize_t len_args, PyObject *kwnames) |
| 115 | { |
| 116 | PyObject *list = NULL, *weight = Py_None, *mlength = NULL; |
| 117 | PyArrayObject *lst = NULL, *ans = NULL, *wts = NULL; |
| 118 | npy_intp *numbers, *ians, len, mx, mn, ans_size; |
| 119 | npy_intp minlength = 0; |
| 120 | npy_intp i; |
| 121 | double *weights , *dans; |
| 122 | |
| 123 | NPY_PREPARE_ARGPARSER; |
| 124 | if (npy_parse_arguments("bincount", args, len_args, kwnames, |
| 125 | "list", NULL, &list, |
| 126 | "|weights", NULL, &weight, |
| 127 | "|minlength", NULL, &mlength, |
| 128 | NULL, NULL, NULL) < 0) { |
| 129 | return NULL; |
| 130 | } |
| 131 | |
| 132 | lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1); |
| 133 | if (lst == NULL) { |
| 134 | goto fail; |
| 135 | } |
| 136 | len = PyArray_SIZE(lst); |
| 137 | |
| 138 | /* |
| 139 | * This if/else if can be removed by changing the argspec to O|On above, |
| 140 | * once we retire the deprecation |
| 141 | */ |
| 142 | if (mlength == Py_None) { |
| 143 | /* NumPy 1.14, 2017-06-01 */ |
| 144 | if (DEPRECATE("0 should be passed as minlength instead of None; " |
| 145 | "this will error in future.") < 0) { |
| 146 | goto fail; |
| 147 | } |
| 148 | } |
| 149 | else if (mlength != NULL) { |
| 150 | minlength = PyArray_PyIntAsIntp(mlength); |
| 151 | if (error_converting(minlength)) { |
| 152 | goto fail; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (minlength < 0) { |
| 157 | PyErr_SetString(PyExc_ValueError, |
| 158 | "'minlength' must not be negative"); |
| 159 | goto fail; |
| 160 | } |
| 161 | |
| 162 | /* handle empty list */ |
| 163 | if (len == 0) { |
| 164 | ans = (PyArrayObject *)PyArray_ZEROS(1, &minlength, NPY_INTP, 0); |
| 165 | if (ans == NULL){ |
| 166 | goto fail; |
| 167 | } |
| 168 | Py_DECREF(lst); |
| 169 | return (PyObject *)ans; |
nothing calls this directly
no test coverage detected