@@ -92,114 +92,6 @@ parse_index_entry(PyObject *op, npy_intp *step_size,
92
92
}
93
93
94
94
95
- /*
96
- * Parses an index that has no fancy indexing. Populates
97
- * out_dimensions, out_strides, and out_offset.
98
- */
99
- NPY_NO_EXPORT int
100
- parse_index (PyArrayObject * self , PyObject * op ,
101
- npy_intp * out_dimensions ,
102
- npy_intp * out_strides ,
103
- npy_intp * out_offset ,
104
- int check_index )
105
- {
106
- int i , j , n ;
107
- int nd_old , nd_new , n_add , n_ellipsis ;
108
- npy_intp n_steps , start , offset , step_size ;
109
- PyObject * op1 = NULL ;
110
- int is_slice ;
111
-
112
- if (PySlice_Check (op ) || op == Py_Ellipsis || op == Py_None ) {
113
- n = 1 ;
114
- op1 = op ;
115
- Py_INCREF (op );
116
- /* this relies on the fact that n==1 for loop below */
117
- is_slice = 1 ;
118
- }
119
- else {
120
- if (!PySequence_Check (op )) {
121
- PyErr_SetString (PyExc_IndexError ,
122
- "index must be either an int "
123
- "or a sequence" );
124
- return -1 ;
125
- }
126
- n = PySequence_Length (op );
127
- is_slice = 0 ;
128
- }
129
-
130
- nd_old = nd_new = 0 ;
131
-
132
- offset = 0 ;
133
- for (i = 0 ; i < n ; i ++ ) {
134
- if (!is_slice ) {
135
- op1 = PySequence_GetItem (op , i );
136
- if (op1 == NULL ) {
137
- return -1 ;
138
- }
139
- }
140
- start = parse_index_entry (op1 , & step_size , & n_steps ,
141
- nd_old < PyArray_NDIM (self ) ?
142
- PyArray_DIMS (self )[nd_old ] : 0 ,
143
- nd_old , check_index ?
144
- nd_old < PyArray_NDIM (self ) : 0 );
145
- Py_DECREF (op1 );
146
- if (start == -1 ) {
147
- break ;
148
- }
149
- if (n_steps == NEWAXIS_INDEX ) {
150
- out_dimensions [nd_new ] = 1 ;
151
- out_strides [nd_new ] = 0 ;
152
- nd_new ++ ;
153
- }
154
- else if (n_steps == ELLIPSIS_INDEX ) {
155
- for (j = i + 1 , n_ellipsis = 0 ; j < n ; j ++ ) {
156
- op1 = PySequence_GetItem (op , j );
157
- if (op1 == Py_None ) {
158
- n_ellipsis ++ ;
159
- }
160
- Py_DECREF (op1 );
161
- }
162
- n_add = PyArray_NDIM (self )- (n - i - n_ellipsis - 1 + nd_old );
163
- if (n_add < 0 ) {
164
- PyErr_SetString (PyExc_IndexError , "too many indices" );
165
- return -1 ;
166
- }
167
- for (j = 0 ; j < n_add ; j ++ ) {
168
- out_dimensions [nd_new ] = PyArray_DIMS (self )[nd_old ];
169
- out_strides [nd_new ] = PyArray_STRIDES (self )[nd_old ];
170
- nd_new ++ ; nd_old ++ ;
171
- }
172
- }
173
- else {
174
- if (nd_old >= PyArray_NDIM (self )) {
175
- PyErr_SetString (PyExc_IndexError , "too many indices" );
176
- return -1 ;
177
- }
178
- offset += PyArray_STRIDES (self )[nd_old ]* start ;
179
- nd_old ++ ;
180
- if (n_steps != SINGLE_INDEX ) {
181
- out_dimensions [nd_new ] = n_steps ;
182
- out_strides [nd_new ] = step_size *
183
- PyArray_STRIDES (self )[nd_old - 1 ];
184
- nd_new ++ ;
185
- }
186
- }
187
- }
188
- if (i < n ) {
189
- return -1 ;
190
- }
191
- n_add = PyArray_NDIM (self )- nd_old ;
192
- for (j = 0 ; j < n_add ; j ++ ) {
193
- out_dimensions [nd_new ] = PyArray_DIMS (self )[nd_old ];
194
- out_strides [nd_new ] = PyArray_STRIDES (self )[nd_old ];
195
- nd_new ++ ;
196
- nd_old ++ ;
197
- }
198
- * out_offset = offset ;
199
- return nd_new ;
200
- }
201
-
202
-
203
95
/*********************** Element-wise Array Iterator ***********************/
204
96
/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/
205
97
/* and Python's array iterator ***/
0 commit comments