From 29f1212823716bd90f06ab15d9c2fca41f9ba96a Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Tue, 1 Aug 2017 10:46:43 +0900 Subject: [PATCH 1/8] Revert "Revert "Support NumPy 1.13"" --- cupy/core/core.pyx | 14 ++++++++------ cupy/manipulation/join.py | 5 ++++- cupy/manipulation/rearrange.py | 8 ++++++-- cupy/math/sumprod.py | 4 ++-- cupy/statistics/histogram.py | 2 +- tests/cupy_tests/core_tests/test_fusion.py | 2 +- tests/cupy_tests/core_tests/test_ndarray.py | 1 + .../cupy_tests/core_tests/test_ndarray_unary_op.py | 14 ++++++++++---- tests/cupy_tests/manipulation_tests/test_dims.py | 4 ++++ tests/cupy_tests/manipulation_tests/test_join.py | 2 +- .../manipulation_tests/test_rearrange.py | 2 ++ tests/cupy_tests/math_tests/test_sumprod.py | 4 ++++ tests/cupy_tests/statics_tests/test_histogram.py | 11 +++++++++-- 13 files changed, 53 insertions(+), 20 deletions(-) diff --git a/cupy/core/core.pyx b/cupy/core/core.pyx index 7b094e57d39..bea9adc19bc 100644 --- a/cupy/core/core.pyx +++ b/cupy/core/core.pyx @@ -605,8 +605,9 @@ cdef class ndarray: if _axis < 0: _axis += ndim if _axis < 0 or _axis >= ndim: - msg = "'axis' entry %d is out of bounds [-%d, %d)" - raise ValueError(msg % (axis_orig, ndim, ndim)) + raise numpy.AxisError( + "'axis' entry %d is out of bounds [-%d, %d)" % + (axis_orig, ndim, ndim)) if axis_flags[_axis] == 1: raise ValueError("duplicate value in 'axis'") axis_flags[_axis] = 1 @@ -621,8 +622,9 @@ cdef class ndarray: pass else: if _axis < 0 or _axis >= ndim: - msg = "'axis' entry %d is out of bounds [-%d, %d)" - raise ValueError(msg % (axis_orig, ndim, ndim)) + raise numpy.AxisError( + "'axis' entry %d is out of bounds [-%d, %d)" % + (axis_orig, ndim, ndim)) axis_flags[_axis] = 1 # Verify that the axes requested are all of size one @@ -2273,7 +2275,7 @@ cpdef ndarray concatenate_method(tup, int axis): if axis < 0: axis += ndim if axis < 0 or axis >= ndim: - raise IndexError( + raise numpy.AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) dtype = a.dtype continue @@ -2649,7 +2651,7 @@ cpdef ndarray _take(ndarray a, indices, li=None, ri=None, ndarray out=None): index_range = a.size else: if not (-a.ndim <= li < a.ndim and -a.ndim <= ri < a.ndim): - raise ValueError('Axis overrun') + raise numpy.AxisError('Axis overrun') if a.ndim != 0: li %= a.ndim ri %= a.ndim diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py index 339febb1f7a..f20bb913116 100644 --- a/cupy/manipulation/join.py +++ b/cupy/manipulation/join.py @@ -1,3 +1,5 @@ +import numpy + import cupy from cupy import core @@ -128,5 +130,6 @@ def _get_positive_axis(ndim, axis): if a < 0: a += ndim if a < 0 or a >= ndim: - raise IndexError('axis {} out of bounds [0, {})'.format(axis, ndim)) + raise numpy.AxisError( + 'axis {} out of bounds [0, {})'.format(axis, ndim)) return a diff --git a/cupy/manipulation/rearrange.py b/cupy/manipulation/rearrange.py index 17197b0aaac..8158a20aaf7 100644 --- a/cupy/manipulation/rearrange.py +++ b/cupy/manipulation/rearrange.py @@ -1,3 +1,5 @@ +import numpy + import cupy @@ -23,7 +25,8 @@ def flip(a, axis): axis = int(axis) if not -a_ndim <= axis < a_ndim: - raise ValueError('axis must be >= %d and < %d' % (-a_ndim, a_ndim)) + raise ValueError( + 'axis must be >= %d and < %d' % (-a_ndim, a_ndim)) return _flip(a, axis) @@ -99,7 +102,8 @@ def roll(a, shift, axis=None): if axis < 0: axis += a.ndim if not 0 <= axis < a.ndim: - raise ValueError('axis must be >= %d and < %d' % (-a.ndim, a.ndim)) + raise numpy.AxisError( + 'axis must be >= %d and < %d' % (-a.ndim, a.ndim)) size = a.shape[axis] if size == 0: return a diff --git a/cupy/math/sumprod.py b/cupy/math/sumprod.py index 083d486e3f1..3c8cb34feaf 100644 --- a/cupy/math/sumprod.py +++ b/cupy/math/sumprod.py @@ -125,7 +125,7 @@ def cumsum(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise ValueError('axis(={}) out of bounds'.format(axis)) + raise numpy.AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumsum_batch, out, axis=axis) @@ -203,7 +203,7 @@ def cumprod(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise ValueError('axis(={}) out of bounds'.format(axis)) + raise numpy.AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumprod_batch, out, axis=axis) diff --git a/cupy/statistics/histogram.py b/cupy/statistics/histogram.py index 0753e10c471..22e67878e29 100644 --- a/cupy/statistics/histogram.py +++ b/cupy/statistics/histogram.py @@ -40,7 +40,7 @@ def bincount(x, weights=None, minlength=None): raise ValueError('The weights and list don\'t have the same length.') if minlength is not None: minlength = int(minlength) - if minlength <= 0: + if minlength < 0: raise ValueError('minlength must be positive') size = int(cupy.max(x)) + 1 diff --git a/tests/cupy_tests/core_tests/test_fusion.py b/tests/cupy_tests/core_tests/test_fusion.py index 938af177e4f..3c0838b73af 100644 --- a/tests/cupy_tests/core_tests/test_fusion.py +++ b/tests/cupy_tests/core_tests/test_fusion.py @@ -949,7 +949,7 @@ def g(x, y, z): return g(a, b, c) - @testing.for_all_dtypes() + @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_array_equal() def test_fuse3(self, xp, dtype): a = xp.array([2, 2, 2, 2, 3, 3, 3, 3], dtype=dtype) diff --git a/tests/cupy_tests/core_tests/test_ndarray.py b/tests/cupy_tests/core_tests/test_ndarray.py index d30f93b2950..63fe71ed0d4 100644 --- a/tests/cupy_tests/core_tests/test_ndarray.py +++ b/tests/cupy_tests/core_tests/test_ndarray.py @@ -217,6 +217,7 @@ def test_take(self, xp, dtype): class TestNdarrayTakeErrorAxisOverRun(unittest.TestCase): @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_axis_overrun(self, xp, dtype): a = testing.shaped_arange(self.shape, xp, dtype) diff --git a/tests/cupy_tests/core_tests/test_ndarray_unary_op.py b/tests/cupy_tests/core_tests/test_ndarray_unary_op.py index a95da06c563..039229672dd 100644 --- a/tests/cupy_tests/core_tests/test_ndarray_unary_op.py +++ b/tests/cupy_tests/core_tests/test_ndarray_unary_op.py @@ -51,8 +51,11 @@ def check_array_op(self, op, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return op(a) - def test_neg_array(self): - self.check_array_op(operator.neg) + @testing.for_all_dtypes(no_bool=True) + @testing.numpy_cupy_allclose() + def test_neg_array(self, xp, dtype): + a = testing.shaped_arange((2, 3), xp, dtype) + return operator.neg(a) def test_pos_array(self): self.check_array_op(operator.pos) @@ -66,8 +69,11 @@ def check_zerodim_op(self, op, xp, dtype): a = xp.array(-2, dtype) return op(a) - def test_neg_zerodim(self): - self.check_zerodim_op(operator.neg) + @testing.for_all_dtypes(no_bool=True) + @testing.numpy_cupy_allclose() + def test_neg_zerodim(self, xp, dtype): + a = xp.array(-2, dtype) + return operator.neg(a) def test_pos_zerodim(self): self.check_zerodim_op(operator.pos) diff --git a/tests/cupy_tests/manipulation_tests/test_dims.py b/tests/cupy_tests/manipulation_tests/test_dims.py index 4f41303602a..307ba33cade 100644 --- a/tests/cupy_tests/manipulation_tests/test_dims.py +++ b/tests/cupy_tests/manipulation_tests/test_dims.py @@ -161,6 +161,7 @@ def test_squeze_int_axis2(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) return a.squeeze(axis=-3) + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_squeze_int_axis_failure(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) @@ -186,6 +187,7 @@ def test_squeze_tuple_axis4(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) return a.squeeze(axis=()) + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_squeze_tuple_axis_failure1(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) @@ -206,11 +208,13 @@ def test_squeeze_scalar2(self, xp): a = testing.shaped_arange((), xp) return a.squeeze(axis=-1) + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_squeeze_scalar_failure1(self, xp): a = testing.shaped_arange((), xp) a.squeeze(axis=-2) + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_squeeze_scalar_failure2(self, xp): a = testing.shaped_arange((), xp) diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py index 78371335259..ae73d80f20b 100644 --- a/tests/cupy_tests/manipulation_tests/test_join.py +++ b/tests/cupy_tests/manipulation_tests/test_join.py @@ -206,7 +206,7 @@ def test_stack_different_shape(self, xp): b = testing.shaped_arange((2, 4), xp) return xp.stack([a, b]) - @testing.with_requires('numpy>=1.10') + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_stack_out_of_bounds(self, xp): a = testing.shaped_arange((2, 3), xp) diff --git a/tests/cupy_tests/manipulation_tests/test_rearrange.py b/tests/cupy_tests/manipulation_tests/test_rearrange.py index 2b1724e83eb..47aa475c6a5 100644 --- a/tests/cupy_tests/manipulation_tests/test_rearrange.py +++ b/tests/cupy_tests/manipulation_tests/test_rearrange.py @@ -57,12 +57,14 @@ def test_roll_zero_array(self, xp, dtype): return xp.roll(x, 5) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_roll_invalid_axis(self, xp, dtype): x = testing.shaped_arange((5, 2), xp, dtype) return xp.roll(x, 1, axis=2) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_roll_invalid_negative_axis(self, xp, dtype): x = testing.shaped_arange((5, 2), xp, dtype) diff --git a/tests/cupy_tests/math_tests/test_sumprod.py b/tests/cupy_tests/math_tests/test_sumprod.py index e229a7e0f69..c2f2bbade14 100644 --- a/tests/cupy_tests/math_tests/test_sumprod.py +++ b/tests/cupy_tests/math_tests/test_sumprod.py @@ -188,12 +188,14 @@ def test_cumsum_axis(self, xp, dtype): return xp.cumsum(a, axis=self.axis) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_invalid_axis_lower(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumsum(a, axis=-a.ndim - 1) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_invalid_axis_upper(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) @@ -230,12 +232,14 @@ def test_cumprod_huge_array(self, xp): return xp.cumprod(a) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_invalid_axis_lower(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumprod(a, axis=-a.ndim - 1) @testing.for_all_dtypes() + @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() def test_invalid_axis_upper(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) diff --git a/tests/cupy_tests/statics_tests/test_histogram.py b/tests/cupy_tests/statics_tests/test_histogram.py index f60a40224f5..5ce81c36fa2 100644 --- a/tests/cupy_tests/statics_tests/test_histogram.py +++ b/tests/cupy_tests/statics_tests/test_histogram.py @@ -91,7 +91,14 @@ def test_bincount_too_small(self, xp, dtype): return xp.bincount(x) @for_all_dtypes_bincount() - @testing.numpy_cupy_raises() - def test_bincount_zero_minlength(self, xp, dtype): + @testing.with_requires('numpy>=1.13') + @testing.numpy_cupy_allclose(accept_error=TypeError) + def test_bincount_zero(self, xp, dtype): x = testing.shaped_arange((3,), xp, dtype) return xp.bincount(x, minlength=0) + + @for_all_dtypes_bincount() + @testing.numpy_cupy_raises() + def test_bincount_too_small_minlength(self, xp, dtype): + x = testing.shaped_arange((3,), xp, dtype) + return xp.bincount(x, minlength=-1) From 5c63f1554e1b08b5d6420c066cda2c09907fcd2e Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Mon, 31 Jul 2017 18:06:23 +0900 Subject: [PATCH 2/8] Fix AxisError problem --- cupy/core/__init__.py | 1 + cupy/core/core.pyx | 19 +++++++++++++++---- cupy/manipulation/join.py | 4 +--- cupy/manipulation/rearrange.py | 5 ++--- cupy/math/sumprod.py | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cupy/core/__init__.py b/cupy/core/__init__.py index 7fc262f748b..d92019d9e19 100644 --- a/cupy/core/__init__.py +++ b/cupy/core/__init__.py @@ -9,6 +9,7 @@ from cupy.core.core import array_split # NOQA from cupy.core.core import ascontiguousarray # NOQA from cupy.core.core import asfortranarray # NOQA +from cupy.core.core import AxisError # NOQA from cupy.core.core import bitwise_and # NOQA from cupy.core.core import bitwise_or # NOQA from cupy.core.core import bitwise_xor # NOQA diff --git a/cupy/core/core.pyx b/cupy/core/core.pyx index bea9adc19bc..ba1cc60fe90 100644 --- a/cupy/core/core.pyx +++ b/cupy/core/core.pyx @@ -36,6 +36,17 @@ cdef inline _should_use_rop(x, y): return xp < yp and not isinstance(y, ndarray) +class IndexOrValueError(IndexError, ValueError): + + def __init__(self, *args, **kwargs): + super(IndexOrValueError, self).__init__(*args, **kwargs) + +try: + AxisError = numpy.AxisError +except AttributeError: + AxisError = IndexOrValueError + + cdef class ndarray: """Multi-dimensional array on a CUDA device. @@ -605,7 +616,7 @@ cdef class ndarray: if _axis < 0: _axis += ndim if _axis < 0 or _axis >= ndim: - raise numpy.AxisError( + raise AxisError( "'axis' entry %d is out of bounds [-%d, %d)" % (axis_orig, ndim, ndim)) if axis_flags[_axis] == 1: @@ -622,7 +633,7 @@ cdef class ndarray: pass else: if _axis < 0 or _axis >= ndim: - raise numpy.AxisError( + raise AxisError( "'axis' entry %d is out of bounds [-%d, %d)" % (axis_orig, ndim, ndim)) axis_flags[_axis] = 1 @@ -2275,7 +2286,7 @@ cpdef ndarray concatenate_method(tup, int axis): if axis < 0: axis += ndim if axis < 0 or axis >= ndim: - raise numpy.AxisError( + raise AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) dtype = a.dtype continue @@ -2651,7 +2662,7 @@ cpdef ndarray _take(ndarray a, indices, li=None, ri=None, ndarray out=None): index_range = a.size else: if not (-a.ndim <= li < a.ndim and -a.ndim <= ri < a.ndim): - raise numpy.AxisError('Axis overrun') + raise AxisError('Axis overrun') if a.ndim != 0: li %= a.ndim ri %= a.ndim diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py index f20bb913116..121235baf25 100644 --- a/cupy/manipulation/join.py +++ b/cupy/manipulation/join.py @@ -1,5 +1,3 @@ -import numpy - import cupy from cupy import core @@ -130,6 +128,6 @@ def _get_positive_axis(ndim, axis): if a < 0: a += ndim if a < 0 or a >= ndim: - raise numpy.AxisError( + raise core.AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) return a diff --git a/cupy/manipulation/rearrange.py b/cupy/manipulation/rearrange.py index 8158a20aaf7..0fc8c86b821 100644 --- a/cupy/manipulation/rearrange.py +++ b/cupy/manipulation/rearrange.py @@ -1,6 +1,5 @@ -import numpy - import cupy +from cupy import core def flip(a, axis): @@ -102,7 +101,7 @@ def roll(a, shift, axis=None): if axis < 0: axis += a.ndim if not 0 <= axis < a.ndim: - raise numpy.AxisError( + raise core.AxisError( 'axis must be >= %d and < %d' % (-a.ndim, a.ndim)) size = a.shape[axis] if size == 0: diff --git a/cupy/math/sumprod.py b/cupy/math/sumprod.py index 3c8cb34feaf..24e72cb1f2a 100644 --- a/cupy/math/sumprod.py +++ b/cupy/math/sumprod.py @@ -125,7 +125,7 @@ def cumsum(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise numpy.AxisError('axis(={}) out of bounds'.format(axis)) + raise core.AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumsum_batch, out, axis=axis) @@ -203,7 +203,7 @@ def cumprod(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise numpy.AxisError('axis(={}) out of bounds'.format(axis)) + raise core.AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumprod_batch, out, axis=axis) From 1c97d217b5db2df809b621ec9149dc032ebc170e Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Mon, 31 Jul 2017 22:34:14 +0900 Subject: [PATCH 3/8] Add test for old numpy environment --- tests/cupy_tests/core_tests/test_ndarray.py | 9 +++++- .../manipulation_tests/test_dims.py | 22 ++++++++++++- .../manipulation_tests/test_join.py | 7 +++- .../manipulation_tests/test_rearrange.py | 17 ++++++++-- tests/cupy_tests/math_tests/test_sumprod.py | 32 ++++++++++++++++--- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/tests/cupy_tests/core_tests/test_ndarray.py b/tests/cupy_tests/core_tests/test_ndarray.py index 63fe71ed0d4..d51c30445c7 100644 --- a/tests/cupy_tests/core_tests/test_ndarray.py +++ b/tests/cupy_tests/core_tests/test_ndarray.py @@ -3,6 +3,7 @@ import numpy +import cupy from cupy import core from cupy import cuda from cupy import get_array_module @@ -219,10 +220,16 @@ class TestNdarrayTakeErrorAxisOverRun(unittest.TestCase): @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_axis_overrun(self, xp, dtype): + def test_axis_overrun1(self, xp, dtype): a = testing.shaped_arange(self.shape, xp, dtype) wrap_take(a, self.indices, axis=self.axis) + @testing.for_all_dtypes() + def test_axis_overrun2(self, dtype): + a = testing.shaped_arange(self.shape, cupy, dtype) + with self.assertRaises(core.AxisError): + wrap_take(a, self.indices, axis=self.axis) + @testing.parameterize( {"shape": (3, 4, 5), "indices": (2, 3), "out_shape": (2, 4)}, diff --git a/tests/cupy_tests/manipulation_tests/test_dims.py b/tests/cupy_tests/manipulation_tests/test_dims.py index 307ba33cade..a02dcc46ec7 100644 --- a/tests/cupy_tests/manipulation_tests/test_dims.py +++ b/tests/cupy_tests/manipulation_tests/test_dims.py @@ -163,10 +163,15 @@ def test_squeze_int_axis2(self, xp): @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_squeze_int_axis_failure(self, xp): + def test_squeze_int_axis_failure1(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) a.squeeze(axis=-9) + def test_squeze_int_axis_failure2(self): + a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) + with self.assertRaises(cupy.core.AxisError): + a.squeeze(axis=-9) + @testing.numpy_cupy_array_equal() def test_squeze_tuple_axis1(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) @@ -198,6 +203,11 @@ def test_squeze_tuple_axis_failure2(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) a.squeeze(axis=(2, 2)) + def test_squeze_tuple_axis_failure3(self): + a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) + with self.assertRaises(cupy.core.AxisError): + a.squeeze(axis=(-9,)) + @testing.numpy_cupy_array_equal() def test_squeeze_scalar1(self, xp): a = testing.shaped_arange((), xp) @@ -220,6 +230,16 @@ def test_squeeze_scalar_failure2(self, xp): a = testing.shaped_arange((), xp) a.squeeze(axis=1) + def test_squeeze_scalar_failure3(self): + a = testing.shaped_arange((), cupy) + with self.assertRaises(cupy.core.AxisError): + a.squeeze(axis=-2) + + def test_squeeze_scalar_failure4(self): + a = testing.shaped_arange((), cupy) + with self.assertRaises(cupy.core.AxisError): + a.squeeze(axis=1) + @testing.numpy_cupy_raises() def test_squeeze_failure(self, xp): a = testing.shaped_arange((2, 1, 3, 4), xp) diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py index ae73d80f20b..f661bf0a8b2 100644 --- a/tests/cupy_tests/manipulation_tests/test_join.py +++ b/tests/cupy_tests/manipulation_tests/test_join.py @@ -208,6 +208,11 @@ def test_stack_different_shape(self, xp): @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_stack_out_of_bounds(self, xp): + def test_stack_out_of_bounds1(self, xp): a = testing.shaped_arange((2, 3), xp) return xp.stack([a, a], axis=3) + + def test_stack_out_of_bounds2(self): + a = testing.shaped_arange((2, 3), cupy) + with self.assertRaises(cupy.core.AxisError): + return cupy.stack([a, a], axis=3) diff --git a/tests/cupy_tests/manipulation_tests/test_rearrange.py b/tests/cupy_tests/manipulation_tests/test_rearrange.py index 47aa475c6a5..3d5381198dc 100644 --- a/tests/cupy_tests/manipulation_tests/test_rearrange.py +++ b/tests/cupy_tests/manipulation_tests/test_rearrange.py @@ -1,5 +1,6 @@ import unittest +import cupy from cupy import testing @@ -59,17 +60,29 @@ def test_roll_zero_array(self, xp, dtype): @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_roll_invalid_axis(self, xp, dtype): + def test_roll_invalid_axis1(self, xp, dtype): x = testing.shaped_arange((5, 2), xp, dtype) return xp.roll(x, 1, axis=2) + @testing.for_all_dtypes() + def test_roll_invalid_axis2(self, dtype): + x = testing.shaped_arange((5, 2), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.roll(x, 1, axis=2) + @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_roll_invalid_negative_axis(self, xp, dtype): + def test_roll_invalid_negative_axis1(self, xp, dtype): x = testing.shaped_arange((5, 2), xp, dtype) return xp.roll(x, 1, axis=-3) + @testing.for_all_dtypes() + def test_roll_invalid_negative_axis2(self, dtype): + x = testing.shaped_arange((5, 2), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.roll(x, 1, axis=-3) + @testing.gpu class TestFliplr(unittest.TestCase): diff --git a/tests/cupy_tests/math_tests/test_sumprod.py b/tests/cupy_tests/math_tests/test_sumprod.py index c2f2bbade14..91339d94be9 100644 --- a/tests/cupy_tests/math_tests/test_sumprod.py +++ b/tests/cupy_tests/math_tests/test_sumprod.py @@ -190,17 +190,29 @@ def test_cumsum_axis(self, xp, dtype): @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_invalid_axis_lower(self, xp, dtype): + def test_invalid_axis_lower1(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumsum(a, axis=-a.ndim - 1) + @testing.for_all_dtypes() + def test_invalid_axis_lower2(self, dtype): + a = testing.shaped_arange((4, 5), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.cumsum(a, axis=-a.ndim - 1) + @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_invalid_axis_upper(self, xp, dtype): + def test_invalid_axis_upper1(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumsum(a, axis=a.ndim + 1) + @testing.for_all_dtypes() + def test_invalid_axis_upper2(self, dtype): + a = testing.shaped_arange((4, 5), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.cumsum(a, axis=a.ndim + 1) + @testing.gpu class TestCumprod(unittest.TestCase): @@ -234,13 +246,25 @@ def test_cumprod_huge_array(self, xp): @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_invalid_axis_lower(self, xp, dtype): + def test_invalid_axis_lower1(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumprod(a, axis=-a.ndim - 1) + @testing.for_all_dtypes() + def test_invalid_axis_lower2(self, dtype): + a = testing.shaped_arange((4, 5), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.cumprod(a, axis=-a.ndim - 1) + @testing.for_all_dtypes() @testing.with_requires('numpy>=1.13') @testing.numpy_cupy_raises() - def test_invalid_axis_upper(self, xp, dtype): + def test_invalid_axis_upper1(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumprod(a, axis=a.ndim) + + @testing.for_all_dtypes() + def test_invalid_axis_upper2(self, dtype): + a = testing.shaped_arange((4, 5), cupy, dtype) + with self.assertRaises(cupy.core.AxisError): + return cupy.cumprod(a, axis=a.ndim) From 995c99327bcb46a9895f8a5cc5471a1b235af9e1 Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Tue, 1 Aug 2017 10:59:50 +0900 Subject: [PATCH 4/8] Fix document --- docs/source/install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/install.rst b/docs/source/install.rst index ac041b8a9cc..6124084fa3e 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -44,7 +44,7 @@ Before installing CuPy, we recommend to upgrade ``setuptools`` if you are using The following Python packages are required to install CuPy. The latest version of each package will automatically be installed if missing. -* `NumPy `_ 1.9, 1.10, 1.11, 1.12 +* `NumPy `_ 1.9, 1.10, 1.11, 1.12, 1.13 * `Six `_ 1.9+ CUDA support From a2bb5a371e892a7d6c4d20ded6db2bc1c1e6b17b Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Mon, 7 Aug 2017 15:26:19 +0900 Subject: [PATCH 5/8] Add underscore --- cupy/core/__init__.py | 2 +- cupy/core/core.pyx | 12 ++++++------ cupy/manipulation/join.py | 2 +- cupy/manipulation/rearrange.py | 2 +- cupy/math/sumprod.py | 4 ++-- tests/cupy_tests/core_tests/test_ndarray.py | 2 +- tests/cupy_tests/manipulation_tests/test_dims.py | 8 ++++---- tests/cupy_tests/manipulation_tests/test_join.py | 2 +- .../cupy_tests/manipulation_tests/test_rearrange.py | 4 ++-- tests/cupy_tests/math_tests/test_sumprod.py | 8 ++++---- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cupy/core/__init__.py b/cupy/core/__init__.py index d92019d9e19..dfddabc943b 100644 --- a/cupy/core/__init__.py +++ b/cupy/core/__init__.py @@ -3,13 +3,13 @@ # import class and function +from cupy.core.core import _AxisError # NOQA from cupy.core.core import absolute # NOQA from cupy.core.core import add # NOQA from cupy.core.core import array # NOQA from cupy.core.core import array_split # NOQA from cupy.core.core import ascontiguousarray # NOQA from cupy.core.core import asfortranarray # NOQA -from cupy.core.core import AxisError # NOQA from cupy.core.core import bitwise_and # NOQA from cupy.core.core import bitwise_or # NOQA from cupy.core.core import bitwise_xor # NOQA diff --git a/cupy/core/core.pyx b/cupy/core/core.pyx index ba1cc60fe90..7ce9246d823 100644 --- a/cupy/core/core.pyx +++ b/cupy/core/core.pyx @@ -42,9 +42,9 @@ class IndexOrValueError(IndexError, ValueError): super(IndexOrValueError, self).__init__(*args, **kwargs) try: - AxisError = numpy.AxisError + _AxisError = numpy.AxisError except AttributeError: - AxisError = IndexOrValueError + _AxisError = IndexOrValueError cdef class ndarray: @@ -616,7 +616,7 @@ cdef class ndarray: if _axis < 0: _axis += ndim if _axis < 0 or _axis >= ndim: - raise AxisError( + raise _AxisError( "'axis' entry %d is out of bounds [-%d, %d)" % (axis_orig, ndim, ndim)) if axis_flags[_axis] == 1: @@ -633,7 +633,7 @@ cdef class ndarray: pass else: if _axis < 0 or _axis >= ndim: - raise AxisError( + raise _AxisError( "'axis' entry %d is out of bounds [-%d, %d)" % (axis_orig, ndim, ndim)) axis_flags[_axis] = 1 @@ -2286,7 +2286,7 @@ cpdef ndarray concatenate_method(tup, int axis): if axis < 0: axis += ndim if axis < 0 or axis >= ndim: - raise AxisError( + raise _AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) dtype = a.dtype continue @@ -2662,7 +2662,7 @@ cpdef ndarray _take(ndarray a, indices, li=None, ri=None, ndarray out=None): index_range = a.size else: if not (-a.ndim <= li < a.ndim and -a.ndim <= ri < a.ndim): - raise AxisError('Axis overrun') + raise _AxisError('Axis overrun') if a.ndim != 0: li %= a.ndim ri %= a.ndim diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py index 121235baf25..ac1b0784253 100644 --- a/cupy/manipulation/join.py +++ b/cupy/manipulation/join.py @@ -128,6 +128,6 @@ def _get_positive_axis(ndim, axis): if a < 0: a += ndim if a < 0 or a >= ndim: - raise core.AxisError( + raise core._AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) return a diff --git a/cupy/manipulation/rearrange.py b/cupy/manipulation/rearrange.py index 0fc8c86b821..9d11a162a5f 100644 --- a/cupy/manipulation/rearrange.py +++ b/cupy/manipulation/rearrange.py @@ -101,7 +101,7 @@ def roll(a, shift, axis=None): if axis < 0: axis += a.ndim if not 0 <= axis < a.ndim: - raise core.AxisError( + raise core._AxisError( 'axis must be >= %d and < %d' % (-a.ndim, a.ndim)) size = a.shape[axis] if size == 0: diff --git a/cupy/math/sumprod.py b/cupy/math/sumprod.py index 24e72cb1f2a..7e0824fef67 100644 --- a/cupy/math/sumprod.py +++ b/cupy/math/sumprod.py @@ -125,7 +125,7 @@ def cumsum(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise core.AxisError('axis(={}) out of bounds'.format(axis)) + raise core._AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumsum_batch, out, axis=axis) @@ -203,7 +203,7 @@ def cumprod(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise core.AxisError('axis(={}) out of bounds'.format(axis)) + raise core._AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumprod_batch, out, axis=axis) diff --git a/tests/cupy_tests/core_tests/test_ndarray.py b/tests/cupy_tests/core_tests/test_ndarray.py index d51c30445c7..dd694f7639e 100644 --- a/tests/cupy_tests/core_tests/test_ndarray.py +++ b/tests/cupy_tests/core_tests/test_ndarray.py @@ -227,7 +227,7 @@ def test_axis_overrun1(self, xp, dtype): @testing.for_all_dtypes() def test_axis_overrun2(self, dtype): a = testing.shaped_arange(self.shape, cupy, dtype) - with self.assertRaises(core.AxisError): + with self.assertRaises(core._AxisError): wrap_take(a, self.indices, axis=self.axis) diff --git a/tests/cupy_tests/manipulation_tests/test_dims.py b/tests/cupy_tests/manipulation_tests/test_dims.py index a02dcc46ec7..12e43029fed 100644 --- a/tests/cupy_tests/manipulation_tests/test_dims.py +++ b/tests/cupy_tests/manipulation_tests/test_dims.py @@ -169,7 +169,7 @@ def test_squeze_int_axis_failure1(self, xp): def test_squeze_int_axis_failure2(self): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): a.squeeze(axis=-9) @testing.numpy_cupy_array_equal() @@ -205,7 +205,7 @@ def test_squeze_tuple_axis_failure2(self, xp): def test_squeze_tuple_axis_failure3(self): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): a.squeeze(axis=(-9,)) @testing.numpy_cupy_array_equal() @@ -232,12 +232,12 @@ def test_squeeze_scalar_failure2(self, xp): def test_squeeze_scalar_failure3(self): a = testing.shaped_arange((), cupy) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): a.squeeze(axis=-2) def test_squeeze_scalar_failure4(self): a = testing.shaped_arange((), cupy) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): a.squeeze(axis=1) @testing.numpy_cupy_raises() diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py index f661bf0a8b2..a33835fde5a 100644 --- a/tests/cupy_tests/manipulation_tests/test_join.py +++ b/tests/cupy_tests/manipulation_tests/test_join.py @@ -214,5 +214,5 @@ def test_stack_out_of_bounds1(self, xp): def test_stack_out_of_bounds2(self): a = testing.shaped_arange((2, 3), cupy) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.stack([a, a], axis=3) diff --git a/tests/cupy_tests/manipulation_tests/test_rearrange.py b/tests/cupy_tests/manipulation_tests/test_rearrange.py index 3d5381198dc..11044f0e2ee 100644 --- a/tests/cupy_tests/manipulation_tests/test_rearrange.py +++ b/tests/cupy_tests/manipulation_tests/test_rearrange.py @@ -67,7 +67,7 @@ def test_roll_invalid_axis1(self, xp, dtype): @testing.for_all_dtypes() def test_roll_invalid_axis2(self, dtype): x = testing.shaped_arange((5, 2), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.roll(x, 1, axis=2) @testing.for_all_dtypes() @@ -80,7 +80,7 @@ def test_roll_invalid_negative_axis1(self, xp, dtype): @testing.for_all_dtypes() def test_roll_invalid_negative_axis2(self, dtype): x = testing.shaped_arange((5, 2), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.roll(x, 1, axis=-3) diff --git a/tests/cupy_tests/math_tests/test_sumprod.py b/tests/cupy_tests/math_tests/test_sumprod.py index 91339d94be9..83602e2055c 100644 --- a/tests/cupy_tests/math_tests/test_sumprod.py +++ b/tests/cupy_tests/math_tests/test_sumprod.py @@ -197,7 +197,7 @@ def test_invalid_axis_lower1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_lower2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.cumsum(a, axis=-a.ndim - 1) @testing.for_all_dtypes() @@ -210,7 +210,7 @@ def test_invalid_axis_upper1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_upper2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.cumsum(a, axis=a.ndim + 1) @@ -253,7 +253,7 @@ def test_invalid_axis_lower1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_lower2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.cumprod(a, axis=-a.ndim - 1) @testing.for_all_dtypes() @@ -266,5 +266,5 @@ def test_invalid_axis_upper1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_upper2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core.AxisError): + with self.assertRaises(cupy.core._AxisError): return cupy.cumprod(a, axis=a.ndim) From 078efee53cf2656b872f8c46e782214ad3aca39b Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Mon, 7 Aug 2017 16:34:02 +0900 Subject: [PATCH 6/8] Move IndexOrValueError --- cupy/core/core.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cupy/core/core.pyx b/cupy/core/core.pyx index 7ce9246d823..16bc3598456 100644 --- a/cupy/core/core.pyx +++ b/cupy/core/core.pyx @@ -36,14 +36,14 @@ cdef inline _should_use_rop(x, y): return xp < yp and not isinstance(y, ndarray) -class IndexOrValueError(IndexError, ValueError): - - def __init__(self, *args, **kwargs): - super(IndexOrValueError, self).__init__(*args, **kwargs) - try: _AxisError = numpy.AxisError except AttributeError: + class IndexOrValueError(IndexError, ValueError): + + def __init__(self, *args, **kwargs): + super(IndexOrValueError, self).__init__(*args, **kwargs) + _AxisError = IndexOrValueError From ba3fb057f44e0576deff6c1f9f63ff744e8dd5f0 Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Tue, 8 Aug 2017 23:45:09 +0900 Subject: [PATCH 7/8] Fix error message --- cupy/statistics/histogram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cupy/statistics/histogram.py b/cupy/statistics/histogram.py index 22e67878e29..f0534947a57 100644 --- a/cupy/statistics/histogram.py +++ b/cupy/statistics/histogram.py @@ -41,7 +41,7 @@ def bincount(x, weights=None, minlength=None): if minlength is not None: minlength = int(minlength) if minlength < 0: - raise ValueError('minlength must be positive') + raise ValueError('minlength must be non-negative') size = int(cupy.max(x)) + 1 if minlength is not None: From 211d3642d417f5d3e8d695eb3e028a69d85caf18 Mon Sep 17 00:00:00 2001 From: Ryosuke Okuta Date: Wed, 9 Aug 2017 22:22:58 +0900 Subject: [PATCH 8/8] Remove _AxisError from __init__.py --- cupy/core/__init__.py | 1 - cupy/manipulation/join.py | 2 +- cupy/manipulation/rearrange.py | 2 +- cupy/math/sumprod.py | 4 ++-- tests/cupy_tests/core_tests/test_ndarray.py | 2 +- tests/cupy_tests/manipulation_tests/test_dims.py | 8 ++++---- tests/cupy_tests/manipulation_tests/test_join.py | 2 +- tests/cupy_tests/manipulation_tests/test_rearrange.py | 4 ++-- tests/cupy_tests/math_tests/test_sumprod.py | 8 ++++---- 9 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cupy/core/__init__.py b/cupy/core/__init__.py index dfddabc943b..7fc262f748b 100644 --- a/cupy/core/__init__.py +++ b/cupy/core/__init__.py @@ -3,7 +3,6 @@ # import class and function -from cupy.core.core import _AxisError # NOQA from cupy.core.core import absolute # NOQA from cupy.core.core import add # NOQA from cupy.core.core import array # NOQA diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py index ac1b0784253..3ac496ef935 100644 --- a/cupy/manipulation/join.py +++ b/cupy/manipulation/join.py @@ -128,6 +128,6 @@ def _get_positive_axis(ndim, axis): if a < 0: a += ndim if a < 0 or a >= ndim: - raise core._AxisError( + raise core.core._AxisError( 'axis {} out of bounds [0, {})'.format(axis, ndim)) return a diff --git a/cupy/manipulation/rearrange.py b/cupy/manipulation/rearrange.py index 9d11a162a5f..c2434b612f8 100644 --- a/cupy/manipulation/rearrange.py +++ b/cupy/manipulation/rearrange.py @@ -101,7 +101,7 @@ def roll(a, shift, axis=None): if axis < 0: axis += a.ndim if not 0 <= axis < a.ndim: - raise core._AxisError( + raise core.core._AxisError( 'axis must be >= %d and < %d' % (-a.ndim, a.ndim)) size = a.shape[axis] if size == 0: diff --git a/cupy/math/sumprod.py b/cupy/math/sumprod.py index 7e0824fef67..b412dcf991d 100644 --- a/cupy/math/sumprod.py +++ b/cupy/math/sumprod.py @@ -125,7 +125,7 @@ def cumsum(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise core._AxisError('axis(={}) out of bounds'.format(axis)) + raise core.core._AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumsum_batch, out, axis=axis) @@ -203,7 +203,7 @@ def cumprod(a, axis=None, dtype=None, out=None): if axis is None: out = out.ravel() elif not (-a.ndim <= axis < a.ndim): - raise core._AxisError('axis(={}) out of bounds'.format(axis)) + raise core.core._AxisError('axis(={}) out of bounds'.format(axis)) else: return _proc_as_batch(_cumprod_batch, out, axis=axis) diff --git a/tests/cupy_tests/core_tests/test_ndarray.py b/tests/cupy_tests/core_tests/test_ndarray.py index dd694f7639e..d1fc1564e83 100644 --- a/tests/cupy_tests/core_tests/test_ndarray.py +++ b/tests/cupy_tests/core_tests/test_ndarray.py @@ -227,7 +227,7 @@ def test_axis_overrun1(self, xp, dtype): @testing.for_all_dtypes() def test_axis_overrun2(self, dtype): a = testing.shaped_arange(self.shape, cupy, dtype) - with self.assertRaises(core._AxisError): + with self.assertRaises(core.core._AxisError): wrap_take(a, self.indices, axis=self.axis) diff --git a/tests/cupy_tests/manipulation_tests/test_dims.py b/tests/cupy_tests/manipulation_tests/test_dims.py index 12e43029fed..d365bb265f1 100644 --- a/tests/cupy_tests/manipulation_tests/test_dims.py +++ b/tests/cupy_tests/manipulation_tests/test_dims.py @@ -169,7 +169,7 @@ def test_squeze_int_axis_failure1(self, xp): def test_squeze_int_axis_failure2(self): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): a.squeeze(axis=-9) @testing.numpy_cupy_array_equal() @@ -205,7 +205,7 @@ def test_squeze_tuple_axis_failure2(self, xp): def test_squeze_tuple_axis_failure3(self): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), cupy) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): a.squeeze(axis=(-9,)) @testing.numpy_cupy_array_equal() @@ -232,12 +232,12 @@ def test_squeeze_scalar_failure2(self, xp): def test_squeeze_scalar_failure3(self): a = testing.shaped_arange((), cupy) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): a.squeeze(axis=-2) def test_squeeze_scalar_failure4(self): a = testing.shaped_arange((), cupy) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): a.squeeze(axis=1) @testing.numpy_cupy_raises() diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py index a33835fde5a..2b483cfab29 100644 --- a/tests/cupy_tests/manipulation_tests/test_join.py +++ b/tests/cupy_tests/manipulation_tests/test_join.py @@ -214,5 +214,5 @@ def test_stack_out_of_bounds1(self, xp): def test_stack_out_of_bounds2(self): a = testing.shaped_arange((2, 3), cupy) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.stack([a, a], axis=3) diff --git a/tests/cupy_tests/manipulation_tests/test_rearrange.py b/tests/cupy_tests/manipulation_tests/test_rearrange.py index 11044f0e2ee..657c2383048 100644 --- a/tests/cupy_tests/manipulation_tests/test_rearrange.py +++ b/tests/cupy_tests/manipulation_tests/test_rearrange.py @@ -67,7 +67,7 @@ def test_roll_invalid_axis1(self, xp, dtype): @testing.for_all_dtypes() def test_roll_invalid_axis2(self, dtype): x = testing.shaped_arange((5, 2), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.roll(x, 1, axis=2) @testing.for_all_dtypes() @@ -80,7 +80,7 @@ def test_roll_invalid_negative_axis1(self, xp, dtype): @testing.for_all_dtypes() def test_roll_invalid_negative_axis2(self, dtype): x = testing.shaped_arange((5, 2), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.roll(x, 1, axis=-3) diff --git a/tests/cupy_tests/math_tests/test_sumprod.py b/tests/cupy_tests/math_tests/test_sumprod.py index 83602e2055c..3eec6a669f6 100644 --- a/tests/cupy_tests/math_tests/test_sumprod.py +++ b/tests/cupy_tests/math_tests/test_sumprod.py @@ -197,7 +197,7 @@ def test_invalid_axis_lower1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_lower2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.cumsum(a, axis=-a.ndim - 1) @testing.for_all_dtypes() @@ -210,7 +210,7 @@ def test_invalid_axis_upper1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_upper2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.cumsum(a, axis=a.ndim + 1) @@ -253,7 +253,7 @@ def test_invalid_axis_lower1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_lower2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.cumprod(a, axis=-a.ndim - 1) @testing.for_all_dtypes() @@ -266,5 +266,5 @@ def test_invalid_axis_upper1(self, xp, dtype): @testing.for_all_dtypes() def test_invalid_axis_upper2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) - with self.assertRaises(cupy.core._AxisError): + with self.assertRaises(cupy.core.core._AxisError): return cupy.cumprod(a, axis=a.ndim)