NUMPY_API * * Removes the axes flagged as True from the array, * modifying it in place. If an axis flagged for removal * has a shape entry bigger than one, this effectively selects * index zero for that axis. * * WARNING: If an axis flagged for removal has a shape equal to zero, * the array will point to invalid memory. The caller must * validate this! * If an
| 1003 | * from a reduction result once its computation is complete. |
| 1004 | */ |
| 1005 | NPY_NO_EXPORT void |
| 1006 | PyArray_RemoveAxesInPlace(PyArrayObject *arr, const npy_bool *flags) |
| 1007 | { |
| 1008 | PyArrayObject_fields *fa = (PyArrayObject_fields *)arr; |
| 1009 | npy_intp *shape = fa->dimensions, *strides = fa->strides; |
| 1010 | int idim, ndim = fa->nd, idim_out = 0; |
| 1011 | |
| 1012 | /* Compress the dimensions and strides */ |
| 1013 | for (idim = 0; idim < ndim; ++idim) { |
| 1014 | if (!flags[idim]) { |
| 1015 | shape[idim_out] = shape[idim]; |
| 1016 | strides[idim_out] = strides[idim]; |
| 1017 | ++idim_out; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | /* The final number of dimensions */ |
| 1022 | fa->nd = idim_out; |
| 1023 | |
| 1024 | /* NOTE: This is only necessary if a dimension with size != 1 was removed */ |
| 1025 | PyArray_UpdateFlags(arr, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS); |
| 1026 | } |
no test coverage detected