* Converts a subarray of 'self' into lists, with starting data pointer * 'dataptr' and from dimension 'startdim' to the last dimension of 'self'. * * Returns a new reference. */
| 80 | * Returns a new reference. |
| 81 | */ |
| 82 | static PyObject * |
| 83 | recursive_tolist(PyArrayObject *self, char *dataptr, int startdim) |
| 84 | { |
| 85 | npy_intp i, n, stride; |
| 86 | PyObject *ret, *item; |
| 87 | |
| 88 | /* Base case */ |
| 89 | if (startdim >= PyArray_NDIM(self)) { |
| 90 | return PyArray_GETITEM(self, dataptr); |
| 91 | } |
| 92 | |
| 93 | n = PyArray_DIM(self, startdim); |
| 94 | stride = PyArray_STRIDE(self, startdim); |
| 95 | |
| 96 | ret = PyList_New(n); |
| 97 | if (ret == NULL) { |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | for (i = 0; i < n; ++i) { |
| 102 | item = recursive_tolist(self, dataptr, startdim+1); |
| 103 | if (item == NULL) { |
| 104 | Py_DECREF(ret); |
| 105 | return NULL; |
| 106 | } |
| 107 | PyList_SET_ITEM(ret, i, item); |
| 108 | |
| 109 | dataptr += stride; |
| 110 | } |
| 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | /*NUMPY_API |
| 116 | * To List |
no test coverage detected