MCPcopy Create free account
hub / github.com/numpy/numpy / iter_subscript_Bool

Function iter_subscript_Bool

numpy/core/src/multiarray/iterators.c:417–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415
416
417static PyArrayObject *
418iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
419{
420 npy_intp counter, strides;
421 int itemsize;
422 npy_intp count = 0;
423 char *dptr, *optr;
424 PyArrayObject *ret;
425 int swap;
426 PyArray_CopySwapFunc *copyswap;
427
428
429 if (PyArray_NDIM(ind) != 1) {
430 PyErr_SetString(PyExc_ValueError,
431 "boolean index array should have 1 dimension");
432 return NULL;
433 }
434 counter = PyArray_DIMS(ind)[0];
435 if (counter > self->size) {
436 PyErr_SetString(PyExc_ValueError,
437 "too many boolean indices");
438 return NULL;
439 }
440
441 strides = PyArray_STRIDES(ind)[0];
442 dptr = PyArray_DATA(ind);
443 /* Get size of return array */
444 while (counter--) {
445 if (*((npy_bool *)dptr) != 0) {
446 count++;
447 }
448 dptr += strides;
449 }
450 itemsize = PyArray_DESCR(self->ao)->elsize;
451 Py_INCREF(PyArray_DESCR(self->ao));
452 ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
453 PyArray_DESCR(self->ao), 1, &count,
454 NULL, NULL,
455 0, (PyObject *)self->ao);
456 if (ret == NULL) {
457 return NULL;
458 }
459 /* Set up loop */
460 optr = PyArray_DATA(ret);
461 counter = PyArray_DIMS(ind)[0];
462 dptr = PyArray_DATA(ind);
463 copyswap = PyArray_DESCR(self->ao)->f->copyswap;
464 /* Loop over Boolean array */
465 swap = (PyArray_ISNOTSWAPPED(self->ao) != PyArray_ISNOTSWAPPED(ret));
466 while (counter--) {
467 if (*((npy_bool *)dptr) != 0) {
468 copyswap(optr, self->dataptr, swap, self->ao);
469 optr += itemsize;
470 }
471 dptr += strides;
472 PyArray_ITER_NEXT(self);
473 }
474 PyArray_ITER_RESET(self);

Callers 1

iter_subscriptFunction · 0.85

Calls 6

PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_STRIDESFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_NewFromDescrFunction · 0.85

Tested by

no test coverage detected