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

Function iter_array

numpy/core/src/multiarray/iterators.c:990–1025  ·  view source on GitHub ↗

Two options: * 1) underlying array is contiguous * -- return 1-d wrapper around it * 2) underlying array is not contiguous * -- make new 1-d contiguous array with updateifcopy flag set * to copy back to the old array * * If underlying array is readonly, then we make the output array readonly * and updateifcopy does not apply. * * Changed 2017-07-21, 1.14.0. * *

Source from the content-addressed store, hash-verified

988 * ignored.
989 */
990static PyArrayObject *
991iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
992{
993
994 PyArrayObject *ret;
995 npy_intp size;
996
997 size = PyArray_SIZE(it->ao);
998 Py_INCREF(PyArray_DESCR(it->ao));
999
1000 if (PyArray_ISCONTIGUOUS(it->ao)) {
1001 ret = (PyArrayObject *)PyArray_NewFromDescrAndBase(
1002 &PyArray_Type, PyArray_DESCR(it->ao),
1003 1, &size, NULL, PyArray_DATA(it->ao),
1004 PyArray_FLAGS(it->ao), (PyObject *)it->ao, (PyObject *)it->ao);
1005 if (ret == NULL) {
1006 return NULL;
1007 }
1008 }
1009 else {
1010 ret = (PyArrayObject *)PyArray_NewFromDescr(
1011 &PyArray_Type, PyArray_DESCR(it->ao), 1, &size,
1012 NULL, NULL, 0,
1013 (PyObject *)it->ao);
1014 if (ret == NULL) {
1015 return NULL;
1016 }
1017 if (PyArray_CopyAnyInto(ret, it->ao) < 0) {
1018 Py_DECREF(ret);
1019 return NULL;
1020 }
1021 PyArray_CLEARFLAGS(ret, NPY_ARRAY_WRITEABLE);
1022 }
1023 return ret;
1024
1025}
1026
1027static PyObject *
1028iter_copy(PyArrayIterObject *it, PyObject *args)

Callers 1

iter_richcompareFunction · 0.85

Calls 7

PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_FLAGSFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_CopyAnyIntoFunction · 0.85
PyArray_CLEARFLAGSFunction · 0.85

Tested by

no test coverage detected