@@ -259,17 +259,10 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
259259 PyObject * tmp = PyTuple_GET_ITEM (axis_in , i );
260260 int axis = PyArray_PyIntAsInt_ErrMsg (tmp ,
261261 "integers are required for the axis tuple elements" );
262- int axis_orig = axis ;
263262 if (error_converting (axis )) {
264263 return NPY_FAIL ;
265264 }
266- if (axis < 0 ) {
267- axis += ndim ;
268- }
269- if (axis < 0 || axis >= ndim ) {
270- PyErr_Format (PyExc_ValueError ,
271- "'axis' entry %d is out of bounds [-%d, %d)" ,
272- axis_orig , ndim , ndim );
265+ if (check_and_adjust_axis (& axis , ndim ) < 0 ) {
273266 return NPY_FAIL ;
274267 }
275268 if (out_axis_flags [axis ]) {
@@ -284,20 +277,16 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
284277 }
285278 /* Try to interpret axis as an integer */
286279 else {
287- int axis , axis_orig ;
280+ int axis ;
288281
289282 memset (out_axis_flags , 0 , ndim );
290283
291284 axis = PyArray_PyIntAsInt_ErrMsg (axis_in ,
292285 "an integer is required for the axis" );
293- axis_orig = axis ;
294286
295287 if (error_converting (axis )) {
296288 return NPY_FAIL ;
297289 }
298- if (axis < 0 ) {
299- axis += ndim ;
300- }
301290 /*
302291 * Special case letting axis={-1,0} slip through for scalars,
303292 * for backwards compatibility reasons.
@@ -306,10 +295,7 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
306295 return NPY_SUCCEED ;
307296 }
308297
309- if (axis < 0 || axis >= ndim ) {
310- PyErr_Format (PyExc_ValueError ,
311- "'axis' entry %d is out of bounds [-%d, %d)" ,
312- axis_orig , ndim , ndim );
298+ if (check_and_adjust_axis (& axis , ndim ) < 0 ) {
313299 return NPY_FAIL ;
314300 }
315301
0 commit comments