From 0a1c41443aeb4073933c75cc21ea6dde2e6a3def Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Oct 2022 13:07:09 -0500 Subject: [PATCH 1/4] Raise not-implemented exception on numpy fallback --- dpnp/config.py | 7 ++++++- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dpnp/config.py b/dpnp/config.py index a9a6b6ec7c52..daa1f427b63c 100644 --- a/dpnp/config.py +++ b/dpnp/config.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ***************************************************************************** -# Copyright (c) 2016-2020, Intel Corporation +# Copyright (c) 2016-2022, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -52,3 +52,8 @@ ''' Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions ''' + +__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ = int(os.getenv('__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__', 1)) +''' +Trigger non-implemented exception when DPNP fallbacks on NumPy implementation +''' diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index aac77164b911..4e1fce59a618 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -1,7 +1,7 @@ # cython: language_level=3 # -*- coding: utf-8 -*- # ***************************************************************************** -# Copyright (c) 2016-2020, Intel Corporation +# Copyright (c) 2016-2022, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -114,6 +114,10 @@ def call_origin(function, *args, **kwargs): Call fallback function for unsupported cases """ + if config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__: + raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} " + "isn't currently supported, fallback on NumPy implementation.") + dpnp_inplace = kwargs.pop("dpnp_inplace", False) # print(f"DPNP call_origin(): Fallback called. \n\t function={function}, \n\t args={args}, \n\t kwargs={kwargs}, \n\t dpnp_inplace={dpnp_inplace}") From aa3e191405a3206abc1a01eaf542edca484f22f5 Mon Sep 17 00:00:00 2001 From: Anton <100830759+antonwolfy@users.noreply.github.com> Date: Fri, 21 Oct 2022 12:00:56 +0200 Subject: [PATCH 2/4] Update dpnp/dpnp_utils/dpnp_algo_utils.pyx --- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index 4e1fce59a618..7d009c7fa192 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -116,7 +116,7 @@ def call_origin(function, *args, **kwargs): if config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__: raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} " - "isn't currently supported, fallback on NumPy implementation.") + "isn't currently supported and would fall back on NumPy implementation.") dpnp_inplace = kwargs.pop("dpnp_inplace", False) # print(f"DPNP call_origin(): Fallback called. \n\t function={function}, \n\t args={args}, \n\t kwargs={kwargs}, \n\t dpnp_inplace={dpnp_inplace}") From 001fb2593b19a81ed148a0d56c52a01ee897fb83 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 14 Nov 2022 06:50:38 -0600 Subject: [PATCH 3/4] Pass tests with DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK=0 where it's needed --- dpnp/config.py | 2 +- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 8 ++- dpnp/random/dpnp_iface_random.py | 2 +- dpnp/random/dpnp_random_state.py | 25 ++++++--- tests/conftest.py | 4 ++ tests/test_amin_amax.py | 2 + tests/test_arithmetic.py | 3 ++ tests/test_arraycreation.py | 7 +++ tests/test_arraymanipulation.py | 11 ++++ tests/test_bitwise.py | 6 +++ tests/test_histograms.py | 4 ++ tests/test_indexing.py | 9 ++++ tests/test_linalg.py | 6 +++ tests/test_logic.py | 5 ++ tests/test_manipulation.py | 2 + tests/test_mathematical.py | 52 +++++++++---------- tests/test_random.py | 30 +++++++++++ tests/test_random_state.py | 9 ++++ tests/test_sort.py | 1 + tests/test_statistics.py | 3 ++ tests/test_strides.py | 2 + tests/test_sycl_queue.py | 4 ++ tests/test_umath.py | 1 + .../core_tests/test_ndarray_conversion.py | 1 + .../core_tests/test_ndarray_copy_and_view.py | 2 + .../cupy/core_tests/test_ndarray_math.py | 2 + .../cupy/core_tests/test_ndarray_reduction.py | 2 + .../cupy/creation_tests/test_from_data.py | 1 + .../cupy/creation_tests/test_matrix.py | 8 +++ .../cupy/creation_tests/test_ranges.py | 8 +++ tests/third_party/cupy/fft_tests/test_fft.py | 9 ++++ .../cupy/indexing_tests/test_generate.py | 1 + .../cupy/indexing_tests/test_indexing.py | 8 +++ .../cupy/indexing_tests/test_insert.py | 6 +++ .../cupy/linalg_tests/test_einsum.py | 8 +++ .../cupy/linalg_tests/test_product.py | 13 +++++ .../cupy/logic_tests/test_comparison.py | 4 ++ .../cupy/logic_tests/test_content.py | 4 ++ .../third_party/cupy/logic_tests/test_ops.py | 5 ++ .../cupy/manipulation_tests/test_basic.py | 4 ++ .../cupy/manipulation_tests/test_dims.py | 4 ++ .../cupy/manipulation_tests/test_tiling.py | 4 ++ .../cupy/manipulation_tests/test_transpose.py | 9 ++++ .../cupy/math_tests/test_arithmetic.py | 4 ++ .../cupy/math_tests/test_matmul.py | 3 ++ .../cupy/math_tests/test_rounding.py | 2 + .../cupy/math_tests/test_sumprod.py | 11 ++++ .../cupy/random_tests/test_distributions.py | 25 +++++++++ .../cupy/random_tests/test_sample.py | 8 +++ .../cupy/sorting_tests/test_search.py | 18 +++++++ .../cupy/sorting_tests/test_sort.py | 10 ++++ .../cupy/statistics_tests/test_correlation.py | 6 +++ .../cupy/statistics_tests/test_histogram.py | 1 + .../cupy/statistics_tests/test_meanvar.py | 21 ++++++++ 54 files changed, 372 insertions(+), 38 deletions(-) diff --git a/dpnp/config.py b/dpnp/config.py index 4e3391a1bbf4..58a35f88a6e4 100644 --- a/dpnp/config.py +++ b/dpnp/config.py @@ -48,7 +48,7 @@ Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions ''' -__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ = int(os.getenv('__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__', 1)) +__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ = int(os.getenv('DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK', 1)) ''' Trigger non-implemented exception when DPNP fallbacks on NumPy implementation ''' diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index a642a94b37d2..b73d2a5be652 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -114,9 +114,13 @@ def call_origin(function, *args, **kwargs): Call fallback function for unsupported cases """ - if config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__: + allow_fallback = kwargs.pop("allow_fallback", False) + + if not allow_fallback and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1: raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} " - "isn't currently supported and would fall back on NumPy implementation.") + "isn't currently supported and would fall back on NumPy implementation. " + "Define enviroment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` " + "if the fall back is required to be supported without rasing an exception.") dpnp_inplace = kwargs.pop("dpnp_inplace", False) sycl_queue = kwargs.pop("sycl_queue", None) diff --git a/dpnp/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index c71cad80ae4a..677f2a7e94bc 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -1314,7 +1314,7 @@ def seed(seed=None): dpnp_rng_srand(seed) # always reseed numpy engine also - return call_origin(numpy.random.seed, seed) + return call_origin(numpy.random.seed, seed, allow_fallback=True) def standard_cauchy(size=None): diff --git a/dpnp/random/dpnp_random_state.py b/dpnp/random/dpnp_random_state.py index d23f7886a2ab..87cdf83c4967 100644 --- a/dpnp/random/dpnp_random_state.py +++ b/dpnp/random/dpnp_random_state.py @@ -67,7 +67,7 @@ def __init__(self, seed=None, device=None, sycl_queue=None): self._def_float_type = dpnp.float64 self._random_state = MT19937(self._seed, self._sycl_queue) - self._fallback_random_state = call_origin(numpy.random.RandomState, seed) + self._fallback_random_state = call_origin(numpy.random.RandomState, seed, allow_fallback=True) def get_state(self): @@ -125,12 +125,15 @@ def normal(self, loc=0.0, scale=1.0, size=None, dtype=None, usm_type="device"): else: min_double = numpy.finfo('double').min max_double = numpy.finfo('double').max - if (loc >= max_double or loc <= min_double) and dpnp.isfinite(loc): + + # TODO: switch to dpnp.isfinite() and dpnp.signbit() once functions are available, + # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar + if (loc >= max_double or loc <= min_double) and numpy.isfinite(loc): raise OverflowError(f"Range of loc={loc} exceeds valid bounds") - if (scale >= max_double) and dpnp.isfinite(scale): + if (scale >= max_double) and numpy.isfinite(scale): raise OverflowError(f"Range of scale={scale} exceeds valid bounds") - # # scale = -0.0 is cosidered as negative + # scale = -0.0 is cosidered as negative elif scale < 0 or scale == 0 and numpy.signbit(scale): raise ValueError(f"scale={scale}, but must be non-negative.") @@ -230,9 +233,12 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"): min_int = numpy.iinfo('int32').min max_int = numpy.iinfo('int32').max - if not dpnp.isfinite(low) or low > max_int or low < min_int: + + # TODO: switch to dpnp.isfinite() once function is available, + # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar + if not numpy.isfinite(low) or low > max_int or low < min_int: raise OverflowError(f"Range of low={low} exceeds valid bounds") - elif not dpnp.isfinite(high) or high > max_int or high < min_int: + elif not numpy.isfinite(high) or high > max_int or high < min_int: raise OverflowError(f"Range of high={high} exceeds valid bounds") low = int(low) @@ -400,9 +406,12 @@ def uniform(self, low=0.0, high=1.0, size=None, dtype=None, usm_type="device"): else: min_double = numpy.finfo('double').min max_double = numpy.finfo('double').max - if not dpnp.isfinite(low) or low >= max_double or low <= min_double: + + # TODO: switch to dpnp.isfinite() once function is available, + # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar + if not numpy.isfinite(low) or low >= max_double or low <= min_double: raise OverflowError(f"Range of low={low} exceeds valid bounds") - elif not dpnp.isfinite(high) or high >= max_double or high <= min_double: + elif not numpy.isfinite(high) or high >= max_double or high <= min_double: raise OverflowError(f"Range of high={high} exceeds valid bounds") if low > high: diff --git a/tests/conftest.py b/tests/conftest.py index d9cbbb593e36..78d3180bac08 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -73,3 +73,7 @@ def pytest_collection_modifyitems(config, items): # exact match of the test name with items from excluded_list if test_name == item_tbl_str: item.add_marker(skip_mark) + +@pytest.fixture +def allow_fall_back_on_numpy(monkeypatch): + monkeypatch.setattr(dpnp.config, '__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__', 0) diff --git a/tests/test_amin_amax.py b/tests/test_amin_amax.py index 90c92138e81e..442690cc15d3 100644 --- a/tests/test_amin_amax.py +++ b/tests/test_amin_amax.py @@ -67,6 +67,7 @@ def _get_min_max_input(type, shape): return a.reshape(shape) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -87,6 +88,7 @@ def test_amax(type, shape): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) diff --git a/tests/test_arithmetic.py b/tests/test_arithmetic.py index 6eb635e57730..aacb749ccc83 100644 --- a/tests/test_arithmetic.py +++ b/tests/test_arithmetic.py @@ -1,4 +1,5 @@ import unittest +import pytest from tests.third_party.cupy import testing @@ -21,12 +22,14 @@ def test_modf_part2(self, xp, dtype): return c + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_float_dtypes() @testing.numpy_cupy_allclose() def test_nanprod(self, xp, dtype): a = xp.array([-2.5, -1.5, xp.nan, 10.5, 1.5, xp.nan], dtype=dtype) return xp.nanprod(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_float_dtypes() @testing.numpy_cupy_allclose() def test_nansum(self, xp, dtype): diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index e9f703d783dc..3bb56a48fe5f 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -81,6 +81,7 @@ def test_eye(N, M, k, dtype): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -93,6 +94,7 @@ def test_frombuffer(type): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -109,6 +111,7 @@ def test_fromfile(type): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -124,6 +127,7 @@ def func(x, y): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -136,6 +140,7 @@ def test_fromiter(type): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -148,6 +153,7 @@ def test_fromstring(type): numpy.testing.assert_array_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -183,6 +189,7 @@ def test_identity(n, type): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) diff --git a/tests/test_arraymanipulation.py b/tests/test_arraymanipulation.py index 9b06bf9596d3..c0cd3e6c2b1e 100644 --- a/tests/test_arraymanipulation.py +++ b/tests/test_arraymanipulation.py @@ -4,6 +4,7 @@ import numpy +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=["float64", "float32", "int64", "int32"]) @@ -30,6 +31,7 @@ def test_asfarray2(dtype, data): numpy.testing.assert_array_equal(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestConcatenate: def test_returns_copy(self): a = dpnp.array(numpy.eye(3)) @@ -91,9 +93,11 @@ class TestHstack: def test_non_iterable(self): numpy.testing.assert_raises(TypeError, dpnp.hstack, 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_empty_input(self): numpy.testing.assert_raises(ValueError, dpnp.hstack, ()) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_0D_array(self): b = dpnp.array(2) a = dpnp.array(1) @@ -101,6 +105,7 @@ def test_0D_array(self): desired = dpnp.array([1, 2]) numpy.testing.assert_array_equal(res, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_1D_array(self): a = dpnp.array([1]) b = dpnp.array([2]) @@ -108,6 +113,7 @@ def test_1D_array(self): desired = dpnp.array([1, 2]) numpy.testing.assert_array_equal(res, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_2D_array(self): a = dpnp.array([[1], [2]]) b = dpnp.array([[1], [2]]) @@ -126,9 +132,11 @@ class TestVstack: def test_non_iterable(self): numpy.testing.assert_raises(TypeError, dpnp.vstack, 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_empty_input(self): numpy.testing.assert_raises(ValueError, dpnp.vstack, ()) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_0D_array(self): a = dpnp.array(1) b = dpnp.array(2) @@ -136,6 +144,7 @@ def test_0D_array(self): desired = dpnp.array([[1], [2]]) numpy.testing.assert_array_equal(res, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_1D_array(self): a = dpnp.array([1]) b = dpnp.array([2]) @@ -143,6 +152,7 @@ def test_1D_array(self): desired = dpnp.array([[1], [2]]) numpy.testing.assert_array_equal(res, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_2D_array(self): a = dpnp.array([[1], [2]]) b = dpnp.array([[1], [2]]) @@ -150,6 +160,7 @@ def test_2D_array(self): desired = dpnp.array([[1], [2], [1], [2]]) numpy.testing.assert_array_equal(res, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_2D_array2(self): a = dpnp.array([1, 2]) b = dpnp.array([1, 2]) diff --git a/tests/test_bitwise.py b/tests/test_bitwise.py index 8b21bcd2644a..645ae4556c1c 100644 --- a/tests/test_bitwise.py +++ b/tests/test_bitwise.py @@ -37,20 +37,26 @@ def _test_binary_int(self, name, lhs, rhs, dtype): numpy.testing.assert_array_equal(result, expected) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_bitwise_and(self, lhs, rhs, dtype): self._test_binary_int('bitwise_and', lhs, rhs, dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_bitwise_or(self, lhs, rhs, dtype): self._test_binary_int('bitwise_or', lhs, rhs, dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_bitwise_xor(self, lhs, rhs, dtype): self._test_binary_int('bitwise_xor', lhs, rhs, dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_invert(self, lhs, rhs, dtype): self._test_unary_int('invert', lhs, dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_left_shift(self, lhs, rhs, dtype): self._test_binary_int('left_shift', lhs, rhs, dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_right_shift(self, lhs, rhs, dtype): self._test_binary_int('right_shift', lhs, rhs, dtype) diff --git a/tests/test_histograms.py b/tests/test_histograms.py index 825a407d47d3..b95b1712408e 100644 --- a/tests/test_histograms.py +++ b/tests/test_histograms.py @@ -13,6 +13,7 @@ def setup(self): def teardown(self): pass + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_simple(self): n = 100 v = dpnp.random.rand(n) @@ -24,6 +25,7 @@ def test_simple(self): (a, b) = dpnp.histogram(numpy.linspace(0, 10, 100)) numpy.testing.assert_array_equal(a, 10) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_one_bin(self): # Ticket 632 hist, edges = dpnp.histogram([1, 2, 3, 4], [1, 2]) @@ -66,6 +68,8 @@ def test_density(self): [1, 2, 3, 4], [0.5, 1.5, numpy.inf], density=True) numpy.testing.assert_equal(counts, [.25, 0]) + + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_arr_weights_mismatch(self): a = dpnp.arange(10) + .5 w = dpnp.arange(11) + .5 diff --git a/tests/test_indexing.py b/tests/test_indexing.py index 6519576171d0..091cf1345c4e 100644 --- a/tests/test_indexing.py +++ b/tests/test_indexing.py @@ -5,6 +5,7 @@ import numpy +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_choose(): a = numpy.r_[:4] ia = dpnp.array(a) @@ -109,6 +110,7 @@ def test_nonzero(array): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("vals", [[100, 200], (100, 200)], @@ -138,6 +140,7 @@ def test_place1(arr, mask, vals): numpy.testing.assert_array_equal(a, ia) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("vals", [[100, 200], [100, 200, 300, 400, 500, 600], @@ -161,6 +164,7 @@ def test_place2(arr, mask, vals): numpy.testing.assert_array_equal(a, ia) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("vals", [[100, 200], [100, 200, 300, 400, 500, 600], @@ -243,6 +247,7 @@ def test_put3(): numpy.testing.assert_array_equal(a, ia) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_put_along_axis_val_int(): a = numpy.arange(16).reshape(4, 4) ai = dpnp.array(a) @@ -254,6 +259,7 @@ def test_put_along_axis_val_int(): numpy.testing.assert_array_equal(a, ai) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_put_along_axis1(): a = numpy.arange(64).reshape(4, 4, 4) ai = dpnp.array(a) @@ -265,6 +271,7 @@ def test_put_along_axis1(): numpy.testing.assert_array_equal(a, ai) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_put_along_axis2(): a = numpy.arange(64).reshape(4, 4, 4) ai = dpnp.array(a) @@ -411,6 +418,7 @@ def test_take(array, indices, array_type, indices_type): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_take_along_axis(): a = numpy.arange(16).reshape(4, 4) ai = dpnp.array(a) @@ -422,6 +430,7 @@ def test_take_along_axis(): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_take_along_axis1(): a = numpy.arange(64).reshape(4, 4, 4) ai = dpnp.array(a) diff --git a/tests/test_linalg.py b/tests/test_linalg.py index b9535a7b274f..dd89a18adbd6 100644 --- a/tests/test_linalg.py +++ b/tests/test_linalg.py @@ -85,6 +85,7 @@ def test_det(array): numpy.testing.assert_allclose(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -179,6 +180,7 @@ def test_matrix_rank(type, tol, array): numpy.testing.assert_allclose(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[7], [1, 2], [1, 0]], ids=['[7]', '[1, 2]', '[1, 0]']) @@ -196,6 +198,7 @@ def test_norm1(array, ord, axis): numpy.testing.assert_allclose(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[[1, 0]], [[1, 2]], [[1, 0], [3, 0]], [[1, 2], [3, 4]]], ids=['[[1, 0]]', '[[1, 2]]', '[[1, 0], [3, 0]]', '[[1, 2], [3, 4]]']) @@ -213,6 +216,7 @@ def test_norm2(array, ord, axis): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[1, 0], [3, 0]], [[5, 0], [7, 0]]]], ids=['[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]', '[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]']) @@ -230,6 +234,7 @@ def test_norm3(array, ord, axis): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) @@ -273,6 +278,7 @@ def test_qr(type, shape, mode): numpy.testing.assert_allclose(dpnp_r, np_r, rtol=tol, atol=tol) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['float64', 'float32', 'int64', 'int32']) diff --git a/tests/test_logic.py b/tests/test_logic.py index b826740b9bd9..b3280be07618 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -95,6 +95,7 @@ def test_any(type, shape): numpy.testing.assert_allclose(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_greater(): a = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) ia = dpnp.array(a) @@ -104,6 +105,7 @@ def test_greater(): numpy.testing.assert_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_greater_equal(): a = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) ia = dpnp.array(a) @@ -113,6 +115,7 @@ def test_greater_equal(): numpy.testing.assert_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_less(): a = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) ia = dpnp.array(a) @@ -122,6 +125,7 @@ def test_less(): numpy.testing.assert_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_less_equal(): a = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) ia = dpnp.array(a) @@ -131,6 +135,7 @@ def test_less_equal(): numpy.testing.assert_equal(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_not_equal(): a = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) ia = dpnp.array(a) diff --git a/tests/test_manipulation.py b/tests/test_manipulation.py index 8130fcdb4e86..bb91f5d0d500 100644 --- a/tests/test_manipulation.py +++ b/tests/test_manipulation.py @@ -23,6 +23,7 @@ def test_copyto_dtype(in_obj, out_dtype): numpy.testing.assert_array_equal(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("arr", [[], [1, 2, 3, 4], [[1, 2], [3, 4]], [[[1], [2]], [[3], [4]]]], ids=['[]', '[1, 2, 3, 4]', '[[1, 2], [3, 4]]', '[[[1], [2]], [[3], [4]]]']) @@ -34,6 +35,7 @@ def test_repeat(arr): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[1, 2, 3], [1, 2, 2, 1, 2, 4], diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 21040478ca8d..63d63f131994 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -5,6 +5,7 @@ import numpy +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestConvolve: def test_object(self): d = [1.] * 100 @@ -33,6 +34,7 @@ def test_mode(self): dpnp.convolve(d, k, mode=None) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[[0, 0], [0, 0]], [[1, 2], [1, 2]], @@ -54,6 +56,7 @@ def test_diff(array): numpy.testing.assert_allclose(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype1", [numpy.bool_, numpy.float64, numpy.float32, numpy.int64, numpy.int32, numpy.complex64, numpy.complex128], ids=['numpy.bool_', 'numpy.float64', 'numpy.float32', 'numpy.int64', 'numpy.int32', 'numpy.complex64', 'numpy.complex128']) @@ -98,46 +101,60 @@ def _test_mathematical(self, name, dtype, lhs, rhs): numpy.testing.assert_allclose(result, expected, atol=1e-4) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_add(self, dtype, lhs, rhs): self._test_mathematical('add', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_arctan2(self, dtype, lhs, rhs): self._test_mathematical('arctan2', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_copysign(self, dtype, lhs, rhs): self._test_mathematical('copysign', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_divide(self, dtype, lhs, rhs): self._test_mathematical('divide', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_fmod(self, dtype, lhs, rhs): self._test_mathematical('fmod', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_floor_divide(self, dtype, lhs, rhs): self._test_mathematical('floor_divide', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_hypot(self, dtype, lhs, rhs): self._test_mathematical('hypot', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_maximum(self, dtype, lhs, rhs): self._test_mathematical('maximum', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_minimum(self, dtype, lhs, rhs): self._test_mathematical('minimum', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_multiply(self, dtype, lhs, rhs): self._test_mathematical('multiply', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_remainder(self, dtype, lhs, rhs): self._test_mathematical('remainder', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_power(self, dtype, lhs, rhs): self._test_mathematical('power', dtype, lhs, rhs) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_subtract(self, dtype, lhs, rhs): self._test_mathematical('subtract', dtype, lhs, rhs) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("val_type", [bool, int, float], ids=['bool', 'int', 'float']) @@ -172,6 +189,7 @@ def test_multiply_scalar(array, val, data_type, val_type): numpy.testing.assert_array_equal(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("shape", [(), (3, 2)], ids=['()', '(3, 2)']) @@ -187,6 +205,7 @@ def test_multiply_scalar2(shape, dtype): numpy.testing.assert_array_equal(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[1, 2, 3, 4, 5], [1, 2, numpy.nan, 4, 5], [[1, 2, numpy.nan], [3, -4, -5]]]) @@ -199,6 +218,7 @@ def test_nancumprod(array): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[1, 2, 3, 4, 5], [1, 2, numpy.nan, 4, 5], [[1, 2, numpy.nan], [3, -4, -5]]]) @@ -226,6 +246,7 @@ def test_negative(data, dtype): numpy.testing.assert_array_equal(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("val_type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=['numpy.float64', 'numpy.float32', 'numpy.int64', 'numpy.int32']) @@ -270,6 +291,8 @@ def test_ediff1d_int(self, array, data_type): expected = numpy.ediff1d(np_a) numpy.testing.assert_array_equal(expected, result) + + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_ediff1d_args(self): np_a = numpy.array([1, 2, 4, 7, 0]) @@ -281,6 +304,7 @@ def test_ediff1d_args(self): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestTrapz: @pytest.mark.parametrize("data_type", [numpy.float64, numpy.float32, numpy.int64, numpy.int32]) @@ -336,6 +360,7 @@ def test_trapz_with_dx_params(self, y_array, dx): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestCross: @pytest.mark.parametrize("axis", [None, 0], @@ -370,32 +395,7 @@ def test_cross_3x3(self, x1, x2, axisa, axisb, axisc, axis): numpy.testing.assert_array_equal(expected, result) -class TestGradient: - - @pytest.mark.parametrize("array", [[2, 3, 6, 8, 4, 9], - [3., 4., 7.5, 9.], - [2, 6, 8, 10]]) - def test_gradient_y1(self, array): - np_y = numpy.array(array) - dpnp_y = dpnp.array(array) - - result = dpnp.gradient(dpnp_y) - expected = numpy.gradient(np_y) - numpy.testing.assert_array_equal(expected, result) - - @pytest.mark.parametrize("array", [[2, 3, 6, 8, 4, 9], - [3., 4., 7.5, 9.], - [2, 6, 8, 10]]) - @pytest.mark.parametrize("dx", [2, 3.5]) - def test_gradient_y1_dx(self, array, dx): - np_y = numpy.array(array) - dpnp_y = dpnp.array(array) - - result = dpnp.gradient(dpnp_y, dx) - expected = numpy.gradient(np_y, dx) - numpy.testing.assert_array_equal(expected, result) - - +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestGradient: @pytest.mark.parametrize("array", [[2, 3, 6, 8, 4, 9], diff --git a/tests/test_random.py b/tests/test_random.py index fa7da686065f..54cb2fa3a4d7 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -75,6 +75,7 @@ def test_input_shape(func): assert shape == res.shape +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("func", [dpnp.random.random, dpnp.random.random_sample, @@ -139,6 +140,7 @@ def test_randn_normal_distribution(): assert math.isclose(mean, expected_mean, abs_tol=0.03) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsBeta(TestDistribution): def test_moments(self): @@ -162,6 +164,7 @@ def test_seed(self): self.check_seed('beta', {'a': a, 'b': b}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsBinomial(TestDistribution): def test_extreme_value(self): @@ -199,6 +202,7 @@ def test_seed(self): self.check_seed('binomial', {'n': n, 'p': p}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsChisquare(TestDistribution): def test_invalid_args(self): @@ -210,6 +214,7 @@ def test_seed(self): self.check_seed('chisquare', {'df': df}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsExponential(TestDistribution): def test_invalid_args(self): @@ -221,6 +226,7 @@ def test_seed(self): self.check_seed('exponential', {'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsF(TestDistribution): def test_moments(self): @@ -248,6 +254,7 @@ def test_seed(self): self.check_seed('f', {'dfnum': dfnum, 'dfden': dfden}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsGamma(TestDistribution): def test_moments(self): @@ -271,6 +278,7 @@ def test_seed(self): self.check_seed('gamma', {'shape': shape}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsGeometric(TestDistribution): def test_extreme_value(self): @@ -294,6 +302,7 @@ def test_seed(self): self.check_seed('geometric', {'p': p}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsGumbel(TestDistribution): def test_extreme_value(self): @@ -323,6 +332,7 @@ def test_seed(self): self.check_seed('gumbel', {'loc': loc, 'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsHypergeometric(TestDistribution): def test_extreme_value(self): @@ -389,6 +399,7 @@ def test_seed(self): {'ngood': ngood, 'nbad': nbad, 'nsample': nsample}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsLaplace(TestDistribution): def test_extreme_value(self): @@ -418,6 +429,7 @@ def test_seed(self): self.check_seed('laplace', {'loc': loc, 'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsLogistic(TestDistribution): def test_moments(self): @@ -440,6 +452,7 @@ def test_seed(self): self.check_seed('logistic', {'loc': loc, 'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsLognormal(TestDistribution): def test_extreme_value(self): @@ -468,6 +481,7 @@ def test_seed(self): self.check_seed('lognormal', {'mean': mean, 'sigma': sigma}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsMultinomial(TestDistribution): def test_extreme_value(self): @@ -514,6 +528,7 @@ def test_seed1(self): self.check_seed('multinomial', {'n': n, 'pvals': pvals}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsMultivariateNormal(TestDistribution): def test_moments(self): @@ -553,6 +568,7 @@ def test_seed(self): self.check_seed('multivariate_normal', {'mean': mean, 'cov': cov}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsNegativeBinomial(TestDistribution): def test_extreme_value(self): @@ -609,6 +625,7 @@ def test_seed(self): self.check_seed('normal', {'loc': loc, 'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsNoncentralChisquare: @pytest.mark.parametrize("df", [5.0, 1.0, 0.5], ids=['df_grt_1', 'df_eq_1', 'df_less_1']) @@ -648,6 +665,7 @@ def test_seed(self, df): assert_allclose(a1, a2, rtol=1e-07, atol=0) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsPareto(TestDistribution): def test_moments(self): @@ -667,6 +685,7 @@ def test_seed(self): self.check_seed('pareto', {'a': a}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsPoisson(TestDistribution): def test_extreme_value(self): @@ -689,6 +708,7 @@ def test_seed(self): self.check_seed('poisson', {'lam': lam}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsPower(TestDistribution): def test_moments(self): @@ -709,6 +729,7 @@ def test_seed(self): self.check_seed('power', {'a': a}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsRayleigh(TestDistribution): def test_extreme_value(self): @@ -750,6 +771,7 @@ def test_seed(self): self.check_seed('standard_exponential', {}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsStandardGamma(TestDistribution): def test_extreme_value(self): @@ -782,6 +804,7 @@ def test_seed(self): self.check_seed('standard_normal', {}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsStandardT(TestDistribution): def test_moments(self): @@ -799,6 +822,7 @@ def test_seed(self): self.check_seed('standard_t', {'df': 10.0}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsTriangular(TestDistribution): def test_moments(self): @@ -851,6 +875,7 @@ def test_seed(self): self.check_seed('uniform', {'low': low, 'high': high}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsVonmises: @pytest.mark.parametrize("kappa", [5.0, 0.5], ids=['large_kappa', 'small_kappa']) @@ -887,6 +912,7 @@ def test_seed(self, kappa): assert_allclose(a1, a2, rtol=1e-07, atol=0) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsWald(TestDistribution): def test_moments(self): @@ -913,6 +939,7 @@ def test_seed(self): self.check_seed('wald', {'mean': mean, 'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsWeibull(TestDistribution): def test_extreme_value(self): @@ -929,6 +956,7 @@ def test_seed(self): self.check_seed('weibull', {'a': a}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestDistributionsZipf(TestDistribution): def test_invalid_args(self): @@ -1018,6 +1046,8 @@ def test_shuffle1(self, conv): desired = conv(dpnp_1d) assert_array_equal(actual, desired) + + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("conv", [lambda x: x, lambda x: [(i, i) for i in x]], ids=['lambda x: x', diff --git a/tests/test_random_state.py b/tests/test_random_state.py index 9d2f14643c84..c92a4680e86e 100644 --- a/tests/test_random_state.py +++ b/tests/test_random_state.py @@ -123,6 +123,7 @@ def test_extreme_bounds(self): "with the following message:\n\n%s" % str(e)) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("scale", [dpnp.array([3]), numpy.array([3])], ids=['dpnp.array([3])', 'numpy.array([3])']) @@ -293,6 +294,7 @@ def test_negative_bounds(self): assert_array_equal(actual, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_negative_interval(self): rs = RandomState(3567) @@ -354,6 +356,7 @@ def test_full_range(self): "with the following message:\n\n%s" % str(e)) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_in_bounds_fuzz(self): for high in [4, 8, 16]: vals = RandomState().randint(2, high, size=2**16) @@ -369,6 +372,7 @@ def test_zero_size(self, zero_size): assert_equal(RandomState().randint(0, 10, size=zero_size).shape, exp_shape) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("high", [dpnp.array([3]), numpy.array([3])], ids=['dpnp.array([3])', 'numpy.array([3])']) @@ -385,6 +389,7 @@ def test_bounds_fallback(self, low, high): assert_equal(actual, desired) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype", [dpnp.int64, dpnp.integer, dpnp.bool, dpnp.bool_, bool], ids=['dpnp.int64', 'dpnp.integer', 'dpnp.bool', 'dpnp.bool_', 'bool']) @@ -495,6 +500,7 @@ def test_scalar(self, func): assert_array_almost_equal(a1, a2, decimal=precision) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("seed", [range(3), numpy.arange(3, dtype=numpy.int32), @@ -527,6 +533,7 @@ def test_invalid_type(self, seed): assert_raises(TypeError, RandomState, seed) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("seed", [-1, [-3, 7], (17, 3, -5), [4, 3, 2, 1], (7, 6, 5, 1), range(-1, -11, -1), @@ -736,6 +743,7 @@ def test_low_high_equal(self, dtype, usm_type): assert_array_almost_equal(actual, desired, decimal=numpy.finfo(dtype=dtype).precision) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_range_bounds(self): fmin = numpy.finfo('double').min fmax = numpy.finfo('double').max @@ -751,6 +759,7 @@ def test_range_bounds(self): func(low=numpy.nextafter(fmin, 0), high=numpy.nextafter(fmax, 0)) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("high", [dpnp.array([3]), numpy.array([3])], ids=['dpnp.array([3])', 'numpy.array([3])']) diff --git a/tests/test_sort.py b/tests/test_sort.py index 205dddafd9c9..aa633c0c3ad9 100644 --- a/tests/test_sort.py +++ b/tests/test_sort.py @@ -32,6 +32,7 @@ def test_partition(array, dtype, kth): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("side", ["left", "right"], ids=['"left"', '"right"']) diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 7973b008392b..04a765a73bce 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -20,6 +20,7 @@ def test_median(type, size): numpy.testing.assert_allclose(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("axis", [0, 1, -1, 2, -2, (1, 2), (0, -2)]) def test_max(axis): @@ -32,6 +33,7 @@ def test_max(axis): numpy.testing.assert_allclose(dpnp_res, np_res) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("array", [[2, 0, 6, 2], [2, 0, 6, 2, 5, 6, 7, 8], @@ -74,6 +76,7 @@ def test_nanvar(array): numpy.testing.assert_array_equal(expected, result) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestBincount: @pytest.mark.parametrize("array", diff --git a/tests/test_strides.py b/tests/test_strides.py index 08f3bbed0ae6..7ec1d6b3f03f 100644 --- a/tests/test_strides.py +++ b/tests/test_strides.py @@ -190,6 +190,7 @@ def test_strides_copysign(dtype, shape): numpy.testing.assert_allclose(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=["float64", "float32", "int64", "int32"]) @@ -209,6 +210,7 @@ def test_strides_fmod(dtype, shape): numpy.testing.assert_allclose(result, expected) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype", [numpy.float64, numpy.float32, numpy.int64, numpy.int32], ids=["float64", "float32", "int64", "int32"]) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index e3e8680e6aca..f5b5fd1a74ba 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -93,6 +93,7 @@ def test_array_creation(func, arg, kwargs, device): assert dpnp_array.sycl_device == device +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize( "func,data", [ @@ -300,6 +301,7 @@ def test_rs_uniform(usm_type, seed): assert_sycl_queue_equal(res_sycl_queue, sycl_queue) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize( "func,data1,data2", [ @@ -460,6 +462,7 @@ def test_det(device): assert_sycl_queue_equal(result_queue, expected_queue) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("device", valid_devices, ids=[device.filter_string for device in valid_devices]) @@ -586,6 +589,7 @@ def test_qr(device): assert_sycl_queue_equal(dpnp_r_queue, expected_queue) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("device", valid_devices, ids=[device.filter_string for device in valid_devices]) diff --git a/tests/test_umath.py b/tests/test_umath.py index 52941ba94cb5..6122b253ca37 100644 --- a/tests/test_umath.py +++ b/tests/test_umath.py @@ -58,6 +58,7 @@ def get_id(val): return val.__str__() +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize('test_cases', test_cases, ids=get_id) def test_umaths(test_cases): umath, args_str = test_cases diff --git a/tests/third_party/cupy/core_tests/test_ndarray_conversion.py b/tests/third_party/cupy/core_tests/test_ndarray_conversion.py index 9dcf1bd0d781..78b1b250db12 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_conversion.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_conversion.py @@ -12,6 +12,7 @@ {'shape': (1,)}, {'shape': (1, 1, 1)}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestNdarrayItem(unittest.TestCase): @testing.for_all_dtypes() diff --git a/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py b/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py index 1a5a87fbae40..b026377e3e2a 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py @@ -159,12 +159,14 @@ def test_astype_strides_broadcast(self, xp, src_dtype, dst_dtype): return numpy.array( astype_without_warning(src, dst_dtype, order='K').strides) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_diagonal1(self, xp, dtype): a = testing.shaped_arange((3, 4, 5), xp, dtype) return a.diagonal(1, 2, 0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_diagonal2(self, xp, dtype): diff --git a/tests/third_party/cupy/core_tests/test_ndarray_math.py b/tests/third_party/cupy/core_tests/test_ndarray_math.py index 36bd6979c6ec..816261517c4c 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_math.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_math.py @@ -1,4 +1,5 @@ import unittest +import pytest import numpy @@ -9,6 +10,7 @@ @testing.parameterize(*testing.product({ 'decimals': [-2, -1, 0, 1, 2], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestRound(unittest.TestCase): shape = (20,) diff --git a/tests/third_party/cupy/core_tests/test_ndarray_reduction.py b/tests/third_party/cupy/core_tests/test_ndarray_reduction.py index 6f5f466062d0..34275e917cf6 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_reduction.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_reduction.py @@ -1,4 +1,5 @@ import unittest +import pytest import numpy @@ -7,6 +8,7 @@ from tests.third_party.cupy import testing +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestArrayReduction(unittest.TestCase): diff --git a/tests/third_party/cupy/creation_tests/test_from_data.py b/tests/third_party/cupy/creation_tests/test_from_data.py index a2fecb8d6418..e07d927b1cf0 100644 --- a/tests/third_party/cupy/creation_tests/test_from_data.py +++ b/tests/third_party/cupy/creation_tests/test_from_data.py @@ -414,6 +414,7 @@ def test_asarray_cuda_array_zero_dim_dtype(self, xp): return xp.ascontiguousarray(a, dtype=numpy.int64) # @testing.for_CF_orders() + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_orders('C') @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() diff --git a/tests/third_party/cupy/creation_tests/test_matrix.py b/tests/third_party/cupy/creation_tests/test_matrix.py index 5b2fb7cc51a6..a5471f213ebf 100644 --- a/tests/third_party/cupy/creation_tests/test_matrix.py +++ b/tests/third_party/cupy/creation_tests/test_matrix.py @@ -60,16 +60,19 @@ def test_diag_construction_from_tuple(self, xp): self.assertIsInstance(r, xp.ndarray) return r + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_diag_scaler(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.diag(1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_diag_0dim(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.diag(xp.zeros(())) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_diag_3dim(self): for xp in (numpy, cupy): with pytest.raises(ValueError): @@ -90,14 +93,17 @@ def test_diagflat3(self, xp): a = testing.shaped_arange((3, 3), xp) return xp.diagflat(a, -2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_diagflat_from_scalar(self, xp): return xp.diagflat(3) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_diagflat_from_scalar_with_k0(self, xp): return xp.diagflat(3, 0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_diagflat_from_scalar_with_k1(self, xp): return xp.diagflat(3, 1) @@ -142,6 +148,7 @@ def test_tril(self, xp, dtype): m = testing.shaped_arange(self.shape, xp, dtype) return xp.tril(m) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_tril_array_like(self, xp): return xp.tril([[1, 2], [3, 4]]) @@ -164,6 +171,7 @@ def test_triu(self, xp, dtype): m = testing.shaped_arange(self.shape, xp, dtype) return xp.triu(m) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_triu_array_like(self, xp): return xp.triu([[1, 2], [3, 4]]) diff --git a/tests/third_party/cupy/creation_tests/test_ranges.py b/tests/third_party/cupy/creation_tests/test_ranges.py index d765858023c2..75960e492c17 100644 --- a/tests/third_party/cupy/creation_tests/test_ranges.py +++ b/tests/third_party/cupy/creation_tests/test_ranges.py @@ -206,11 +206,13 @@ def test_linspace_start_stop_list(self, xp, dtype): stop = [100, 16] return xp.linspace(start, stop, num=50, dtype=dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_allclose() def test_logspace(self, xp, dtype): return xp.logspace(0, 2, 5, dtype=dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_allclose() def test_logspace2(self, xp, dtype): @@ -221,24 +223,29 @@ def test_logspace2(self, xp, dtype): def test_logspace_zero_num(self, xp, dtype): return xp.logspace(0, 2, 0, dtype=dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_allclose() def test_logspace_one_num(self, xp, dtype): return xp.logspace(0, 2, 1, dtype=dtype) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_allclose() def test_logspace_no_endpoint(self, xp, dtype): return xp.logspace(0, 2, 5, dtype=dtype, endpoint=False) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_allclose() def test_logspace_no_dtype_int(self, xp): return xp.logspace(0, 2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_allclose() def test_logspace_no_dtype_float(self, xp): return xp.logspace(0.0, 2.0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_allclose() def test_logspace_float_args_with_int_dtype(self, xp): return xp.logspace(0.1, 2.1, 11, dtype=int) @@ -248,6 +255,7 @@ def test_logspace_neg_num(self): with pytest.raises(ValueError): xp.logspace(0, 10, -1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) @testing.numpy_cupy_allclose() def test_logspace_base(self, xp, dtype): diff --git a/tests/third_party/cupy/fft_tests/test_fft.py b/tests/third_party/cupy/fft_tests/test_fft.py index cf23e4a5e902..e56a52f79399 100644 --- a/tests/third_party/cupy/fft_tests/test_fft.py +++ b/tests/third_party/cupy/fft_tests/test_fft.py @@ -14,6 +14,7 @@ 'shape': [(0,), (10, 0), (10,), (10, 10)], 'norm': [None, 'ortho', ''], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFft(unittest.TestCase): @@ -61,6 +62,7 @@ def test_ifft(self, xp, dtype): {'shape': (3, 4), 's': (0, 5), 'axes': None, 'norm': None}, {'shape': (3, 4), 's': (1, 0), 'axes': None, 'norm': None}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFft2(unittest.TestCase): @@ -109,6 +111,7 @@ def test_ifft2(self, xp, dtype): {'shape': (2, 0, 5), 's': None, 'axes': None, 'norm': None}, {'shape': (0, 0, 5), 's': None, 'axes': None, 'norm': None}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFftn(unittest.TestCase): @@ -136,6 +139,7 @@ def test_ifftn(self, xp, dtype): 'shape': [(10,), (10, 10)], 'norm': [None, 'ortho'], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRfft(unittest.TestCase): @@ -160,6 +164,7 @@ def test_irfft(self, xp, dtype): {'shape': (3, 4), 's': None, 'axes': (), 'norm': None}, {'shape': (2, 3, 4), 's': None, 'axes': (), 'norm': None}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRfft2EmptyAxes(unittest.TestCase): @@ -182,6 +187,7 @@ def test_irfft2(self, dtype): {'shape': (3, 4), 's': None, 'axes': (), 'norm': None}, {'shape': (2, 3, 4), 's': None, 'axes': (), 'norm': None}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRfftnEmptyAxes(unittest.TestCase): @@ -205,6 +211,7 @@ def test_irfftn(self, dtype): 'shape': [(10,), (10, 10)], 'norm': [None, 'ortho'], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestHfft(unittest.TestCase): @@ -230,6 +237,7 @@ def test_ihfft(self, xp, dtype): {'n': 10, 'd': 0.5}, {'n': 100, 'd': 2}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFftfreq(unittest.TestCase): @@ -257,6 +265,7 @@ def test_rfftfreq(self, xp, dtype): {'shape': (10, 10), 'axes': 0}, {'shape': (10, 10), 'axes': (0, 1)}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFftshift(unittest.TestCase): diff --git a/tests/third_party/cupy/indexing_tests/test_generate.py b/tests/third_party/cupy/indexing_tests/test_generate.py index d9be22ed28aa..d10e503bcec8 100644 --- a/tests/third_party/cupy/indexing_tests/test_generate.py +++ b/tests/third_party/cupy/indexing_tests/test_generate.py @@ -7,6 +7,7 @@ from tests.third_party.cupy import testing +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestIndices(unittest.TestCase): diff --git a/tests/third_party/cupy/indexing_tests/test_indexing.py b/tests/third_party/cupy/indexing_tests/test_indexing.py index e3b6b18162b0..1cdab954bbe8 100644 --- a/tests/third_party/cupy/indexing_tests/test_indexing.py +++ b/tests/third_party/cupy/indexing_tests/test_indexing.py @@ -10,16 +10,19 @@ @testing.gpu class TestIndexing(unittest.TestCase): + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_take_by_scalar(self, xp): a = testing.shaped_arange((2, 4, 3), xp) return a.take(2, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_external_take_by_scalar(self, xp): a = testing.shaped_arange((2, 4, 3), xp) return xp.take(a, 2, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_take_by_array(self, xp): a = testing.shaped_arange((2, 4, 3), xp) @@ -48,12 +51,14 @@ def test_take_index_range_overflow(self, xp, dtype): b = xp.array([0], dtype=dtype) return a.take(b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_take_along_axis(self, xp): a = testing.shaped_random((2, 4, 3), xp, dtype='float32') b = testing.shaped_random((2, 6, 3), xp, dtype='int64', scale=4) return xp.take_along_axis(a, b, axis=-2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_take_along_axis_none_axis(self, xp): a = testing.shaped_random((2, 4, 3), xp, dtype='float32') @@ -97,6 +102,7 @@ def test_diagonal(self, xp, dtype): a = testing.shaped_arange((3, 4, 5), xp, dtype) return a.diagonal(1, 2, 0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_external_diagonal(self, xp, dtype): @@ -189,6 +195,7 @@ def test_extract_empty_1dim(self, xp): return xp.extract(b, a) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestChoose(unittest.TestCase): @@ -339,6 +346,7 @@ def test_select_type_error_condlist(self, dtype): with pytest.raises(AttributeError): cupy.select(condlist, choicelist) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_bool=True) def test_select_type_error_choicelist(self, dtype): a, b = list(range(10)), list(range(-10, 0)) diff --git a/tests/third_party/cupy/indexing_tests/test_insert.py b/tests/third_party/cupy/indexing_tests/test_insert.py index 722e3ee2a1ff..ed6a156e8848 100644 --- a/tests/third_party/cupy/indexing_tests/test_insert.py +++ b/tests/third_party/cupy/indexing_tests/test_insert.py @@ -64,6 +64,7 @@ def test_place_shape_unmatch_error(self, dtype): 'mode': ['raise', 'wrap', 'clip'], 'n_vals': [0, 1, 3, 4, 5], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestPut(unittest.TestCase): @@ -84,6 +85,7 @@ def test_put(self, xp, dtype): @testing.parameterize(*testing.product({ 'shape': [(7,), (2, 3), (4, 3, 2)], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestPutScalars(unittest.TestCase): @@ -110,6 +112,7 @@ def test_put_values_scalar(self, xp): @testing.parameterize(*testing.product({ 'shape': [(7,), (2, 3)], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestPutRaises(unittest.TestCase): @@ -178,6 +181,7 @@ def test_putmask(self, xp, dtype): return a +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestPutmask(unittest.TestCase): @@ -232,6 +236,7 @@ def test_putmask_differnt_dtypes_mask(self, xp, dtype): 'val': [1, 0, (2,), (2, 2)], 'wrap': [True, False], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestFillDiagonal(unittest.TestCase): @@ -308,6 +313,7 @@ def test_diag_indices_from(self, xp): @testing.parameterize(*testing.product({ 'shape': [(3, 5), (3, 3, 4), (5,), (0,), (-1,)], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDiagIndicesFromRaises(unittest.TestCase): diff --git a/tests/third_party/cupy/linalg_tests/test_einsum.py b/tests/third_party/cupy/linalg_tests/test_einsum.py index f4e2f623e908..26c7639ef0ce 100644 --- a/tests/third_party/cupy/linalg_tests/test_einsum.py +++ b/tests/third_party/cupy/linalg_tests/test_einsum.py @@ -13,6 +13,7 @@ def _dec_shape(shape, dec): return tuple(1 if s == 1 else max(0, s - dec) for s in shape) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestEinSumError(unittest.TestCase): def test_irregular_ellipsis1(self): @@ -194,21 +195,25 @@ def test_invalid_sub1(self): with pytest.raises(ValueError): xp.einsum(xp.arange(2), [None]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_invalid_sub2(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.einsum(xp.arange(2), [0], [1]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_invalid_sub3(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.einsum(xp.arange(2), [Ellipsis, 0, Ellipsis]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_dim_mismatch1(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.einsum(xp.arange(2), [0], xp.arange(3), [0]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_dim_mismatch2(self): for xp in (numpy, cupy): with pytest.raises(ValueError): @@ -219,11 +224,13 @@ def test_dim_mismatch3(self): with pytest.raises(ValueError): xp.einsum(xp.arange(6).reshape(2, 3), [0, 0]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_too_many_dims1(self): for xp in (numpy, cupy): with pytest.raises(ValueError): xp.einsum(3, [0]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_too_many_dims2(self): for xp in (numpy, cupy): with pytest.raises(ValueError): @@ -298,6 +305,7 @@ def setUp(self): self.operands = operands + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_allclose(contiguous_check=False) def test_einsum(self, xp): # TODO(kataoka): support memory efficient cupy.einsum diff --git a/tests/third_party/cupy/linalg_tests/test_product.py b/tests/third_party/cupy/linalg_tests/test_product.py index a4eff836e12c..2a97fa79b7ce 100644 --- a/tests/third_party/cupy/linalg_tests/test_product.py +++ b/tests/third_party/cupy/linalg_tests/test_product.py @@ -31,6 +31,7 @@ 'trans_a': [True, False], 'trans_b': [True, False], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDot(unittest.TestCase): @@ -89,6 +90,7 @@ def test_dot_with_out(self, xp, dtype_a, dtype_b, dtype_c): ((2, 4, 5, 2), (2, 4, 5, 2), 0, 0, -1), ], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestCrossProduct(unittest.TestCase): @@ -224,6 +226,7 @@ def test_transposed_multidim_vdot(self, xp, dtype): (2, 2, 2, 3), xp, dtype).transpose(1, 3, 0, 2) return xp.vdot(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_inner(self, xp, dtype): @@ -231,6 +234,7 @@ def test_inner(self, xp, dtype): b = testing.shaped_reverse_arange((5,), xp, dtype) return xp.inner(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_reversed_inner(self, xp, dtype): @@ -238,6 +242,7 @@ def test_reversed_inner(self, xp, dtype): b = testing.shaped_reverse_arange((5,), xp, dtype)[::-1] return xp.inner(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_multidim_inner(self, xp, dtype): @@ -273,6 +278,7 @@ def test_multidim_outer(self, xp, dtype): b = testing.shaped_arange((4, 5), xp, dtype) return xp.outer(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_tensordot(self, xp, dtype): @@ -287,6 +293,7 @@ def test_transposed_tensordot(self, xp, dtype): b = testing.shaped_arange((4, 3, 2), xp, dtype).transpose(2, 0, 1) return xp.tensordot(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_tensordot_with_int_axes(self, xp, dtype): @@ -316,6 +323,7 @@ def test_transposed_tensordot_with_int_axes(self, xp, dtype): (5, 4, 3, 2), xp, dtype).transpose(3, 0, 2, 1) return xp.tensordot(a, b, axes=3) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_tensordot_with_list_axes(self, xp, dtype): @@ -392,6 +400,7 @@ def test_zerodim_kron(self, xp, dtype): ((0, 0, 0), ([0, 2, 1], [1, 2, 0])), ], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestProductZeroLength(unittest.TestCase): @@ -404,6 +413,7 @@ def test_tensordot_zero_length(self, xp, dtype): class TestMatrixPower(unittest.TestCase): + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_matrix_power_0(self, xp, dtype): @@ -428,6 +438,7 @@ def test_matrix_power_3(self, xp, dtype): a = testing.shaped_arange((3, 3), xp, dtype) return xp.linalg.matrix_power(a, 3) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_float_dtypes(no_float16=True) @testing.numpy_cupy_allclose(rtol=1e-5) def test_matrix_power_inv1(self, xp, dtype): @@ -435,6 +446,7 @@ def test_matrix_power_inv1(self, xp, dtype): a = a * a % 30 return xp.linalg.matrix_power(a, -1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_float_dtypes(no_float16=True) @testing.numpy_cupy_allclose(rtol=1e-5) def test_matrix_power_inv2(self, xp, dtype): @@ -442,6 +454,7 @@ def test_matrix_power_inv2(self, xp, dtype): a = a * a % 30 return xp.linalg.matrix_power(a, -2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_float_dtypes(no_float16=True) @testing.numpy_cupy_allclose(rtol=1e-4) def test_matrix_power_inv3(self, xp, dtype): diff --git a/tests/third_party/cupy/logic_tests/test_comparison.py b/tests/third_party/cupy/logic_tests/test_comparison.py index 32ebc76c9b61..0be9eaeee610 100644 --- a/tests/third_party/cupy/logic_tests/test_comparison.py +++ b/tests/third_party/cupy/logic_tests/test_comparison.py @@ -1,5 +1,6 @@ import operator import unittest +import pytest import numpy @@ -7,6 +8,7 @@ from tests.third_party.cupy import testing +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestComparison(unittest.TestCase): @@ -36,6 +38,7 @@ def test_equal(self): self.check_binary('equal') +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestComparisonOperator(unittest.TestCase): @@ -160,6 +163,7 @@ def test_allclose_array_scalar(self, xp, dtype): return xp.allclose(a, b) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestIsclose(unittest.TestCase): @testing.for_all_dtypes(no_complex=True) diff --git a/tests/third_party/cupy/logic_tests/test_content.py b/tests/third_party/cupy/logic_tests/test_content.py index 32d4f95d1ef6..7172d9b12b2e 100644 --- a/tests/third_party/cupy/logic_tests/test_content.py +++ b/tests/third_party/cupy/logic_tests/test_content.py @@ -1,4 +1,5 @@ import unittest +import pytest import numpy @@ -23,11 +24,14 @@ def check_unary_nan(self, name, xp, dtype): dtype=dtype) return getattr(xp, name)(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_isfinite(self): self.check_unary_inf('isfinite') + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_isinf(self): self.check_unary_inf('isinf') + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_isnan(self): self.check_unary_nan('isnan') diff --git a/tests/third_party/cupy/logic_tests/test_ops.py b/tests/third_party/cupy/logic_tests/test_ops.py index 2948602b8a51..55b8617882b1 100644 --- a/tests/third_party/cupy/logic_tests/test_ops.py +++ b/tests/third_party/cupy/logic_tests/test_ops.py @@ -1,4 +1,5 @@ import unittest +import pytest from tests.third_party.cupy import testing @@ -19,14 +20,18 @@ def check_binary(self, name, xp, dtype): b = testing.shaped_reverse_arange((2, 3), xp, dtype) return getattr(xp, name)(a, b) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_logical_and(self): self.check_binary('logical_and') + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_logical_or(self): self.check_binary('logical_or') + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_logical_xor(self): self.check_binary('logical_xor') + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_logical_not(self): self.check_unary('logical_not') diff --git a/tests/third_party/cupy/manipulation_tests/test_basic.py b/tests/third_party/cupy/manipulation_tests/test_basic.py index 936e94c7e19f..8cc170d3241a 100644 --- a/tests/third_party/cupy/manipulation_tests/test_basic.py +++ b/tests/third_party/cupy/manipulation_tests/test_basic.py @@ -1,5 +1,6 @@ import itertools import unittest +import pytest import numpy @@ -27,6 +28,7 @@ def test_copyto_dtype(self, xp, dtype): xp.copyto(b, a) return b + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_copyto_broadcast(self, xp, dtype): @@ -35,6 +37,7 @@ def test_copyto_broadcast(self, xp, dtype): xp.copyto(b, a) return b + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_copyto_where(self, xp, dtype): @@ -107,6 +110,7 @@ def test_copyto_where(self, xp, dtype): *testing.product( {'src': [float(3.2), int(0), int(4), int(-4), True, False, 1 + 1j], 'dst_shape': [(), (0,), (1,), (1, 1), (2, 2)]})) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestCopytoFromScalar(unittest.TestCase): diff --git a/tests/third_party/cupy/manipulation_tests/test_dims.py b/tests/third_party/cupy/manipulation_tests/test_dims.py index c6ef32b21484..2c3e73b596da 100644 --- a/tests/third_party/cupy/manipulation_tests/test_dims.py +++ b/tests/third_party/cupy/manipulation_tests/test_dims.py @@ -19,15 +19,18 @@ def check_atleast(self, func, xp): f = numpy.float32(1) return func(a, b, c, d, e, f) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_1d1(self, xp): return self.check_atleast(xp.atleast_1d, xp) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_1d2(self, xp): a = testing.shaped_arange((1, 3, 2), xp) return xp.atleast_1d(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_2d1(self, xp): return self.check_atleast(xp.atleast_2d, xp) @@ -37,6 +40,7 @@ def test_atleast_2d2(self, xp): a = testing.shaped_arange((1, 3, 2), xp) return xp.atleast_2d(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_3d1(self, xp): return self.check_atleast(xp.atleast_3d, xp) diff --git a/tests/third_party/cupy/manipulation_tests/test_tiling.py b/tests/third_party/cupy/manipulation_tests/test_tiling.py index b6d0d180bf2e..fa00273671d5 100644 --- a/tests/third_party/cupy/manipulation_tests/test_tiling.py +++ b/tests/third_party/cupy/manipulation_tests/test_tiling.py @@ -16,6 +16,7 @@ {'repeats': [1, 2, 3], 'axis': 1}, {'repeats': [1, 2, 3], 'axis': -2}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeat(unittest.TestCase): @@ -44,6 +45,7 @@ def test_method(self): {'repeats': [2], 'axis': None}, {'repeats': [2], 'axis': 1}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeatListBroadcast(unittest.TestCase): @@ -65,6 +67,7 @@ def test_array_repeat(self, xp): {'repeats': [1, 2, 3, 4], 'axis': None}, {'repeats': [1, 2, 3, 4], 'axis': 0}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeat1D(unittest.TestCase): @@ -97,6 +100,7 @@ def test_array_repeat(self, xp): {'repeats': 2, 'axis': -4}, {'repeats': 2, 'axis': 3}, ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeatFailure(unittest.TestCase): diff --git a/tests/third_party/cupy/manipulation_tests/test_transpose.py b/tests/third_party/cupy/manipulation_tests/test_transpose.py index d12b268c2f4e..ed06f050f777 100644 --- a/tests/third_party/cupy/manipulation_tests/test_transpose.py +++ b/tests/third_party/cupy/manipulation_tests/test_transpose.py @@ -41,12 +41,14 @@ def test_moveaxis6(self, xp): return xp.moveaxis(a, [0, 2, 1], [3, 4, 0]) # dim is too large + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid1_1(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) with pytest.raises(numpy.AxisError): xp.moveaxis(a, [0, 1], [1, 3]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid1_2(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -54,12 +56,14 @@ def test_moveaxis_invalid1_2(self): xp.moveaxis(a, [0, 1], [1, 3]) # dim is too small + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid2_1(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) with pytest.raises(numpy.AxisError): xp.moveaxis(a, [0, -4], [1, 2]) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid2_2(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -67,6 +71,7 @@ def test_moveaxis_invalid2_2(self): xp.moveaxis(a, [0, -4], [1, 2]) # len(source) != len(destination) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid3(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -74,6 +79,7 @@ def test_moveaxis_invalid3(self): xp.moveaxis(a, [0, 1, 2], [1, 2]) # len(source) != len(destination) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid4(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -81,6 +87,7 @@ def test_moveaxis_invalid4(self): xp.moveaxis(a, [0, 1], [1, 2, 0]) # Use the same axis twice + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_moveaxis_invalid5_1(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -104,6 +111,7 @@ def test_rollaxis(self, xp): a = testing.shaped_arange((2, 3, 4), xp) return xp.rollaxis(a, 2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_rollaxis_failure(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) @@ -115,6 +123,7 @@ def test_swapaxes(self, xp): a = testing.shaped_arange((2, 3, 4), xp) return xp.swapaxes(a, 2, 0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_swapaxes_failure(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) diff --git a/tests/third_party/cupy/math_tests/test_arithmetic.py b/tests/third_party/cupy/math_tests/test_arithmetic.py index f4a92c8f25b7..9f5e8994b70f 100644 --- a/tests/third_party/cupy/math_tests/test_arithmetic.py +++ b/tests/third_party/cupy/math_tests/test_arithmetic.py @@ -57,6 +57,7 @@ def test_raises_with_numpy_input(self): 'name': ['reciprocal'], }) )) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestArithmeticUnary(unittest.TestCase): @testing.numpy_cupy_allclose(atol=1e-5) @@ -177,6 +178,7 @@ def check_binary(self, xp): 'name': ['divide', 'true_divide', 'subtract'], }) )) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestArithmeticBinary(ArithmeticBinaryBase, unittest.TestCase): def test_binary(self): @@ -226,6 +228,7 @@ def test_binary(self): 'use_dtype': [True, False], }) )) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestArithmeticBinary2(ArithmeticBinaryBase, unittest.TestCase): def test_binary(self): @@ -252,6 +255,7 @@ def test_modf(self, xp, dtype): 'xp': [numpy, cupy], 'shape': [(3, 2), (), (3, 0, 2)] })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestBoolSubtract(unittest.TestCase): diff --git a/tests/third_party/cupy/math_tests/test_matmul.py b/tests/third_party/cupy/math_tests/test_matmul.py index 3d9d258fd9d8..f8533eef8c1c 100644 --- a/tests/third_party/cupy/math_tests/test_matmul.py +++ b/tests/third_party/cupy/math_tests/test_matmul.py @@ -54,6 +54,7 @@ ((1, 3, 3), (10, 1, 3, 1)), ], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestMatmul(unittest.TestCase): @@ -88,6 +89,7 @@ def test_cupy_matmul(self, xp, dtype1): ((6, 5, 3, 2), (2,)), ], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestMatmulLarge(unittest.TestCase): @@ -138,6 +140,7 @@ def test_cupy_matmul(self, xp, dtype1): ((0, 1, 1), (2, 1, 1)), ], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestMatmulInvalidShape(unittest.TestCase): diff --git a/tests/third_party/cupy/math_tests/test_rounding.py b/tests/third_party/cupy/math_tests/test_rounding.py index 034e36c9f14b..91d74923f063 100644 --- a/tests/third_party/cupy/math_tests/test_rounding.py +++ b/tests/third_party/cupy/math_tests/test_rounding.py @@ -77,6 +77,7 @@ def test_round_(self): @testing.parameterize(*testing.product({ 'decimals': [-2, -1, 0, 1, 2], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestRound(unittest.TestCase): shape = (20,) @@ -136,6 +137,7 @@ def test_round_small(self, xp, dtype): (1.6, 0), ] })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestRoundBorder(unittest.TestCase): @testing.numpy_cupy_allclose(atol=1e-5) diff --git a/tests/third_party/cupy/math_tests/test_sumprod.py b/tests/third_party/cupy/math_tests/test_sumprod.py index 15066f03872e..d9fe3b22b265 100644 --- a/tests/third_party/cupy/math_tests/test_sumprod.py +++ b/tests/third_party/cupy/math_tests/test_sumprod.py @@ -227,6 +227,7 @@ def test_nansum_axis_transposed(self, xp, dtype): 'shape': [(2, 3, 4), (20, 30, 40)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestNansumNanprodExtra(unittest.TestCase): @@ -254,6 +255,7 @@ def test_nansum_out_wrong_shape(self): 'axis': [(1, 3), (0, 2, 3)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestNansumNanprodAxes(unittest.TestCase): @testing.for_all_dtypes(no_bool=True, no_float16=True) @@ -269,6 +271,7 @@ def test_nansum_axes(self, xp, dtype): @testing.parameterize(*testing.product({'axis': axes})) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestCumsum(unittest.TestCase): @@ -387,6 +390,7 @@ def test_cumprod_1dim(self, xp, dtype): a = testing.shaped_arange((5,), xp, dtype) return xp.cumprod(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_cumprod_out(self, xp, dtype): @@ -409,6 +413,7 @@ def test_cumprod_2dim_without_axis(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.cumprod(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_cumprod_2dim_with_axis(self, xp, dtype): @@ -434,6 +439,7 @@ def test_cumprod_huge_array(self): del result cupy.get_default_memory_pool().free_all_blocks() + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() def test_invalid_axis_lower1(self, dtype): for xp in (numpy, cupy): @@ -441,6 +447,7 @@ def test_invalid_axis_lower1(self, dtype): with pytest.raises(numpy.AxisError): xp.cumprod(a, axis=-a.ndim - 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() def test_invalid_axis_lower2(self, dtype): for xp in (numpy, cupy): @@ -448,6 +455,7 @@ def test_invalid_axis_lower2(self, dtype): with pytest.raises(numpy.AxisError): xp.cumprod(a, axis=-a.ndim - 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() def test_invalid_axis_upper1(self, dtype): for xp in (numpy, cupy): @@ -455,6 +463,7 @@ def test_invalid_axis_upper1(self, dtype): with pytest.raises(numpy.AxisError): return xp.cumprod(a, axis=a.ndim) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() def test_invalid_axis_upper2(self, dtype): a = testing.shaped_arange((4, 5), cupy, dtype) @@ -521,6 +530,7 @@ def test_diff_2dim_with_append(self, xp, dtype): b = testing.shaped_arange((1, 5), xp, dtype) return xp.diff(a, axis=0, append=b, n=2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.with_requires('numpy>=1.16') @testing.for_all_dtypes() @testing.numpy_cupy_allclose() @@ -528,6 +538,7 @@ def test_diff_2dim_with_scalar_append(self, xp, dtype): a = testing.shaped_arange((4, 5), xp, dtype) return xp.diff(a, prepend=1, append=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.with_requires('numpy>=1.16') def test_diff_invalid_axis(self): for xp in (numpy, cupy): diff --git a/tests/third_party/cupy/random_tests/test_distributions.py b/tests/third_party/cupy/random_tests/test_distributions.py index 1504cad45c60..e53d313d91f0 100644 --- a/tests/third_party/cupy/random_tests/test_distributions.py +++ b/tests/third_party/cupy/random_tests/test_distributions.py @@ -1,4 +1,5 @@ import unittest +import pytest import numpy @@ -31,6 +32,7 @@ def check_distribution(self, dist_name, params): 'b_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsBeta(RandomDistributionsTestCase): @@ -68,6 +70,7 @@ def test_binomial(self, n_dtype, p_dtype): 'df_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsChisquare(unittest.TestCase): @@ -88,6 +91,7 @@ def test_chisquare(self, df_dtype): 'alpha_shape': [(3,)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsDirichlet(RandomDistributionsTestCase): @@ -103,6 +107,7 @@ def test_dirichlet(self, alpha_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsExponential(RandomDistributionsTestCase): @@ -112,6 +117,7 @@ def test_exponential(self, scale_dtype): self.check_distribution('exponential', {'scale': scale}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsExponentialError(RandomDistributionsTestCase): @@ -127,6 +133,7 @@ def test_negative_scale(self): 'dfden_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsF(unittest.TestCase): @@ -151,6 +158,7 @@ def test_f(self, dfnum_dtype, dfden_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsGamma(unittest.TestCase): @@ -194,6 +202,7 @@ def test_geometric(self, p_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsGumbel(RandomDistributionsTestCase): @@ -239,6 +248,7 @@ def test_hypergeometric(self, ngood_dtype, nbad_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsuLaplace(RandomDistributionsTestCase): @@ -256,6 +266,7 @@ def test_laplace(self, loc_dtype, scale_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsLogistic(RandomDistributionsTestCase): @@ -342,6 +353,7 @@ def test_normal(self, mean_dtype, cov_dtype): 'p_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsNegativeBinomial(RandomDistributionsTestCase): @@ -368,6 +380,7 @@ def test_negative_binomial_for_noninteger_n(self, n_dtype, p_dtype): 'nonc_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsNoncentralChisquare(RandomDistributionsTestCase): @@ -401,6 +414,7 @@ def test_noncentral_chisquare_for_invalid_params(self, param_dtype): 'nonc_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsNoncentralF(RandomDistributionsTestCase): @@ -444,6 +458,7 @@ def test_noncentral_f_for_invalid_params(self, param_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsNormal(RandomDistributionsTestCase): @@ -460,6 +475,7 @@ def test_normal(self, loc_dtype, scale_dtype): 'a_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsPareto(unittest.TestCase): @@ -523,6 +539,7 @@ def test_power_for_negative_a(self, a_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsRayleigh(RandomDistributionsTestCase): @@ -571,6 +588,7 @@ def test_standard_exponential(self): 'shape_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsStandardGamma(RandomDistributionsTestCase): @@ -597,6 +615,7 @@ def test_standard_normal(self): 'df_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsStandardT(unittest.TestCase): @@ -619,6 +638,7 @@ def test_standard_t(self, df_dtype): 'right_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsTriangular(RandomDistributionsTestCase): @@ -662,6 +682,7 @@ def test_triangular_for_invalid_params(self, param_dtype): 'high_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsUniform(RandomDistributionsTestCase): @@ -679,6 +700,7 @@ def test_uniform(self, low_dtype, high_dtype): 'kappa_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsVonmises(unittest.TestCase): @@ -703,6 +725,7 @@ def test_vonmises(self, mu_dtype, kappa_dtype): 'scale_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsWald(RandomDistributionsTestCase): @@ -720,6 +743,7 @@ def test_wald(self, mean_dtype, scale_dtype): 'a_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsWeibull(RandomDistributionsTestCase): @@ -746,6 +770,7 @@ def test_weibull_for_negative_a(self, a_dtype): 'a_shape': [(), (3, 2)], }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestDistributionsZipf(RandomDistributionsTestCase): diff --git a/tests/third_party/cupy/random_tests/test_sample.py b/tests/third_party/cupy/random_tests/test_sample.py index 19e3fd54ba26..3f8a0169ac12 100644 --- a/tests/third_party/cupy/random_tests/test_sample.py +++ b/tests/third_party/cupy/random_tests/test_sample.py @@ -1,5 +1,6 @@ import unittest from unittest import mock +import pytest import numpy @@ -32,6 +33,7 @@ def test_lo_hi_nonrandom(self): a = random.randint(-1.1, -0.9, size=(2, 2)) numpy.testing.assert_array_equal(a, cupy.full((2, 2), -1)) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_zero_sizes(self): a = random.randint(10, size=(0,)) numpy.testing.assert_array_equal(a, cupy.array(())) @@ -44,6 +46,7 @@ def test_zero_sizes(self): @testing.gpu class TestRandint2(unittest.TestCase): + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @condition.repeat(3, 10) def test_bound_1(self): vals = [random.randint(0, 10, (2, 3)) for _ in range(10)] @@ -52,6 +55,7 @@ def test_bound_1(self): self.assertEqual(min(_.min() for _ in vals), 0) self.assertEqual(max(_.max() for _ in vals), 9) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @condition.repeat(3, 10) def test_bound_2(self): vals = [random.randint(0, 2) for _ in range(20)] @@ -60,6 +64,7 @@ def test_bound_2(self): self.assertEqual(min(_.min() for _ in vals), 0) self.assertEqual(max(_.max() for _ in vals), 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @condition.repeat(3, 10) def test_bound_overflow(self): # 100 - (-100) exceeds the range of int8 @@ -68,6 +73,7 @@ def test_bound_overflow(self): self.assertGreaterEqual(val.min(), -100) self.assertLess(val.max(), 100) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @condition.repeat(3, 10) def test_bound_float1(self): # generate floats s.t. int(low) < int(high) @@ -80,6 +86,7 @@ def test_bound_float1(self): self.assertEqual(min(_.min() for _ in vals), int(low)) self.assertEqual(max(_.max() for _ in vals), int(high) - 1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_bound_float2(self): vals = [random.randint(-1.0, 1.0, (2, 3)) for _ in range(10)] for val in vals: @@ -105,6 +112,7 @@ def test_goodness_of_fit_2(self): self.assertTrue(hypothesis.chi_square_test(counts, expected)) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRandintDtype(unittest.TestCase): diff --git a/tests/third_party/cupy/sorting_tests/test_search.py b/tests/third_party/cupy/sorting_tests/test_search.py index d9e80f3e87d6..838f559ed8cf 100644 --- a/tests/third_party/cupy/sorting_tests/test_search.py +++ b/tests/third_party/cupy/sorting_tests/test_search.py @@ -29,30 +29,35 @@ def test_argmax_nan(self, xp, dtype): a = xp.array([float('nan'), -1, 1], dtype) return a.argmax() + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmax_axis_large(self, xp, dtype): a = testing.shaped_random((3, 1000), xp, dtype) return a.argmax(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_external_argmax_axis_large(self, xp, dtype): a = testing.shaped_random((3, 1000), xp, dtype) return xp.argmax(a, axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmax_axis0(self, xp, dtype): a = testing.shaped_random((2, 3, 4), xp, dtype) return a.argmax(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmax_axis1(self, xp, dtype): a = testing.shaped_random((2, 3, 4), xp, dtype) return a.argmax(axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmax_axis2(self, xp, dtype): @@ -72,6 +77,7 @@ def test_argmax_zero_size(self, dtype): with pytest.raises(ValueError): a.argmax() + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) def test_argmax_zero_size_axis0(self, dtype): for xp in (numpy, cupy): @@ -79,6 +85,7 @@ def test_argmax_zero_size_axis0(self, dtype): with pytest.raises(ValueError): a.argmax(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmax_zero_size_axis1(self, xp, dtype): @@ -103,30 +110,35 @@ def test_external_argmin_all(self, xp, dtype): a = testing.shaped_random((2, 3), xp, dtype) return xp.argmin(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmin_axis_large(self, xp, dtype): a = testing.shaped_random((3, 1000), xp, dtype) return a.argmin(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_external_argmin_axis_large(self, xp, dtype): a = testing.shaped_random((3, 1000), xp, dtype) return xp.argmin(a, axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmin_axis0(self, xp, dtype): a = testing.shaped_random((2, 3, 4), xp, dtype) return a.argmin(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmin_axis1(self, xp, dtype): a = testing.shaped_random((2, 3, 4), xp, dtype) return a.argmin(axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmin_axis2(self, xp, dtype): @@ -146,6 +158,7 @@ def test_argmin_zero_size(self, dtype): with pytest.raises(ValueError): return a.argmin() + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) def test_argmin_zero_size_axis0(self, dtype): for xp in (numpy, cupy): @@ -153,6 +166,7 @@ def test_argmin_zero_size_axis0(self, dtype): with pytest.raises(ValueError): a.argmin(axis=0) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_argmin_zero_size_axis1(self, xp, dtype): @@ -571,6 +585,7 @@ def test_nanargmax_zero_size_axis1(self, xp, dtype): 'side': ['left', 'right'], 'shape': [(), (10,), (6, 3, 3)]}) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestSearchSorted(unittest.TestCase): @testing.for_all_dtypes(no_bool=True) @@ -586,6 +601,7 @@ def test_searchsorted(self, xp, dtype): @testing.parameterize( {'side': 'left'}, {'side': 'right'}) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestSearchSortedNanInf(unittest.TestCase): @testing.numpy_cupy_array_equal() @@ -648,6 +664,7 @@ def test_searchsorted_minf(self, xp): return y, +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestSearchSortedInvalid(unittest.TestCase): @@ -662,6 +679,7 @@ def test_searchsorted_ndbins(self): xp.searchsorted(bins, x) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestSearchSortedWithSorter(unittest.TestCase): diff --git a/tests/third_party/cupy/sorting_tests/test_sort.py b/tests/third_party/cupy/sorting_tests/test_sort.py index 966ccbf309b6..f26d13cf537b 100644 --- a/tests/third_party/cupy/sorting_tests/test_sort.py +++ b/tests/third_party/cupy/sorting_tests/test_sort.py @@ -34,12 +34,14 @@ def test_external_sort_zero_dim(self): with pytest.raises(numpy.AxisError): xp.sort(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_sort_two_or_more_dim(self, xp): a = testing.shaped_random((2, 3, 3), xp) a.sort() return a + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_external_sort_two_or_more_dim(self, xp): a = testing.shaped_random((2, 3, 3), xp) @@ -103,6 +105,7 @@ def test_sort_axis3(self, xp): a.sort(axis=2) return a + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_external_sort_axis(self, xp): a = testing.shaped_random((2, 3, 3), xp) @@ -114,11 +117,13 @@ def test_sort_negative_axis(self, xp): a.sort(axis=-2) return a + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_external_sort_negative_axis(self, xp): a = testing.shaped_random((2, 3, 3), xp) return xp.sort(a, axis=-2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_external_sort_none_axis(self, xp): a = testing.shaped_random((2, 3, 3), xp) @@ -135,12 +140,14 @@ def test_sort_invalid_axis2(self): with self.assertRaises(numpy.AxisError): a.sort(axis=3) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_external_sort_invalid_axis1(self): for xp in (numpy, cupy): a = testing.shaped_random((2, 3, 3), xp) with pytest.raises(numpy.AxisError): xp.sort(a, axis=3) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_external_sort_invalid_axis2(self): a = testing.shaped_random((2, 3, 3), cupy) with self.assertRaises(numpy.AxisError): @@ -157,12 +164,14 @@ def test_sort_invalid_negative_axis2(self): with self.assertRaises(numpy.AxisError): a.sort(axis=-4) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_external_sort_invalid_negative_axis1(self): for xp in (numpy, cupy): a = testing.shaped_random((2, 3, 3), xp) with pytest.raises(numpy.AxisError): xp.sort(a, axis=-4) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_external_sort_invalid_negative_axis2(self): a = testing.shaped_random((2, 3, 3), cupy) with self.assertRaises(numpy.AxisError): @@ -459,6 +468,7 @@ def test_sort_complex_nan(self, xp, dtype): 'external': [False, True], 'length': [10, 20000], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestPartition(unittest.TestCase): diff --git a/tests/third_party/cupy/statistics_tests/test_correlation.py b/tests/third_party/cupy/statistics_tests/test_correlation.py index f23d49114277..a6320c2d55bc 100644 --- a/tests/third_party/cupy/statistics_tests/test_correlation.py +++ b/tests/third_party/cupy/statistics_tests/test_correlation.py @@ -70,6 +70,7 @@ def check_raises(self, a_shape, y_shape=None, rowvar=True, bias=False, with pytest.raises(ValueError): xp.cov(a, y, rowvar, bias, ddof) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_cov(self): self.check((2, 3)) self.check((2,), (2,)) @@ -78,10 +79,12 @@ def test_cov(self): self.check((2, 3), bias=True) self.check((2, 3), ddof=2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_cov_warns(self): self.check_warns((2, 3), ddof=3) self.check_warns((2, 3), ddof=4) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_cov_raises(self): self.check_raises((2, 3), ddof=1.2) self.check_raises((3, 4, 2)) @@ -97,6 +100,7 @@ def test_cov_empty(self): 'shape1': [(5,), (6,), (20,), (21,)], 'shape2': [(5,), (6,), (20,), (21,)], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestCorrelateShapeCombination(unittest.TestCase): @testing.for_all_dtypes(no_float16=True) @@ -111,6 +115,7 @@ def test_correlate(self, xp, dtype): @testing.parameterize(*testing.product({ 'mode': ['valid', 'full', 'same'] })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestCorrelate(unittest.TestCase): @testing.for_all_dtypes() @@ -139,6 +144,7 @@ def test_correlate_diff_types(self, xp, dtype1, dtype2): @testing.parameterize(*testing.product({ 'mode': ['valid', 'same', 'full'] })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestCorrelateInvalid(unittest.TestCase): @testing.with_requires('numpy>=1.18') diff --git a/tests/third_party/cupy/statistics_tests/test_histogram.py b/tests/third_party/cupy/statistics_tests/test_histogram.py index 0560dc00256e..2065a826986d 100644 --- a/tests/third_party/cupy/statistics_tests/test_histogram.py +++ b/tests/third_party/cupy/statistics_tests/test_histogram.py @@ -138,6 +138,7 @@ def test_histogram_float_weights_dtype(self, xp, dtype): assert xp.issubdtype(h.dtype, xp.floating) return h + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_histogram_weights_basic(self): v = cupy.random.rand(100) w = cupy.ones(100) * 5 diff --git a/tests/third_party/cupy/statistics_tests/test_meanvar.py b/tests/third_party/cupy/statistics_tests/test_meanvar.py index ce6953812bbe..aea22d02c511 100644 --- a/tests/third_party/cupy/statistics_tests/test_meanvar.py +++ b/tests/third_party/cupy/statistics_tests/test_meanvar.py @@ -19,36 +19,42 @@ def test_median_noaxis(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_median_axis1(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_median_axis2(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a, axis=2) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_median_overwrite_input(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a, overwrite_input=True) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_median_keepdims_axis1(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a, axis=1, keepdims=True) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_median_keepdims_noaxis(self, xp, dtype): a = testing.shaped_random((3, 4, 5), xp, dtype) return xp.median(a, keepdims=True) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_median_invalid_axis(self): for xp in [numpy, cupy]: a = testing.shaped_random((3, 4, 5), xp) @@ -72,6 +78,7 @@ def test_median_invalid_axis(self): 'keepdims': [True, False] }) ) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestMedianAxis(unittest.TestCase): @@ -82,6 +89,7 @@ def test_median_axis_sequence(self, xp, dtype): return xp.median(a, self.axis, keepdims=self.keepdims) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestAverage(unittest.TestCase): @@ -148,6 +156,7 @@ def test_external_mean_all(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return xp.mean(a) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_mean_axis(self, xp, dtype): @@ -160,18 +169,21 @@ def test_external_mean_axis(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.mean(a, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_mean_all_float64_dtype(self, xp, dtype): a = xp.full((2, 3, 4), 123456789, dtype=dtype) return xp.mean(a, dtype=numpy.float64) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_mean_all_int64_dtype(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.mean(a, dtype=numpy.int64) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_mean_all_complex_dtype(self, xp, dtype): @@ -202,24 +214,28 @@ def test_external_var_all_ddof(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return xp.var(a, ddof=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_var_axis(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return a.var(axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_external_var_axis(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.var(a, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_var_axis_ddof(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return a.var(axis=1, ddof=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_external_var_axis_ddof(self, xp, dtype): @@ -250,24 +266,28 @@ def test_external_std_all_ddof(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return xp.std(a, ddof=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_std_axis(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return a.std(axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_external_std_axis(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.std(a, axis=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_std_axis_ddof(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return a.std(axis=1, ddof=1) + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.for_all_dtypes() @testing.numpy_cupy_allclose() def test_external_std_axis_ddof(self, xp, dtype): @@ -454,6 +474,7 @@ def test_nanstd_float16(self, xp): ], 'func': ['mean', 'std', 'var'], })) +@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestProductZeroLength(unittest.TestCase): From bbdacd03efcdacdd525c7fabd78b293d5dfa21ef Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 15 Nov 2022 04:34:14 -0600 Subject: [PATCH 4/4] Wrap numpy.isfinite() and numpy.signbit() with TODO note --- dpnp/random/dpnp_random_state.py | 61 ++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/dpnp/random/dpnp_random_state.py b/dpnp/random/dpnp_random_state.py index 87cdf83c4967..1ee37924db8d 100644 --- a/dpnp/random/dpnp_random_state.py +++ b/dpnp/random/dpnp_random_state.py @@ -70,6 +70,44 @@ def __init__(self, seed=None, device=None, sycl_queue=None): self._fallback_random_state = call_origin(numpy.random.RandomState, seed, allow_fallback=True) + def _is_finite_scalar(self, x): + """ + Test a scalar for finiteness (not infinity and not Not a Number). + + Parameters + ----------- + x : input value for test, must be a scalar. + + Returns + ------- + True where ``x`` is not positive infinity, negative infinity, or NaN; + false otherwise. + """ + + # TODO: replace with dpnp.isfinite() once function is available in DPNP, + # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar + return numpy.isfinite(x) + + + def _is_signbit_scalar(self, x): + """ + Test a scalar if sign bit is set for it (less than zero). + + Parameters + ----------- + x : input value for test, must be a scalar. + + Returns + ------- + True where sign bit is set for ``x`` (that is ``x`` is less than zero); + false otherwise. + """ + + # TODO: replace with dpnp.signbit() once function is available in DPNP, + # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar + return numpy.signbit(x) + + def get_state(self): """ Return an internal state of the generator. @@ -126,15 +164,13 @@ def normal(self, loc=0.0, scale=1.0, size=None, dtype=None, usm_type="device"): min_double = numpy.finfo('double').min max_double = numpy.finfo('double').max - # TODO: switch to dpnp.isfinite() and dpnp.signbit() once functions are available, - # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar - if (loc >= max_double or loc <= min_double) and numpy.isfinite(loc): + if (loc >= max_double or loc <= min_double) and self._is_finite_scalar(loc): raise OverflowError(f"Range of loc={loc} exceeds valid bounds") - if (scale >= max_double) and numpy.isfinite(scale): + if (scale >= max_double) and self._is_finite_scalar(scale): raise OverflowError(f"Range of scale={scale} exceeds valid bounds") # scale = -0.0 is cosidered as negative - elif scale < 0 or scale == 0 and numpy.signbit(scale): + elif scale < 0 or scale == 0 and self._is_signbit_scalar(scale): raise ValueError(f"scale={scale}, but must be non-negative.") if dtype is None: @@ -201,7 +237,8 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"): Limitations ----------- Parameters ``low`` and ``high`` are supported only as scalar. - Parameter ``dtype`` is supported only as `int`. + Parameter ``dtype`` is supported only as :obj:`dpnp.int32` or `int`, + but `int` value is considered to be exactly equivalent to :obj:`dpnp.int32`. Otherwise, :obj:`numpy.random.randint(low, high, size, dtype)` samples are drawn. Examples @@ -234,11 +271,9 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"): min_int = numpy.iinfo('int32').min max_int = numpy.iinfo('int32').max - # TODO: switch to dpnp.isfinite() once function is available, - # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar - if not numpy.isfinite(low) or low > max_int or low < min_int: + if not self._is_finite_scalar(low) or low > max_int or low < min_int: raise OverflowError(f"Range of low={low} exceeds valid bounds") - elif not numpy.isfinite(high) or high > max_int or high < min_int: + elif not self._is_finite_scalar(high) or high > max_int or high < min_int: raise OverflowError(f"Range of high={high} exceeds valid bounds") low = int(low) @@ -407,11 +442,9 @@ def uniform(self, low=0.0, high=1.0, size=None, dtype=None, usm_type="device"): min_double = numpy.finfo('double').min max_double = numpy.finfo('double').max - # TODO: switch to dpnp.isfinite() once function is available, - # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar - if not numpy.isfinite(low) or low >= max_double or low <= min_double: + if not self._is_finite_scalar(low) or low >= max_double or low <= min_double: raise OverflowError(f"Range of low={low} exceeds valid bounds") - elif not numpy.isfinite(high) or high >= max_double or high <= min_double: + elif not self._is_finite_scalar(high) or high >= max_double or high <= min_double: raise OverflowError(f"Range of high={high} exceeds valid bounds") if low > high: