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

Function iter_subscript_int

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

Source from the content-addressed store, hash-verified

476}
477
478static PyObject *
479iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
480{
481 npy_intp num;
482 PyArrayObject *ret;
483 PyArrayIterObject *ind_it;
484 int itemsize;
485 int swap;
486 char *optr;
487 npy_intp counter;
488 PyArray_CopySwapFunc *copyswap;
489
490 itemsize = PyArray_DESCR(self->ao)->elsize;
491 if (PyArray_NDIM(ind) == 0) {
492 num = *((npy_intp *)PyArray_DATA(ind));
493 if (check_and_adjust_index(&num, self->size, -1, NULL) < 0) {
494 PyArray_ITER_RESET(self);
495 return NULL;
496 }
497 else {
498 PyObject *tmp;
499 PyArray_ITER_GOTO1D(self, num);
500 tmp = PyArray_ToScalar(self->dataptr, self->ao);
501 PyArray_ITER_RESET(self);
502 return tmp;
503 }
504 }
505
506 Py_INCREF(PyArray_DESCR(self->ao));
507 ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
508 PyArray_DESCR(self->ao),
509 PyArray_NDIM(ind),
510 PyArray_DIMS(ind),
511 NULL, NULL,
512 0, (PyObject *)self->ao);
513 if (ret == NULL) {
514 return NULL;
515 }
516 optr = PyArray_DATA(ret);
517 ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
518 if (ind_it == NULL) {
519 Py_DECREF(ret);
520 return NULL;
521 }
522 counter = ind_it->size;
523 copyswap = PyArray_DESCR(ret)->f->copyswap;
524 swap = (PyArray_ISNOTSWAPPED(ret) != PyArray_ISNOTSWAPPED(self->ao));
525 while (counter--) {
526 num = *((npy_intp *)(ind_it->dataptr));
527 if (check_and_adjust_index(&num, self->size, -1, NULL) < 0) {
528 Py_DECREF(ind_it);
529 Py_DECREF(ret);
530 PyArray_ITER_RESET(self);
531 return NULL;
532 }
533 PyArray_ITER_GOTO1D(self, num);
534 copyswap(optr, self->dataptr, swap, ret);
535 optr += itemsize;

Callers 1

iter_subscriptFunction · 0.85

Calls 7

PyArray_DESCRFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DATAFunction · 0.85
check_and_adjust_indexFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_IterNewFunction · 0.85

Tested by

no test coverage detected