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

Function _update_descr_and_dimensions

numpy/core/src/multiarray/ctors.c:278–334  ·  view source on GitHub ↗

* Change a sub-array field to the base descriptor * and update the dimensions and strides * appropriately. Dimensions and strides are added * to the end. * * Strides are only added if given (because data is given). */

Source from the content-addressed store, hash-verified

276 * Strides are only added if given (because data is given).
277 */
278static int
279_update_descr_and_dimensions(PyArray_Descr **des, npy_intp *newdims,
280 npy_intp *newstrides, int oldnd)
281{
282 PyArray_Descr *old;
283 int newnd;
284 int numnew;
285 npy_intp *mydim;
286 int i;
287 int tuple;
288
289 old = *des;
290 *des = old->subarray->base;
291
292
293 mydim = newdims + oldnd;
294 tuple = PyTuple_Check(old->subarray->shape);
295 if (tuple) {
296 numnew = PyTuple_GET_SIZE(old->subarray->shape);
297 }
298 else {
299 numnew = 1;
300 }
301
302
303 newnd = oldnd + numnew;
304 if (newnd > NPY_MAXDIMS) {
305 goto finish;
306 }
307 if (tuple) {
308 for (i = 0; i < numnew; i++) {
309 mydim[i] = (npy_intp) PyLong_AsLong(
310 PyTuple_GET_ITEM(old->subarray->shape, i));
311 }
312 }
313 else {
314 mydim[0] = (npy_intp) PyLong_AsLong(old->subarray->shape);
315 }
316
317 if (newstrides) {
318 npy_intp tempsize;
319 npy_intp *mystrides;
320
321 mystrides = newstrides + oldnd;
322 /* Make new strides -- always C-contiguous */
323 tempsize = (*des)->elsize;
324 for (i = numnew - 1; i >= 0; i--) {
325 mystrides[i] = tempsize;
326 tempsize *= mydim[i] ? mydim[i] : 1;
327 }
328 }
329
330 finish:
331 Py_INCREF(*des);
332 Py_DECREF(old);
333 return newnd;
334}
335

Callers 1

PyArray_NewFromDescr_intFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected