* Create new mapiter. * * NOTE: The outer iteration (and subspace if requested buffered) is * created with DELAY_BUFALLOC. It must be reset before usage! * * @param Index information filled by prepare_index. * @param Number of indices (gotten through prepare_index). * @param Kind of index (gotten through preprare_index). * @param NpyIter flags for an extra array. If 0 assume that the
| 2729 | * @return A new MapIter (PyObject *) or NULL. |
| 2730 | */ |
| 2731 | NPY_NO_EXPORT PyObject * |
| 2732 | PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type, |
| 2733 | int ndim, int fancy_ndim, |
| 2734 | PyArrayObject *arr, PyArrayObject *subspace, |
| 2735 | npy_uint32 subspace_iter_flags, npy_uint32 subspace_flags, |
| 2736 | npy_uint32 extra_op_flags, PyArrayObject *extra_op, |
| 2737 | PyArray_Descr *extra_op_dtype) |
| 2738 | { |
| 2739 | /* For shape reporting on error */ |
| 2740 | PyArrayObject *original_extra_op = extra_op; |
| 2741 | |
| 2742 | /* NOTE: MAXARGS is the actual limit (2*NPY_MAXDIMS is index number one) */ |
| 2743 | PyArrayObject *index_arrays[NPY_MAXDIMS]; |
| 2744 | PyArray_Descr *intp_descr; |
| 2745 | PyArray_Descr *dtypes[NPY_MAXDIMS]; /* borrowed references */ |
| 2746 | |
| 2747 | npy_uint32 op_flags[NPY_MAXDIMS]; |
| 2748 | npy_uint32 outer_flags; |
| 2749 | |
| 2750 | PyArrayMapIterObject *mit; |
| 2751 | |
| 2752 | int single_op_axis[NPY_MAXDIMS]; |
| 2753 | int *op_axes[NPY_MAXDIMS] = {NULL}; |
| 2754 | int i, j, dummy_array = 0; |
| 2755 | int nops; |
| 2756 | int uses_subspace; |
| 2757 | |
| 2758 | intp_descr = PyArray_DescrFromType(NPY_INTP); |
| 2759 | if (intp_descr == NULL) { |
| 2760 | return NULL; |
| 2761 | } |
| 2762 | |
| 2763 | /* create new MapIter object */ |
| 2764 | mit = (PyArrayMapIterObject *)PyArray_malloc( |
| 2765 | sizeof(PyArrayMapIterObject) + sizeof(NPY_cast_info)); |
| 2766 | if (mit == NULL) { |
| 2767 | Py_DECREF(intp_descr); |
| 2768 | return NULL; |
| 2769 | } |
| 2770 | /* set all attributes of mapiter to zero */ |
| 2771 | memset(mit, 0, sizeof(PyArrayMapIterObject) + sizeof(NPY_cast_info)); |
| 2772 | PyObject_Init((PyObject *)mit, &PyArrayMapIter_Type); |
| 2773 | |
| 2774 | Py_INCREF(arr); |
| 2775 | mit->array = arr; |
| 2776 | Py_XINCREF(subspace); |
| 2777 | mit->subspace = subspace; |
| 2778 | |
| 2779 | /* |
| 2780 | * The subspace, the part of the array which is not indexed by |
| 2781 | * arrays, needs to be iterated when the size of the subspace |
| 2782 | * is larger than 1. If it is one, it has only an effect on the |
| 2783 | * result shape. (Optimizes for example np.newaxis usage) |
| 2784 | */ |
| 2785 | if ((subspace == NULL) || PyArray_SIZE(subspace) == 1) { |
| 2786 | uses_subspace = 0; |
| 2787 | } |
| 2788 | else { |
no test coverage detected