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

Function array_new

numpy/core/src/multiarray/arrayobject.c:1148–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1146
1147
1148static PyObject *
1149array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
1150{
1151 static char *kwlist[] = {"shape", "dtype", "buffer", "offset", "strides",
1152 "order", NULL};
1153 PyArray_Descr *descr = NULL;
1154 int itemsize;
1155 PyArray_Dims dims = {NULL, 0};
1156 PyArray_Dims strides = {NULL, -1};
1157 PyArray_Chunk buffer;
1158 npy_longlong offset = 0;
1159 NPY_ORDER order = NPY_CORDER;
1160 int is_f_order = 0;
1161 PyArrayObject *ret;
1162
1163 buffer.ptr = NULL;
1164 /*
1165 * Usually called with shape and type but can also be called with buffer,
1166 * strides, and swapped info For now, let's just use this to create an
1167 * empty, contiguous array of a specific type and shape.
1168 */
1169 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&LO&O&:ndarray",
1170 kwlist, PyArray_IntpConverter,
1171 &dims,
1172 PyArray_DescrConverter,
1173 &descr,
1174 PyArray_BufferConverter,
1175 &buffer,
1176 &offset,
1177 &PyArray_OptionalIntpConverter,
1178 &strides,
1179 &PyArray_OrderConverter,
1180 &order)) {
1181 goto fail;
1182 }
1183 if (order == NPY_FORTRANORDER) {
1184 is_f_order = 1;
1185 }
1186 if (descr == NULL) {
1187 descr = PyArray_DescrFromType(NPY_DEFAULT_TYPE);
1188 }
1189
1190 itemsize = descr->elsize;
1191
1192 if (strides.len != -1) {
1193 npy_intp nb, off;
1194 if (strides.len != dims.len) {
1195 PyErr_SetString(PyExc_ValueError,
1196 "strides, if given, must be " \
1197 "the same length as shape");
1198 goto fail;
1199 }
1200
1201 if (buffer.ptr == NULL) {
1202 nb = 0;
1203 off = 0;
1204 }
1205 else {

Callers

nothing calls this directly

Calls 6

PyArray_CheckStridesFunction · 0.85
PyArray_NewFromDescr_intFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_FillObjectArrayFunction · 0.85
PyArray_MultiplyListFunction · 0.85
npy_free_cache_dim_objFunction · 0.85

Tested by

no test coverage detected