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

Function array_resize

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

Source from the content-addressed store, hash-verified

1253
1254#include <stdio.h>
1255static PyObject *
1256array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)
1257{
1258 static char *kwlist[] = {"refcheck", NULL};
1259 Py_ssize_t size = PyTuple_Size(args);
1260 int refcheck = 1;
1261 PyArray_Dims newshape;
1262 PyObject *ret, *obj;
1263
1264
1265 if (!NpyArg_ParseKeywords(kwds, "|i", kwlist, &refcheck)) {
1266 return NULL;
1267 }
1268
1269 if (size == 0) {
1270 Py_RETURN_NONE;
1271 }
1272 else if (size == 1) {
1273 obj = PyTuple_GET_ITEM(args, 0);
1274 if (obj == Py_None) {
1275 Py_RETURN_NONE;
1276 }
1277 args = obj;
1278 }
1279 if (!PyArray_IntpConverter(args, &newshape)) {
1280 if (!PyErr_Occurred()) {
1281 PyErr_SetString(PyExc_TypeError, "invalid shape");
1282 }
1283 return NULL;
1284 }
1285
1286 ret = PyArray_Resize(self, &newshape, refcheck, NPY_ANYORDER);
1287 npy_free_cache_dim_obj(newshape);
1288 if (ret == NULL) {
1289 return NULL;
1290 }
1291 Py_DECREF(ret);
1292 Py_RETURN_NONE;
1293}
1294
1295static PyObject *
1296array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {

Callers

nothing calls this directly

Calls 4

NpyArg_ParseKeywordsFunction · 0.85
PyArray_IntpConverterFunction · 0.85
PyArray_ResizeFunction · 0.85
npy_free_cache_dim_objFunction · 0.85

Tested by

no test coverage detected