From 67244af5de215c97e22c4a0c2eca386b8156142e Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Wed, 11 Dec 2024 14:10:40 +0100 Subject: [PATCH] Some stuff --- .github/workflows/conda-package.yml | 4 +- dpnp/tests/config.py | 5 +- dpnp/tests/helper.py | 22 ++++++++- dpnp/tests/test_absolute.py | 4 +- dpnp/tests/test_arraycreation.py | 9 +++- .../cupy/random_tests/test_distributions.py | 6 ++- dpnp/tests/third_party/cupy/testing/_loops.py | 49 ++++++++++++++++--- 7 files changed, 81 insertions(+), 18 deletions(-) diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 11f791ebaa2..76e578a5813 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -272,7 +272,7 @@ jobs: - name: Run full tests env: - DPNP_TEST_ALL_TYPES: 1 + DPNP_TEST_ALL_INT_TYPES: 1 run: | pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests @@ -527,7 +527,7 @@ jobs: - name: Run full tests if: matrix.python == '3.12' env: - DPNP_TEST_ALL_TYPES: 1 + DPNP_TEST_ALL_INT_TYPES: 1 run: | pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests diff --git a/dpnp/tests/config.py b/dpnp/tests/config.py index 322cffadfa0..0069efe23ee 100644 --- a/dpnp/tests/config.py +++ b/dpnp/tests/config.py @@ -1,3 +1,6 @@ import os -all_types = int(os.getenv("DPNP_TEST_ALL_TYPES", 0)) +all_int_types = int(os.getenv("DPNP_TEST_ALL_INT_TYPES", 0)) +float16_types = int(os.getenv("DPNP_TEST_FLOAT_16", 0)) +complex_types = int(os.getenv("DPNP_TEST_COMPLEX_TYPES", 0)) +bool_types = int(os.getenv("DPNP_TEST_BOOL_TYPES", 0)) diff --git a/dpnp/tests/helper.py b/dpnp/tests/helper.py index 0a55f13cbe7..f2e6a8fa830 100644 --- a/dpnp/tests/helper.py +++ b/dpnp/tests/helper.py @@ -89,7 +89,7 @@ def get_integer_dtypes(): Build a list of integer types supported by DPNP. """ - if config.all_types: + if config.all_int_types: return [ dpnp.int8, dpnp.int16, @@ -147,7 +147,13 @@ def get_float_complex_dtypes(no_float16=True, device=None): def get_all_dtypes( - no_bool=False, no_float16=True, no_complex=False, no_none=False, device=None + no_bool=False, + no_float16=True, + no_complex=False, + no_none=False, + device=None, + xfail_dtypes=None, + exclude=None, ): """ Build a list of types supported by DPNP based on input flags and device capabilities. @@ -171,6 +177,18 @@ def get_all_dtypes( # add None value to validate a default dtype if not no_none: dtypes.append(None) + + def mark_xfail(dtype): + if xfail_dtypes is not None and dtype in xfail_dtypes: + return pytest.param(dtype, marks=pytest.mark.xfail) + return dtype + + def not_excluded(dtype): + if exclude is None: + return True + return dtype not in exclude + + dtypes = [mark_xfail(dtype) for dtype in dtypes if not_excluded(dtype)] return dtypes diff --git a/dpnp/tests/test_absolute.py b/dpnp/tests/test_absolute.py index 1c6a42e98c6..3f5c4860f24 100644 --- a/dpnp/tests/test_absolute.py +++ b/dpnp/tests/test_absolute.py @@ -13,9 +13,9 @@ @pytest.mark.parametrize("func", ["abs", "absolute"]) -@pytest.mark.parametrize("dtype", get_all_dtypes()) +@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True)) def test_abs(func, dtype): - a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9], dtype=dtype) + a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9]).astype(dtype=dtype) ia = dpnp.array(a) result = getattr(dpnp, func)(ia) diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index 909d4d464b0..d892faf9d48 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -708,10 +708,17 @@ def test_dpctl_tensor_input(func, args): ids=["1", "5", "numpy.array(10)", "dpnp.array(17)", "dpt.asarray(100)"], ) @pytest.mark.parametrize( - "dtype", get_all_dtypes(no_bool=True, no_float16=False) + "dtype", + get_all_dtypes( + no_bool=True, no_float16=False, exclude=[numpy.uint8, dpnp.int8] + ), ) @pytest.mark.parametrize("retstep", [True, False]) def test_linspace(start, stop, num, dtype, retstep): + if numpy.issubdtype(dtype, numpy.unsignedinteger): + start = abs(start) + stop = abs(stop) + res_np = numpy.linspace(start, stop, num, dtype=dtype, retstep=retstep) res_dp = dpnp.linspace(start, stop, num, dtype=dtype, retstep=retstep) diff --git a/dpnp/tests/third_party/cupy/random_tests/test_distributions.py b/dpnp/tests/third_party/cupy/random_tests/test_distributions.py index 16ad014645a..93781d009d0 100644 --- a/dpnp/tests/third_party/cupy/random_tests/test_distributions.py +++ b/dpnp/tests/third_party/cupy/random_tests/test_distributions.py @@ -22,7 +22,7 @@ def check_distribution(self, dist_name, params, dtype=None): np_out = numpy.asarray( getattr(numpy.random, dist_name)(size=self.shape, **params), dtype ) - dt_kward = {dtype: dtype} if dtype else {} + dt_kward = {"dtype": dtype} if dtype else {} cp_out = getattr(_distributions, dist_name)( size=self.shape, **dt_kward, **cp_params ) @@ -72,12 +72,14 @@ def test_beta(self, a_dtype, b_dtype): "shape": [(4, 3, 2), (3, 2)], "n_shape": [(), (3, 2)], "p_shape": [(), (3, 2)], - "dtype": _int_dtypes, # to escape timeout + # "dtype": _int_dtypes, # to escape timeout + "dtype": [None], # no dtype supported } ) ) class TestDistributionsBinomial(RandomDistributionsTestCase): + @pytest.mark.skip() @testing.for_signed_dtypes("n_dtype") @testing.for_float_dtypes("p_dtype") def test_binomial(self, n_dtype, p_dtype): diff --git a/dpnp/tests/third_party/cupy/testing/_loops.py b/dpnp/tests/third_party/cupy/testing/_loops.py index 686d7f9d0b1..e9a0fde7104 100644 --- a/dpnp/tests/third_party/cupy/testing/_loops.py +++ b/dpnp/tests/third_party/cupy/testing/_loops.py @@ -8,6 +8,7 @@ from typing import Tuple, Type import numpy +import pytest from dpctl import select_default_device from dpctl.tensor._numpy_helper import AxisError @@ -979,7 +980,7 @@ def test_func(*args, **kw): return decorator -def for_dtypes(dtypes, name="dtype"): +def for_dtypes(dtypes, name="dtype", xfail_dtypes=None): """Decorator for parameterized dtype test. Args: @@ -1010,7 +1011,11 @@ def test_func(*args, **kw): try: kw[name] = numpy.dtype(dtype).type - impl(*args, **kw) + if xfail_dtypes is not None and dtype in xfail_dtypes: + impl_ = pytest.mark.xfail(impl) + else: + impl_ = impl + impl_(*args, **kw) except _skip_classes as e: print("skipped: {} = {} ({})".format(name, dtype, e)) except Exception: @@ -1041,19 +1046,47 @@ def _get_supported_complex_dtypes(): def _get_int_dtypes(): - if config.all_types: + if config.all_int_types: return _signed_dtypes + _unsigned_dtypes else: return (numpy.int64, numpy.int32) +def _get_float_dtypes(): + if config.float16_types: + return _regular_float_dtypes + (numpy.float16,) + else: + return _regular_float_dtypes + + +def _get_signed_dtypes(): + if config.all_int_types: + return tuple(numpy.dtype(i).type for i in "bhilq") + else: + return (numpy.int32,) + + +def _get_unsigned_dtypes(): + if config.all_int_types: + return tuple(numpy.dtype(i).type for i in "BHILQ") + else: + return (numpy.uint32,) + + +def _get_int_bool_dtypes(): + if config.bool_types: + return _int_dtypes + (numpy.bool_,) + else: + return _int_dtypes + + _complex_dtypes = _get_supported_complex_dtypes() _regular_float_dtypes = _get_supported_float_dtypes() -_float_dtypes = _regular_float_dtypes # + (numpy.float16,) -_signed_dtypes = tuple(numpy.dtype(i).type for i in "bhilq") -_unsigned_dtypes = tuple(numpy.dtype(i).type for i in "BHILQ") +_float_dtypes = _get_float_dtypes() +_signed_dtypes = _get_signed_dtypes() +_unsigned_dtypes = _get_unsigned_dtypes() _int_dtypes = _get_int_dtypes() -_int_bool_dtypes = _int_dtypes + (numpy.bool_,) +_int_bool_dtypes = _get_int_bool_dtypes() _regular_dtypes = _regular_float_dtypes + _int_bool_dtypes _dtypes = _float_dtypes + _int_bool_dtypes @@ -1069,7 +1102,7 @@ def _make_all_dtypes(no_float16, no_bool, no_complex): else: dtypes += _int_bool_dtypes - if not no_complex: + if config.complex_types and not no_complex: dtypes += _complex_dtypes return dtypes