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

Function iter_subscript

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

Always returns arrays */

Source from the content-addressed store, hash-verified

542
543/* Always returns arrays */
544NPY_NO_EXPORT PyObject *
545iter_subscript(PyArrayIterObject *self, PyObject *ind)
546{
547 PyArray_Descr *indtype = NULL;
548 PyArray_Descr *dtype;
549 npy_intp start, step_size;
550 npy_intp n_steps;
551 PyArrayObject *ret;
552 char *dptr;
553 int size;
554 PyObject *obj = NULL;
555 PyObject *new;
556 PyArray_CopySwapFunc *copyswap;
557
558 if (ind == Py_Ellipsis) {
559 ind = PySlice_New(NULL, NULL, NULL);
560 obj = iter_subscript(self, ind);
561 Py_DECREF(ind);
562 return obj;
563 }
564 if (PyTuple_Check(ind)) {
565 int len;
566 len = PyTuple_GET_SIZE(ind);
567 if (len > 1) {
568 goto fail;
569 }
570 if (len == 0) {
571 Py_INCREF(self->ao);
572 return (PyObject *)self->ao;
573 }
574 ind = PyTuple_GET_ITEM(ind, 0);
575 }
576
577 /*
578 * Tuples >1d not accepted --- i.e. no newaxis
579 * Could implement this with adjusted strides and dimensions in iterator
580 * Check for Boolean -- this is first because Bool is a subclass of Int
581 */
582 PyArray_ITER_RESET(self);
583
584 if (PyBool_Check(ind)) {
585 if (PyObject_IsTrue(ind)) {
586 return PyArray_ToScalar(self->dataptr, self->ao);
587 }
588 else { /* empty array */
589 npy_intp ii = 0;
590 dtype = PyArray_DESCR(self->ao);
591 Py_INCREF(dtype);
592 ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
593 dtype,
594 1, &ii,
595 NULL, NULL, 0,
596 (PyObject *)self->ao);
597 return (PyObject *)ret;
598 }
599 }
600
601 /* Check for Integer or Slice */

Callers

nothing calls this directly

Calls 8

PyArray_DESCRFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
parse_index_entryFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_FromAnyFunction · 0.85
PyArray_TYPEFunction · 0.85
iter_subscript_BoolFunction · 0.85
iter_subscript_intFunction · 0.85

Tested by

no test coverage detected