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. * *
| 988 | * ignored. |
| 989 | */ |
| 990 | static PyArrayObject * |
| 991 | iter_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 | |
| 1027 | static PyObject * |
| 1028 | iter_copy(PyArrayIterObject *it, PyObject *args) |
no test coverage detected