| 2041 | } |
| 2042 | |
| 2043 | NPY_NO_EXPORT PyObject * |
| 2044 | npyiter_seq_slice(NewNpyArrayIterObject *self, |
| 2045 | Py_ssize_t ilow, Py_ssize_t ihigh) |
| 2046 | { |
| 2047 | PyObject *ret; |
| 2048 | npy_intp nop; |
| 2049 | Py_ssize_t i; |
| 2050 | |
| 2051 | if (self->iter == NULL || self->finished) { |
| 2052 | PyErr_SetString(PyExc_ValueError, |
| 2053 | "Iterator is past the end"); |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | |
| 2057 | if (NpyIter_HasDelayedBufAlloc(self->iter)) { |
| 2058 | PyErr_SetString(PyExc_ValueError, |
| 2059 | "Iterator construction used delayed buffer allocation, " |
| 2060 | "and no reset has been done yet"); |
| 2061 | return NULL; |
| 2062 | } |
| 2063 | nop = NpyIter_GetNOp(self->iter); |
| 2064 | if (ilow < 0) { |
| 2065 | ilow = 0; |
| 2066 | } |
| 2067 | else if (ilow >= nop) { |
| 2068 | ilow = nop-1; |
| 2069 | } |
| 2070 | if (ihigh < ilow) { |
| 2071 | ihigh = ilow; |
| 2072 | } |
| 2073 | else if (ihigh > nop) { |
| 2074 | ihigh = nop; |
| 2075 | } |
| 2076 | |
| 2077 | ret = PyTuple_New(ihigh-ilow); |
| 2078 | if (ret == NULL) { |
| 2079 | return NULL; |
| 2080 | } |
| 2081 | for (i = ilow; i < ihigh ; ++i) { |
| 2082 | PyObject *item = npyiter_seq_item(self, i); |
| 2083 | if (item == NULL) { |
| 2084 | Py_DECREF(ret); |
| 2085 | return NULL; |
| 2086 | } |
| 2087 | PyTuple_SET_ITEM(ret, i-ilow, item); |
| 2088 | } |
| 2089 | return ret; |
| 2090 | } |
| 2091 | |
| 2092 | NPY_NO_EXPORT int |
| 2093 | npyiter_seq_ass_item(NewNpyArrayIterObject *self, Py_ssize_t i, PyObject *v) |
no test coverage detected