diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index d4754ff151c0..c1b6d797875c 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -529,7 +529,7 @@ jobs: env: DPNP_TEST_ALL_INT_TYPES: 1 run: | - pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests upload: name: Upload ['${{ matrix.os }}', python='${{ matrix.python }}'] diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 6cb603fb4804..71cd1ba5a18a 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -590,12 +590,13 @@ def __init__( def __call__(self, x, decimals=0, out=None, dtype=None): if decimals != 0: x_usm = dpnp.get_usm_ndarray(x) - if dpnp.issubdtype(x_usm.dtype, dpnp.integer) and dtype is None: - dtype = x_usm.dtype - out_usm = None if out is None else dpnp.get_usm_ndarray(out) - x_usm = dpt.round(x_usm * 10**decimals, out=out_usm) - res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm) + + if dpnp.issubdtype(x_usm.dtype, dpnp.integer): + res_usm = dpt.round(x_usm, out=out_usm) + else: + x_usm = dpt.round(x_usm * 10**decimals, out=out_usm) + res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm) if dtype is not None: res_usm = dpt.astype(res_usm, dtype, copy=False) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 401b7c67a7f4..e53b3bf92438 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -1469,7 +1469,20 @@ def copyto(dst, src, casting="same_kind", where=True): f"but got {type(dst)}" ) if not dpnp.is_supported_array_type(src): + no_dtype_attr = not hasattr(src, "dtype") src = dpnp.array(src, sycl_queue=dst.sycl_queue) + if no_dtype_attr: + # This case (scalar, list, etc) needs special handling to + # behave similar to NumPy + if dpnp.issubdtype(src, dpnp.integer) and dpnp.issubdtype( + dst, dpnp.unsignedinteger + ): + if dpnp.any(src < 0): + raise OverflowError( + "Cannot copy negative values to an unsigned int array" + ) + + src = src.astype(dst.dtype) if not dpnp.can_cast(src.dtype, dst.dtype, casting=casting): raise TypeError( diff --git a/dpnp/tests/test_sycl_queue.py b/dpnp/tests/test_sycl_queue.py index 9da87c3db865..ba584504d4d3 100644 --- a/dpnp/tests/test_sycl_queue.py +++ b/dpnp/tests/test_sycl_queue.py @@ -810,6 +810,7 @@ def test_reduce_hypot(device): [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0], ), + pytest.param("round", [1.234, 2.567], 2), pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]), pytest.param( "subtract", diff --git a/dpnp/tests/test_usm_type.py b/dpnp/tests/test_usm_type.py index e8e97d2ea385..5231c136cdf9 100644 --- a/dpnp/tests/test_usm_type.py +++ b/dpnp/tests/test_usm_type.py @@ -740,6 +740,7 @@ def test_1in_1out(func, data, usm_type): pytest.param("maximum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]), pytest.param("minimum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]), pytest.param("nextafter", [1, 2], [2, 1]), + pytest.param("round", [1.234, 2.567], 2), pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]), pytest.param( "tensordot", diff --git a/dpnp/tests/third_party/cupy/core_tests/test_elementwise.py b/dpnp/tests/third_party/cupy/core_tests/test_elementwise.py index 2d268e53b37b..729468948209 100644 --- a/dpnp/tests/third_party/cupy/core_tests/test_elementwise.py +++ b/dpnp/tests/third_party/cupy/core_tests/test_elementwise.py @@ -4,7 +4,11 @@ import pytest import dpnp as cupy -from dpnp.tests.helper import has_support_aspect64 +from dpnp.tests.helper import ( + has_support_aspect64, + is_win_platform, + numpy_version, +) from dpnp.tests.third_party.cupy import testing @@ -94,20 +98,22 @@ class TestElementwiseType(unittest.TestCase): @testing.for_int_dtypes(no_bool=True) @testing.numpy_cupy_array_equal(accept_error=OverflowError) def test_large_int_upper_1(self, xp, dtype): - a = xp.array([0], dtype=numpy.int8) + a = xp.array([0], dtype=xp.int8) b = xp.iinfo(dtype).max return a + b @testing.for_int_dtypes(no_bool=True) @testing.numpy_cupy_array_equal(accept_error=OverflowError) def test_large_int_upper_2(self, xp, dtype): - if ( - numpy.issubdtype(dtype, numpy.unsignedinteger) - and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0" - ): - pytest.skip("numpy promotes dtype differently") + if numpy_version() < "2.0.0": + flag = dtype in [xp.int16, xp.int32, xp.int64, xp.longlong] + if xp.issubdtype(dtype, xp.unsignedinteger) or flag: + pytest.skip("numpy doesn't raise OverflowError") + + if dtype in [xp.int8, xp.intc] and is_win_platform(): + pytest.skip("numpy promotes dtype differently") - a = xp.array([1], dtype=numpy.int8) + a = xp.array([1], dtype=xp.int8) b = xp.iinfo(dtype).max - 1 return a + b @@ -116,7 +122,7 @@ def test_large_int_upper_2(self, xp, dtype): def test_large_int_upper_3(self, xp, dtype): if ( numpy.issubdtype(dtype, numpy.unsignedinteger) - and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0" + and numpy_version() < "2.0.0" ): pytest.skip("numpy promotes dtype differently") elif ( @@ -134,7 +140,7 @@ def test_large_int_upper_3(self, xp, dtype): def test_large_int_upper_4(self, xp, dtype): if ( numpy.issubdtype(dtype, numpy.unsignedinteger) - and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0" + and numpy_version() < "2.0.0" ): pytest.skip("numpy promotes dtype differently") elif ( @@ -150,14 +156,28 @@ def test_large_int_upper_4(self, xp, dtype): @testing.for_int_dtypes(no_bool=True) @testing.numpy_cupy_array_equal(accept_error=OverflowError) def test_large_int_lower_1(self, xp, dtype): - a = xp.array([0], dtype=numpy.int8) + if numpy_version() < "2.0.0": + if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]: + pytest.skip("numpy doesn't raise OverflowError") + + if dtype in [xp.int8, xp.intc] and is_win_platform(): + pytest.skip("numpy promotes dtype differently") + + a = xp.array([0], dtype=xp.int8) b = xp.iinfo(dtype).min return a + b @testing.for_int_dtypes(no_bool=True) @testing.numpy_cupy_array_equal(accept_error=OverflowError) def test_large_int_lower_2(self, xp, dtype): - a = xp.array([-1], dtype=numpy.int8) + if numpy_version() < "2.0.0": + if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]: + pytest.skip("numpy doesn't raise OverflowError") + + if dtype in [xp.int8, xp.intc] and is_win_platform(): + pytest.skip("numpy promotes dtype differently") + + a = xp.array([-1], dtype=xp.int8) b = xp.iinfo(dtype).min + 1 return a + b @@ -166,7 +186,7 @@ def test_large_int_lower_2(self, xp, dtype): def test_large_int_lower_3(self, xp, dtype): if ( numpy.issubdtype(dtype, numpy.unsignedinteger) - and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0" + and numpy_version() < "2.0.0" ): pytest.skip("numpy promotes dtype differently") elif ( diff --git a/dpnp/tests/third_party/cupy/core_tests/test_ndarray_complex_ops.py b/dpnp/tests/third_party/cupy/core_tests/test_ndarray_complex_ops.py index 282c38b72e66..3acebaaeb3ad 100644 --- a/dpnp/tests/third_party/cupy/core_tests/test_ndarray_complex_ops.py +++ b/dpnp/tests/third_party/cupy/core_tests/test_ndarray_complex_ops.py @@ -4,7 +4,6 @@ import pytest import dpnp as cupy -from dpnp.tests.helper import has_support_aspect64 from dpnp.tests.third_party.cupy import testing @@ -41,8 +40,10 @@ def test_conjugate_pass(self, xp, dtype): class TestAngle(unittest.TestCase): + # For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32 + # so type_check=False @testing.for_all_dtypes() - @testing.numpy_cupy_array_almost_equal(type_check=has_support_aspect64()) + @testing.numpy_cupy_array_almost_equal(type_check=False) def test_angle(self, xp, dtype): x = testing.shaped_arange((2, 3), xp, dtype) return xp.angle(x) diff --git a/dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py b/dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py index 515243d89c5c..eaf01d1b345c 100644 --- a/dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py +++ b/dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py @@ -338,7 +338,7 @@ def test_astype_type(self, src_dtype, dst_dtype, order): b = astype_without_warning(a, dst_dtype, order=order) a_cpu = testing.shaped_arange((2, 3, 4), numpy, src_dtype) b_cpu = astype_without_warning(a_cpu, dst_dtype, order=order) - assert b.dtype.type == b_cpu.dtype.type + assert b.dtype == b_cpu.dtype @testing.for_orders("CAK") @testing.for_all_dtypes() diff --git a/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py b/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py index b0d209e2570d..06b4ef8dc75a 100644 --- a/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py +++ b/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py @@ -227,7 +227,13 @@ def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out): # TODO (ev-br): np 2.0: had to bump the default rtol on Windows # and numpy 1.26+weak promotion from 0 to 5e-6 if xp.dtype(dtype_range).kind in "u": - start = xp.array([160, 120], dtype=dtype_range) + # to avoid overflow, limit `val` to be smaller + # than xp.iinfo(dtype).max + if dtype_range == xp.uint8 or dtype_out == xp.uint8: + val = 125 + else: + val = 160 + start = xp.array([val, 120], dtype=dtype_range) else: start = xp.array([-120, 120], dtype=dtype_range) stop = 0 diff --git a/dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py b/dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py index a977b44bbdbd..213edf0b2c0e 100644 --- a/dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py +++ b/dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py @@ -204,6 +204,10 @@ class TestChoose(unittest.TestCase): @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_choose(self, xp, dtype): + # TODO: include additional dtype when dpnp#2201 is merged + dtype_list = [xp.int8, xp.int16] + if dtype in dtype_list or xp.issubdtype(dtype, xp.unsignedinteger): + pytest.skip("dpnp.choose() does not support new integer dtypes.") a = xp.array([0, 2, 1, 2]) c = testing.shaped_arange((3, 4), xp, dtype) return a.choose(c) diff --git a/dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py b/dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py index 0714fbc05a72..bb44b791d413 100644 --- a/dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py +++ b/dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py @@ -464,9 +464,8 @@ def test_scalar_float(self, xp, dtype): ) ) class TestEinSumBinaryOperation: - @testing.for_all_dtypes_combination( - ["dtype_a", "dtype_b"], no_bool=False, no_float16=False - ) + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes_combination(["dtype_a", "dtype_b"], no_int8=True) @testing.numpy_cupy_allclose( type_check=has_support_aspect64(), contiguous_check=False ) @@ -555,13 +554,18 @@ def test_scalar_2(self, xp, dtype): ) ) class TestEinSumTernaryOperation: - @testing.for_all_dtypes_combination( - ["dtype_a", "dtype_b", "dtype_c"], no_bool=False, no_float16=False - ) + + @testing.for_all_dtypes_combination(["dtype_a", "dtype_b", "dtype_c"]) @testing.numpy_cupy_allclose( type_check=has_support_aspect64(), contiguous_check=False ) def test_einsum_ternary(self, xp, dtype_a, dtype_b, dtype_c): + flag = all( + dtype in [xp.int8, xp.uint8] + for dtype in [dtype_a, dtype_b, dtype_c] + ) + if self.subscripts == "ij,jk,kl" and flag: + pytest.skip("avoid overflow") a = testing.shaped_arange(self.shape_a, xp, dtype_a) b = testing.shaped_arange(self.shape_b, xp, dtype_b) c = testing.shaped_arange(self.shape_c, xp, dtype_c) diff --git a/dpnp/tests/third_party/cupy/linalg_tests/test_product.py b/dpnp/tests/third_party/cupy/linalg_tests/test_product.py index a712c1cb0328..2617e100a9c2 100644 --- a/dpnp/tests/third_party/cupy/linalg_tests/test_product.py +++ b/dpnp/tests/third_party/cupy/linalg_tests/test_product.py @@ -39,8 +39,9 @@ ) ) class TestDot(unittest.TestCase): - - @testing.for_all_dtypes_combination(["dtype_a", "dtype_b"]) + # no_int8=True is added to avoid overflow for shape=((2, 3, 4), (3, 4, 2)) + # and ((2, 3), (3, 4)) cases on cpu + @testing.for_all_dtypes_combination(["dtype_a", "dtype_b"], no_int8=True) @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_dot(self, xp, dtype_a, dtype_b): shape_a, shape_b = self.shape @@ -238,14 +239,14 @@ def test_dot_vec3(self, xp, dtype): b = testing.shaped_arange((2,), xp, dtype) return xp.dot(a, b) - @testing.for_all_dtypes() + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_transposed_dot(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) b = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(0, 2, 1) return xp.dot(a, b) - @testing.for_all_dtypes() + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_transposed_dot_with_out(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) @@ -320,14 +321,16 @@ def test_reversed_inner(self, xp, dtype): b = testing.shaped_reverse_arange((5,), xp, dtype)[::-1] return xp.inner(a, b) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_multidim_inner(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_arange((3, 2, 4), xp, dtype) return xp.inner(a, b) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_transposed_higher_order_inner(self, xp, dtype): a = testing.shaped_arange((2, 4, 3), xp, dtype).transpose(2, 0, 1) @@ -355,14 +358,16 @@ def test_multidim_outer(self, xp, dtype): b = testing.shaped_arange((4, 5), xp, dtype) return xp.outer(a, b) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_tensordot(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_arange((3, 4, 5), xp, dtype) return xp.tensordot(a, b) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_transposed_tensordot(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) @@ -516,13 +521,15 @@ def test_matrix_power_1(self, xp, dtype): a = testing.shaped_arange((3, 3), xp, dtype) return xp.linalg.matrix_power(a, 1) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_matrix_power_2(self, xp, dtype): a = testing.shaped_arange((3, 3), xp, dtype) return xp.linalg.matrix_power(a, 2) - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose() def test_matrix_power_3(self, xp, dtype): a = testing.shaped_arange((3, 3), xp, dtype) diff --git a/dpnp/tests/third_party/cupy/logic_tests/test_comparison.py b/dpnp/tests/third_party/cupy/logic_tests/test_comparison.py index 7e56ed5b64bf..5215191987b4 100644 --- a/dpnp/tests/third_party/cupy/logic_tests/test_comparison.py +++ b/dpnp/tests/third_party/cupy/logic_tests/test_comparison.py @@ -242,7 +242,8 @@ def test_allclose_array_scalar(self, xp, dtype): class TestIsclose(unittest.TestCase): - @testing.for_all_dtypes(no_complex=True) + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_complex=True, no_int8=True) @testing.numpy_cupy_array_equal() def test_is_close_finite(self, xp, dtype): # In numpy<1.10 this test fails when dtype is bool diff --git a/dpnp/tests/third_party/cupy/math_tests/test_matmul.py b/dpnp/tests/third_party/cupy/math_tests/test_matmul.py index 35852d25dbe7..fd15ba33110a 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_matmul.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_matmul.py @@ -60,8 +60,9 @@ ) class TestMatmul(unittest.TestCase): - @testing.for_all_dtypes(name="dtype1") - @testing.for_all_dtypes(name="dtype2") + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(name="dtype1", no_int8=True) + @testing.for_all_dtypes(name="dtype2", no_int8=True) @testing.numpy_cupy_allclose( rtol=1e-3, atol=1e-3, type_check=has_support_aspect64() ) # required for uint8 @@ -70,8 +71,9 @@ def test_operator_matmul(self, xp, dtype1, dtype2): x2 = testing.shaped_arange(self.shape_pair[1], xp, dtype2) return operator.matmul(x1, x2) - @testing.for_all_dtypes(name="dtype1") - @testing.for_all_dtypes(name="dtype2") + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(name="dtype1", no_int8=True) + @testing.for_all_dtypes(name="dtype2", no_int8=True) @testing.numpy_cupy_allclose( rtol=1e-3, atol=1e-3, type_check=has_support_aspect64() ) # required for uint8 @@ -97,8 +99,9 @@ def test_cupy_matmul(self, xp, dtype1, dtype2): ) class TestMatmulOut(unittest.TestCase): - @testing.for_all_dtypes(name="dtype1") - @testing.for_all_dtypes(name="dtype2") + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(name="dtype1", no_int8=True) + @testing.for_all_dtypes(name="dtype2", no_int8=True) @testing.numpy_cupy_allclose( rtol=1e-3, atol=1e-3, accept_error=TypeError # required for uint8 ) @@ -140,7 +143,8 @@ def test_overlap_both(self, xp, dtype, shape): class TestMatmulStrides: - @testing.for_all_dtypes() + # no_int8=True is added to avoid overflow + @testing.for_all_dtypes(no_int8=True) @testing.numpy_cupy_allclose(rtol=1e-3, atol=1e-3) # required for uint8 def test_relaxed_c_contiguous_input(self, xp, dtype): x1 = testing.shaped_arange((2, 2, 3), xp, dtype)[:, None, :, :] @@ -171,6 +175,7 @@ class TestMatmulLarge(unittest.TestCase): # Avoid overflow skip_dtypes = { + (numpy.int8, numpy.int8), (numpy.int8, numpy.uint8), (numpy.int8, numpy.int16), (numpy.int8, numpy.float16), diff --git a/dpnp/tests/third_party/cupy/math_tests/test_misc.py b/dpnp/tests/third_party/cupy/math_tests/test_misc.py index c2d7d5ed0c86..2664e2496000 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_misc.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_misc.py @@ -176,7 +176,8 @@ def test_sqrt(self): self.check_unary("sqrt") @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) + # atol=1e-3 is needed for int8 + @testing.numpy_cupy_allclose(atol=1e-3, type_check=has_support_aspect64()) def test_cbrt(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.cbrt(a) diff --git a/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py b/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py index e0d4f484082d..3579ddb7fe37 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py @@ -7,7 +7,9 @@ class TestTrigonometric(unittest.TestCase): @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) + @testing.numpy_cupy_allclose( + atol=1e-4, rtol=0.001, type_check=has_support_aspect64() + ) def check_unary(self, name, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return getattr(xp, name)(a) diff --git a/dpnp/tests/third_party/cupy/random_tests/test_permutations.py b/dpnp/tests/third_party/cupy/random_tests/test_permutations.py index eed47320e51b..f580ffcca4d7 100644 --- a/dpnp/tests/third_party/cupy/random_tests/test_permutations.py +++ b/dpnp/tests/third_party/cupy/random_tests/test_permutations.py @@ -38,6 +38,11 @@ def test_permutation_zero_dim(self): @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) def test_permutation_sort_1dim(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.permutation() does not support new integer dtypes." + ) cupy_random = self._xp_random(cupy) a = cupy.arange(10, dtype=dtype) b = cupy.copy(a) @@ -47,6 +52,11 @@ def test_permutation_sort_1dim(self, dtype): @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) def test_permutation_sort_ndim(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.permutation() does not support new integer dtypes." + ) cupy_random = self._xp_random(cupy) a = cupy.arange(15, dtype=dtype).reshape(5, 3) b = cupy.copy(a) @@ -58,6 +68,11 @@ def test_permutation_sort_ndim(self, dtype): @testing.for_all_dtypes() def test_permutation_seed1(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.permutation() does not support new integer dtypes." + ) a = testing.shaped_random((10,), cupy, dtype) b = cupy.copy(a) @@ -89,6 +104,11 @@ def test_shuffle_zero_dim(self): @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) def test_shuffle_sort_1dim(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.shuffle() does not support new integer dtypes." + ) a = cupy.arange(10, dtype=dtype) b = cupy.copy(a) cupy.random.shuffle(a) @@ -96,6 +116,11 @@ def test_shuffle_sort_1dim(self, dtype): @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) def test_shuffle_sort_ndim(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.shuffle() does not support new integer dtypes." + ) a = cupy.arange(15, dtype=dtype).reshape(5, 3) b = cupy.copy(a) cupy.random.shuffle(a) @@ -105,6 +130,11 @@ def test_shuffle_sort_ndim(self, dtype): @testing.for_all_dtypes() def test_shuffle_seed1(self, dtype): + flag = cupy.issubdtype(dtype, cupy.unsignedinteger) + if flag or dtype in [cupy.int8, cupy.int16]: + pytest.skip( + "dpnp.random.shuffle() does not support new integer dtypes." + ) a = testing.shaped_random((10,), cupy, dtype) b = cupy.copy(a) cupy.random.seed(0) diff --git a/dpnp/tests/third_party/cupy/sorting_tests/test_sort.py b/dpnp/tests/third_party/cupy/sorting_tests/test_sort.py index dc619d77f786..7e791f6a7c0e 100644 --- a/dpnp/tests/third_party/cupy/sorting_tests/test_sort.py +++ b/dpnp/tests/third_party/cupy/sorting_tests/test_sort.py @@ -478,6 +478,9 @@ def test_partition_zero_dim(self): @testing.for_all_dtypes() @testing.numpy_cupy_equal() def test_partition_one_dim(self, xp, dtype): + flag = xp.issubdtype(dtype, xp.unsignedinteger) + if flag or dtype in [xp.int8, xp.int16]: + pytest.skip("dpnp.partition() does not support new integer dtypes.") a = testing.shaped_random((self.length,), xp, dtype) kth = 2 x = self.partition(a, kth) diff --git a/dpnp/tests/third_party/cupy/testing/_loops.py b/dpnp/tests/third_party/cupy/testing/_loops.py index 603ec22b1a25..718c3910b64c 100644 --- a/dpnp/tests/third_party/cupy/testing/_loops.py +++ b/dpnp/tests/third_party/cupy/testing/_loops.py @@ -251,7 +251,7 @@ def _make_positive_masks(impl, args, kw, name, sp_name, scipy_name): assert error is None if not isinstance(result, (tuple, list)): result = (result,) - return [cupy.asnumpy(r) >= 0 for r in result] + return [r >= 0 for r in result] def _contains_signed_and_unsigned(kw): @@ -411,8 +411,8 @@ def test_func(*args, **kw): if cupy_r.shape == (): skip = (mask == 0).all() else: - cupy_r = cupy_r[mask].get() - numpy_r = numpy_r[mask] + cupy_r = cupy_r[mask] + numpy_r = numpy_r[mask.asnumpy()] if not skip: check_func(cupy_r, numpy_r) @@ -1082,21 +1082,43 @@ def _get_int_bool_dtypes(): _complex_dtypes = _get_supported_complex_dtypes() _regular_float_dtypes = _get_supported_float_dtypes() -_float_dtypes = _regular_float_dtypes -_signed_dtypes = () -_unsigned_dtypes = tuple(numpy.dtype(i).type for i in "BHILQ") -_int_dtypes = _signed_dtypes + _unsigned_dtypes -_int_bool_dtypes = _int_dtypes +_float_dtypes = _get_float_dtypes() +_signed_dtypes = _get_signed_dtypes() +_unsigned_dtypes = _get_unsigned_dtypes() +_int_dtypes = _get_int_dtypes() +_int_bool_dtypes = _get_int_bool_dtypes() _regular_dtypes = _regular_float_dtypes + _int_bool_dtypes _dtypes = _float_dtypes + _int_bool_dtypes -def _make_all_dtypes(no_float16, no_bool, no_complex): - return (numpy.int64, numpy.int32) + _get_supported_float_dtypes() +def _make_all_dtypes(no_float16, no_bool, no_complex, no_int8): + if no_float16: + dtypes = _regular_float_dtypes + else: + dtypes = _float_dtypes + + if no_bool: + dtypes += _int_dtypes + else: + dtypes += _int_bool_dtypes + + if no_int8: + dtypes = tuple( + filter(lambda dt: dt not in [numpy.int8, numpy.uint8], dtypes) + ) + + if config.complex_types and not no_complex: + dtypes += _complex_dtypes + + return dtypes def for_all_dtypes( - name="dtype", no_float16=False, no_bool=False, no_complex=False + name="dtype", + no_float16=False, + no_bool=False, + no_complex=False, + no_int8=False, ): """Decorator that checks the fixture with all dtypes. @@ -1108,6 +1130,9 @@ def for_all_dtypes( omitted from candidate dtypes. no_complex(bool): If ``True``, ``numpy.complex64`` and ``numpy.complex128`` are omitted from candidate dtypes. + no_int8(bool): If ``True``, ``numpy.int8`` and + ``numpy.uint8`` are omitted from candidate dtypes. + This option is generally used to avoid overflow. dtypes to be tested: ``numpy.complex64`` (optional), ``numpy.complex128`` (optional), @@ -1151,7 +1176,7 @@ def for_all_dtypes( .. seealso:: :func:`cupy.testing.for_dtypes` """ return for_dtypes( - _make_all_dtypes(no_float16, no_bool, no_complex), name=name + _make_all_dtypes(no_float16, no_bool, no_complex, no_int8), name=name ) @@ -1321,6 +1346,7 @@ def for_all_dtypes_combination( no_bool=False, full=None, no_complex=False, + no_int8=False, ): """Decorator that checks the fixture with a product set of all dtypes. @@ -1334,12 +1360,15 @@ def for_all_dtypes_combination( will be tested. Otherwise, the subset of combinations will be tested (see description in :func:`cupy.testing.for_dtypes_combination`). - no_complex(bool): If, True, ``numpy.complex64`` and + no_complex(bool): If, ``True``, ``numpy.complex64`` and ``numpy.complex128`` are omitted from candidate dtypes. + no_int8(bool): If, ``True``, ``numpy.int8`` and + ``numpy.uint8`` are omitted from candidate dtypes. + This option is generally used to avoid overflow. .. seealso:: :func:`cupy.testing.for_dtypes_combination` """ - types = _make_all_dtypes(no_float16, no_bool, no_complex) + types = _make_all_dtypes(no_float16, no_bool, no_complex, no_int8) return for_dtypes_combination(types, names, full)