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

Function array_reshape

numpy/core/src/multiarray/methods.c:169–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169static PyObject *
170array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds)
171{
172 static char *keywords[] = {"order", NULL};
173 PyArray_Dims newshape;
174 PyObject *ret;
175 NPY_ORDER order = NPY_CORDER;
176 Py_ssize_t n = PyTuple_Size(args);
177
178 if (!NpyArg_ParseKeywords(kwds, "|O&", keywords,
179 PyArray_OrderConverter, &order)) {
180 return NULL;
181 }
182
183 if (n <= 1) {
184 if (n != 0 && PyTuple_GET_ITEM(args, 0) == Py_None) {
185 return PyArray_View(self, NULL, NULL);
186 }
187 if (!PyArg_ParseTuple(args, "O&:reshape", PyArray_IntpConverter,
188 &newshape)) {
189 return NULL;
190 }
191 }
192 else {
193 if (!PyArray_IntpConverter(args, &newshape)) {
194 if (!PyErr_Occurred()) {
195 PyErr_SetString(PyExc_TypeError,
196 "invalid shape");
197 }
198 goto fail;
199 }
200 }
201 ret = PyArray_Newshape(self, &newshape, order);
202 npy_free_cache_dim_obj(newshape);
203 return ret;
204
205 fail:
206 npy_free_cache_dim_obj(newshape);
207 return NULL;
208}
209
210static PyObject *
211array_squeeze(PyArrayObject *self,

Callers

nothing calls this directly

Calls 5

NpyArg_ParseKeywordsFunction · 0.85
PyArray_ViewFunction · 0.85
PyArray_IntpConverterFunction · 0.85
PyArray_NewshapeFunction · 0.85
npy_free_cache_dim_objFunction · 0.85

Tested by

no test coverage detected