diff options
| author | Eric Wieser <wieser.eric@gmail.com> | 2018-02-01 00:20:14 -0800 |
|---|---|---|
| committer | Eric Wieser <wieser.eric@gmail.com> | 2018-02-03 11:36:30 -0800 |
| commit | ae76158a5aec8f78a9527ef94f65aa34d5901248 (patch) | |
| tree | 95032e1258372d32bcc78762beb23a9fe17abc32 /numpy/core/src | |
| parent | ef70f13177a53266fd8547da6e00bc252a057893 (diff) | |
| download | numpy-ae76158a5aec8f78a9527ef94f65aa34d5901248.tar.gz | |
MAINT: Use AxisError in diagonal
Diffstat (limited to 'numpy/core/src')
| -rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 17 |
1 files changed, 4 insertions, 13 deletions
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); |
