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

Function recursive_tolist

numpy/core/src/multiarray/convert.c:82–113  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

80 * Returns a new reference.
81 */
82static PyObject *
83recursive_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

Callers 1

PyArray_ToListFunction · 0.85

Calls 4

PyArray_NDIMFunction · 0.85
PyArray_GETITEMFunction · 0.85
PyArray_DIMFunction · 0.85
PyArray_STRIDEFunction · 0.85

Tested by

no test coverage detected