| 476 | } |
| 477 | |
| 478 | static PyObject * |
| 479 | iter_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; |
no test coverage detected