From ae76158a5aec8f78a9527ef94f65aa34d5901248 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 1 Feb 2018 00:20:14 -0800 Subject: MAINT: Use AxisError in diagonal --- numpy/core/src/multiarray/item_selection.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'numpy/core/src') diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 486eb43ce..208b96687 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -1818,26 +1818,17 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) } /* Handle negative axes with standard Python indexing rules */ - if (axis1 < 0) { - axis1 += ndim; + if (check_and_adjust_axis_cmsg(&axis1, ndim, "axis1") < 0) { + return NULL; } - if (axis2 < 0) { - axis2 += ndim; + if (check_and_adjust_axis_cmsg(&axis2, ndim, "axis2") < 0) { + return NULL; } - - /* Error check the two axes */ if (axis1 == axis2) { PyErr_SetString(PyExc_ValueError, "axis1 and axis2 cannot be the same"); return NULL; } - else if (axis1 < 0 || axis1 >= ndim || axis2 < 0 || axis2 >= ndim) { - PyErr_Format(PyExc_ValueError, - "axis1(=%d) and axis2(=%d) " - "must be within range (ndim=%d)", - axis1, axis2, ndim); - return NULL; - } /* Get the shape and strides of the two axes */ shape = PyArray_SHAPE(self); -- cgit v1.2.1