NUMPY_API * Compress */
| 2310 | * Compress |
| 2311 | */ |
| 2312 | NPY_NO_EXPORT PyObject * |
| 2313 | PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis, |
| 2314 | PyArrayObject *out) |
| 2315 | { |
| 2316 | PyArrayObject *cond; |
| 2317 | PyObject *res, *ret; |
| 2318 | |
| 2319 | if (PyArray_Check(condition)) { |
| 2320 | cond = (PyArrayObject *)condition; |
| 2321 | Py_INCREF(cond); |
| 2322 | } |
| 2323 | else { |
| 2324 | PyArray_Descr *dtype = PyArray_DescrFromType(NPY_BOOL); |
| 2325 | if (dtype == NULL) { |
| 2326 | return NULL; |
| 2327 | } |
| 2328 | cond = (PyArrayObject *)PyArray_FromAny(condition, dtype, |
| 2329 | 0, 0, 0, NULL); |
| 2330 | if (cond == NULL) { |
| 2331 | return NULL; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | if (PyArray_NDIM(cond) != 1) { |
| 2336 | Py_DECREF(cond); |
| 2337 | PyErr_SetString(PyExc_ValueError, |
| 2338 | "condition must be a 1-d array"); |
| 2339 | return NULL; |
| 2340 | } |
| 2341 | |
| 2342 | res = PyArray_Nonzero(cond); |
| 2343 | Py_DECREF(cond); |
| 2344 | if (res == NULL) { |
| 2345 | return res; |
| 2346 | } |
| 2347 | ret = PyArray_TakeFrom(self, PyTuple_GET_ITEM(res, 0), axis, |
| 2348 | out, NPY_RAISE); |
| 2349 | Py_DECREF(res); |
| 2350 | return ret; |
| 2351 | } |
| 2352 | |
| 2353 | /* |
| 2354 | * count number of nonzero bytes in 48 byte block |
no test coverage detected