diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 136863e85d3..8ff31e7205e 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -159,7 +159,7 @@ jobs: echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV - name: Install dpnp - run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} + run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest pytest-xdist python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} env: TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}' MAMBA_NO_LOW_SPEED_LIMIT: 1 @@ -175,7 +175,7 @@ jobs: - name: Run tests if: env.RERUN_TESTS_ON_FAILURE != 'true' run: | - python -m pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + python -m pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests - name: Run tests if: env.RERUN_TESTS_ON_FAILURE == 'true' @@ -190,7 +190,91 @@ jobs: . $CONDA/etc/profile.d/mamba.sh mamba activate ${{ env.TEST_ENV_NAME }} - python -m pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + python -m pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + + test_linux_all_dtypes: + name: Test ['ubuntu-latest', python='${{ matrix.python }}'] + + needs: build + + runs-on: ubuntu-latest + + defaults: + run: + shell: bash -el {0} + + strategy: + matrix: + python: ['3.12'] + + continue-on-error: true + + env: + channel-path: '${{ github.workspace }}/channel/' + pkg-path-in-channel: '${{ github.workspace }}/channel/linux-64/' + extracted-pkg-path: '${{ github.workspace }}/pkg/' + ver-json-path: '${{ github.workspace }}/version.json' + + steps: + - name: Download artifact + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + path: ${{ env.pkg-path-in-channel }} + + - name: Extract package archive + run: | + mkdir -p ${{ env.extracted-pkg-path }} + tar -xvf ${{ env.pkg-path-in-channel }}/${{ env.PACKAGE_NAME }}-*.tar.bz2 -C ${{ env.extracted-pkg-path }} + + - name: Setup miniconda + uses: conda-incubator/setup-miniconda@d2e6a045a86077fb6cad6f5adf368e9076ddaa8d # v3.1.0 + with: + miniforge-version: latest + use-mamba: 'true' + channels: conda-forge + conda-remove-defaults: 'true' + python-version: ${{ matrix.python }} + activate-environment: ${{ env.TEST_ENV_NAME }} + + - name: Install conda-index + run: mamba install conda-index=${{ env.CONDA_INDEX_VERSION }} + + - name: Create conda channel + run: | + python -m conda_index ${{ env.channel-path }} + + - name: Test conda channel + run: | + mamba search ${{ env.PACKAGE_NAME }} -c ${{ env.channel-path }} --override-channels --info --json > ${{ env.ver-json-path }} + cat ${{ env.ver-json-path }} + + - name: Get package version + run: | + export PACKAGE_VERSION=$(python -c "${{ env.VER_SCRIPT1 }} ${{ env.VER_SCRIPT2 }}") + + echo PACKAGE_VERSION=${PACKAGE_VERSION} + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV + + - name: Install dpnp + run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest pytest-xdist python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} + env: + TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}' + MAMBA_NO_LOW_SPEED_LIMIT: 1 + + - name: List installed packages + run: mamba list + + - name: Smoke test + run: | + python -c "import dpnp, dpctl; dpctl.lsplatform()" + python -c "import dpnp; print(dpnp.__version__)" + + - name: Run full tests + env: + DPNP_TEST_ALL_INT_TYPES: 1 + run: | + pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests test_windows: name: Test ['windows-2019', python='${{ matrix.python }}'] @@ -282,7 +366,7 @@ jobs: - name: Install dpnp run: | @echo on - mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} + mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest pytest-xdist python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} env: TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}' MAMBA_NO_LOW_SPEED_LIMIT: 1 @@ -311,7 +395,7 @@ jobs: - name: Run tests if: env.RERUN_TESTS_ON_FAILURE != 'true' run: | - pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests - name: Run tests if: env.RERUN_TESTS_ON_FAILURE == 'true' @@ -322,7 +406,130 @@ jobs: max_attempts: ${{ env.RUN_TESTS_MAX_ATTEMPTS }} retry_on: any command: | - python -m pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + python -m pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests + + test_windows_all_dtypes: + name: Test ['windows-2019', python='${{ matrix.python }}'] + + needs: build + + runs-on: windows-2019 + + defaults: + run: + shell: cmd /C CALL {0} + + strategy: + matrix: + python: ['3.12'] + + continue-on-error: true + + env: + channel-path: '${{ github.workspace }}\channel\' + pkg-path-in-channel: '${{ github.workspace }}\channel\win-64\' + extracted-pkg-path: '${{ github.workspace }}\pkg' + ver-json-path: '${{ github.workspace }}\version.json' + workdir: '${{ github.workspace }}' + + steps: + - name: Download artifact + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + path: ${{ env.pkg-path-in-channel }} + + - name: Extract package archive + run: | + @echo on + mkdir -p ${{ env.extracted-pkg-path }} + + set SEARCH_SCRIPT="DIR ${{ env.pkg-path-in-channel }} /s/b | FINDSTR /r "dpnp-.*\.tar\.bz2"" + FOR /F "tokens=* USEBACKQ" %%F IN (`%SEARCH_SCRIPT%`) DO ( + SET FULL_PACKAGE_PATH=%%F + ) + echo FULL_PACKAGE_PATH: %FULL_PACKAGE_PATH% + + python -c "import shutil; shutil.unpack_archive(r\"%FULL_PACKAGE_PATH%\", extract_dir=r\"${{ env.extracted-pkg-path }}\")" + dir ${{ env.extracted-pkg-path }} + + - name: Setup miniconda + uses: conda-incubator/setup-miniconda@d2e6a045a86077fb6cad6f5adf368e9076ddaa8d # v3.1.0 + with: + miniforge-version: latest + use-mamba: 'true' + channels: conda-forge + conda-remove-defaults: 'true' + python-version: ${{ matrix.python }} + activate-environment: ${{ env.TEST_ENV_NAME }} + + - name: Store conda paths as envs + run: | + @echo on + (echo CONDA_LIB_PATH=%CONDA_PREFIX%\Library\lib\) >> %GITHUB_ENV% + (echo CONDA_LIB_BIN_PATH=%CONDA_PREFIX%\Library\bin\) >> %GITHUB_ENV% + + - name: Install conda-index + run: mamba install conda-index=${{ env.CONDA_INDEX_VERSION }} + + - name: Create conda channel + run: | + @echo on + python -m conda_index ${{ env.channel-path }} + + - name: Test conda channel + run: | + @echo on + mamba search ${{ env.PACKAGE_NAME }} -c ${{ env.channel-path }} --override-channels --info --json > ${{ env.ver-json-path }} + + - name: Dump version.json + run: more ${{ env.ver-json-path }} + + - name: Get package version + run: | + @echo on + set "SCRIPT=${{ env.VER_SCRIPT1 }} ${{ env.VER_SCRIPT2 }}" + FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( + set PACKAGE_VERSION=%%F + ) + echo PACKAGE_VERSION: %PACKAGE_VERSION% + (echo PACKAGE_VERSION=%PACKAGE_VERSION%) >> %GITHUB_ENV% + + - name: Install dpnp + run: | + @echo on + mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest pytest-xdist python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} + env: + TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}' + MAMBA_NO_LOW_SPEED_LIMIT: 1 + + - name: List installed packages + run: mamba list + + - name: Activate OCL CPU RT + shell: pwsh + run: | + $script_path="$env:CONDA_PREFIX\Scripts\set-intel-ocl-icd-registry.ps1" + if (Test-Path $script_path) { + &$script_path + } else { + Write-Warning "File $script_path was NOT found!" + } + # Check the variable assisting OpenCL CPU driver to find TBB DLLs which are not located where it expects them by default + $cl_cfg="$env:CONDA_PREFIX\Library\lib\cl.cfg" + Get-Content -Tail 5 -Path $cl_cfg + + - name: Smoke test + run: | + python -c "import dpnp, dpctl; dpctl.lsplatform()" + python -c "import dpnp; print(dpnp.__version__)" + + - name: Run full tests + if: matrix.python == '3.12' + env: + DPNP_TEST_ALL_INT_TYPES: 1 + run: | + pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests upload: name: Upload ['${{ matrix.os }}', python='${{ matrix.python }}'] diff --git a/doc/reference/dtypes_table.rst b/doc/reference/dtypes_table.rst index 6d851da401a..40cf3d742b3 100644 --- a/doc/reference/dtypes_table.rst +++ b/doc/reference/dtypes_table.rst @@ -13,22 +13,35 @@ Table below shows a list of all supported data types (dtypes) and constants of t - Constants * - - :obj:`bool ` + - :obj:`int8 ` + - :obj:`int16 ` - :obj:`int32 ` - :obj:`int64 ` + - :obj:`uint8 ` + - :obj:`uint16 ` + - :obj:`uint32 ` + - :obj:`uint64 ` - :obj:`float32 ` - :obj:`float64 ` - :obj:`complex64 ` - :obj:`complex128 ` - - :obj:`bool_ ` + - :obj:`byte ` - :obj:`cdouble ` - :obj:`csingle ` - :obj:`double ` - :obj:`float16 ` - - :obj:`int ` - :obj:`int_ ` - :obj:`intc ` + - :obj:`intp ` + - :obj:`longlong ` - :obj:`single ` + - :obj:`ubyte ` + - :obj:`uintc ` + - :obj:`uintp ` + - :obj:`ushort ` + - :obj:`ulonglong ` - - :obj:`e ` - :obj:`euler_gamma ` diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 9fbe5b377c1..e06ed5c122e 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -40,6 +40,7 @@ __all__ = [ "bool", "bool_", + "byte", "cdouble", "complex128", "complex64", @@ -57,8 +58,9 @@ "iinfo", "inexact", "inf", - "int", "int_", + "int8", + "int16", "int32", "int64", "integer", @@ -66,12 +68,24 @@ "intp", "issubdtype", "is_type_supported", + "longlong", "nan", "newaxis", "number", "pi", + "short", "signedinteger", "single", + "ubyte", + "uint8", + "uint16", + "uint32", + "uint64", + "uintc", + "uintp", + "unsignedinteger", + "ushort", + "ulonglong", ] @@ -81,6 +95,7 @@ # ============================================================================= bool = numpy.bool_ bool_ = numpy.bool_ +byte = numpy.byte cdouble = numpy.cdouble complex128 = numpy.complex128 complex64 = numpy.complex64 @@ -93,16 +108,29 @@ float64 = numpy.float64 floating = numpy.floating inexact = numpy.inexact -int = numpy.int_ int_ = numpy.int_ +int8 = numpy.int8 +int16 = numpy.int16 int32 = numpy.int32 int64 = numpy.int64 integer = numpy.integer intc = numpy.intc intp = numpy.intp +longlong = numpy.longlong number = numpy.number +short = numpy.short signedinteger = numpy.signedinteger single = numpy.single +ubyte = numpy.ubyte +uint8 = numpy.uint8 +uint16 = numpy.uint16 +uint32 = numpy.uint32 +uint64 = numpy.uint64 +uintc = numpy.uintc +uintp = numpy.uintp +unsignedinteger = numpy.unsignedinteger +ushort = numpy.ushort +ulonglong = numpy.ulonglong # ============================================================================= diff --git a/dpnp/tests/config.py b/dpnp/tests/config.py new file mode 100644 index 00000000000..0069efe23ee --- /dev/null +++ b/dpnp/tests/config.py @@ -0,0 +1,6 @@ +import os + +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 ee457670f59..44945dc4c8b 100644 --- a/dpnp/tests/helper.py +++ b/dpnp/tests/helper.py @@ -2,9 +2,11 @@ import dpctl import numpy +import pytest from numpy.testing import assert_allclose, assert_array_equal import dpnp +from dpnp.tests import config def assert_dtype_allclose( @@ -88,6 +90,18 @@ def get_integer_dtypes(): Build a list of integer types supported by DPNP. """ + if config.all_int_types: + return [ + dpnp.int8, + dpnp.int16, + dpnp.int32, + dpnp.int64, + dpnp.uint8, + dpnp.uint16, + dpnp.uint32, + dpnp.uint64, + ] + return [dpnp.int32, dpnp.int64] @@ -134,7 +148,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. @@ -158,6 +178,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..445c348a95d 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -708,10 +708,15 @@ 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), ) @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/test_arraypad.py b/dpnp/tests/test_arraypad.py index 34a71eec707..16b7c23c75e 100644 --- a/dpnp/tests/test_arraypad.py +++ b/dpnp/tests/test_arraypad.py @@ -30,7 +30,11 @@ class TestPad: "empty": {}, } - @pytest.mark.parametrize("mode", _all_modes.keys()) + # .keys() returns set which is not ordered + # consistent order is required by xdist plugin + _modes = sorted(_all_modes.keys()) + + @pytest.mark.parametrize("mode", _modes) def test_basic(self, mode): a_np = numpy.arange(100) a_dp = dpnp.array(a_np) @@ -43,7 +47,7 @@ def test_basic(self, mode): else: assert_array_equal(result, expected) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_memory_layout_persistence(self, mode): """Test if C and F order is preserved for all pad modes.""" x = dpnp.ones((5, 10), order="C") @@ -52,13 +56,13 @@ def test_memory_layout_persistence(self, mode): assert dpnp.pad(x, 5, mode).flags.f_contiguous @pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True)) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_dtype_persistence(self, dtype, mode): arr = dpnp.zeros((3, 2, 1), dtype=dtype) result = dpnp.pad(arr, 1, mode=mode) assert result.dtype == dtype - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_non_contiguous_array(self, mode): a_np = numpy.arange(24).reshape(4, 6)[::2, ::2] a_dp = dpnp.arange(24).reshape(4, 6)[::2, ::2] @@ -73,12 +77,14 @@ def test_non_contiguous_array(self, mode): # TODO: include "linear_ramp" when dpnp issue gh-2084 is resolved @pytest.mark.parametrize("pad_width", [0, (0, 0), ((0, 0), (0, 0))]) - @pytest.mark.parametrize("mode", _all_modes.keys() - {"linear_ramp"}) + @pytest.mark.parametrize( + "mode", [m for m in _modes if m not in {"linear_ramp"}] + ) def test_zero_pad_width(self, pad_width, mode): arr = dpnp.arange(30).reshape(6, 5) assert_array_equal(arr, dpnp.pad(arr, pad_width, mode=mode)) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_pad_non_empty_dimension(self, mode): a_np = numpy.ones((2, 0, 2)) a_dp = dpnp.array(a_np) @@ -95,14 +101,14 @@ def test_pad_non_empty_dimension(self, mode): ((3, 4, 5), (0, 1, 2)), ], ) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_misshaped_pad_width1(self, pad_width, mode): arr = dpnp.arange(30).reshape((6, 5)) match = "operands could not be broadcast together" with pytest.raises(ValueError, match=match): dpnp.pad(arr, pad_width, mode) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_misshaped_pad_width2(self, mode): arr = dpnp.arange(30).reshape((6, 5)) match = ( @@ -115,7 +121,7 @@ def test_misshaped_pad_width2(self, mode): @pytest.mark.parametrize( "pad_width", [-2, (-2,), (3, -1), ((5, 2), (-2, 3)), ((-4,), (2,))] ) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_negative_pad_width(self, pad_width, mode): arr = dpnp.arange(30).reshape((6, 5)) match = "index can't contain negative values" @@ -126,14 +132,14 @@ def test_negative_pad_width(self, pad_width, mode): "pad_width", ["3", "word", None, 3.4, complex(1, -1), ((-2.1, 3), (3, 2))], ) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_bad_type(self, pad_width, mode): arr = dpnp.arange(30).reshape((6, 5)) match = "`pad_width` must be of integral type." with pytest.raises(TypeError, match=match): dpnp.pad(arr, pad_width, mode) - @pytest.mark.parametrize("mode", _all_modes.keys()) + @pytest.mark.parametrize("mode", _modes) def test_kwargs(self, mode): """Test behavior of pad's kwargs for the given mode.""" allowed = self._all_modes[mode] @@ -439,7 +445,7 @@ def test_pad_empty_dim_valid(self, mode): @pytest.mark.parametrize( "mode", - _all_modes.keys() - {"constant", "empty"}, + [m for m in _modes if m not in {"constant", "empty"}], ) def test_pad_empty_dim_invalid(self, mode): match = ( diff --git a/dpnp/tests/test_linalg.py b/dpnp/tests/test_linalg.py index 810258d3f3f..f239adae84f 100644 --- a/dpnp/tests/test_linalg.py +++ b/dpnp/tests/test_linalg.py @@ -2124,7 +2124,9 @@ def test_0D(self, ord, axis): assert_dtype_allclose(result, expected) @pytest.mark.usefixtures("suppress_divide_numpy_warnings") - @pytest.mark.parametrize("dtype", get_all_dtypes()) + @pytest.mark.parametrize( + "dtype", get_all_dtypes(xfail_dtypes=[dpnp.uint64]) + ) @pytest.mark.parametrize( "ord", [None, -dpnp.inf, -2, -1, 0, 1, 2, 3.5, dpnp.inf] ) @@ -2139,7 +2141,9 @@ def test_1D(self, dtype, ord, axis, keepdims): assert_dtype_allclose(result, expected) @pytest.mark.usefixtures("suppress_divide_numpy_warnings") - @pytest.mark.parametrize("dtype", get_all_dtypes()) + @pytest.mark.parametrize( + "dtype", get_all_dtypes(xfail_dtypes=[dpnp.uint64]) + ) @pytest.mark.parametrize( "ord", [None, -dpnp.inf, -2, -1, 1, 2, 3, dpnp.inf, "fro", "nuc"] ) @@ -2164,7 +2168,12 @@ def test_2D(self, dtype, ord, axis, keepdims): assert_dtype_allclose(result, expected) @pytest.mark.usefixtures("suppress_divide_numpy_warnings") - @pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True)) + @pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_none=True, xfail_dtypes=[dpnp.uint16, dpnp.uint32, dpnp.uint64] + ), + ) @pytest.mark.parametrize( "ord", [None, -dpnp.inf, -2, -1, 1, 2, 3, dpnp.inf, "fro", "nuc"] ) @@ -2195,7 +2204,10 @@ def test_ND(self, dtype, ord, axis, keepdims): assert_dtype_allclose(result, expected) @pytest.mark.usefixtures("suppress_divide_numpy_warnings") - @pytest.mark.parametrize("dtype", get_all_dtypes()) + @pytest.mark.parametrize( + "dtype", + get_all_dtypes(xfail_dtypes=[dpnp.uint16, dpnp.uint32, dpnp.uint64]), + ) @pytest.mark.parametrize( "ord", [None, -dpnp.inf, -2, -1, 1, 2, 3, dpnp.inf, "fro", "nuc"] ) diff --git a/dpnp/tests/test_random_state.py b/dpnp/tests/test_random_state.py index 7107a919c4e..35ff4154cde 100644 --- a/dpnp/tests/test_random_state.py +++ b/dpnp/tests/test_random_state.py @@ -241,7 +241,7 @@ def test_fallback(self, loc, scale): float, dpnp.int64, dpnp.int32, - dpnp.int, + dpnp.int_, int, numpy.clongdouble, dpnp.complex128, @@ -254,7 +254,7 @@ def test_fallback(self, loc, scale): "float", "dpnp.int64", "dpnp.int32", - "dpnp.int", + "dpnp.int_", "int", "numpy.clongdouble", "dpnp.complex128", @@ -364,8 +364,8 @@ def test_wrong_dims(self): class TestRandInt: @pytest.mark.parametrize( "dtype", - [int, dpnp.int32, dpnp.int], - ids=["int", "dpnp.int32", "dpnp.int"], + [int, dpnp.int32, dpnp.int_], + ids=["int", "dpnp.int32", "dpnp.int_"], ) @pytest.mark.parametrize( "usm_type", @@ -377,7 +377,7 @@ def test_distr(self, dtype, usm_type): low = 1 high = 10 - if dtype == dpnp.int and dtype != dpnp.dtype("int32"): + if dtype == dpnp.int_ and dtype != dpnp.dtype("int32"): pytest.skip( "dtype isn't alias on dpnp.int32 on the target OS, so there will be a fallback" ) @@ -564,10 +564,10 @@ def test_bounds_fallback(self, low, high): @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize( "dtype", - [dpnp.int64, dpnp.int, dpnp.bool, dpnp.bool_, bool], + [dpnp.int64, dpnp.int_, dpnp.bool, dpnp.bool_, bool], ids=[ "dpnp.int64", - "dpnp.int", + "dpnp.int_", "dpnp.bool", "dpnp.bool_", "bool", @@ -579,7 +579,7 @@ def test_dtype_fallback(self, dtype): high = 37 if not dtype in {dpnp.bool_, bool} else 2 size = (3, 2, 5) - if dtype == dpnp.int and dtype == dpnp.dtype("int32"): + if dtype == dpnp.int_ and dtype == dpnp.dtype("int32"): pytest.skip( "dtype is alias on dpnp.int32 on the target OS, so no fallback here" ) @@ -1155,7 +1155,7 @@ def test_fallback(self, low, high): dpnp.float16, float, dpnp.int64, - dpnp.int, + dpnp.int_, int, numpy.clongdouble, dpnp.complex128, @@ -1167,7 +1167,7 @@ def test_fallback(self, low, high): "dpnp.float16", "float", "dpnp.int64", - "dpnp.int", + "dpnp.int_", "int", "numpy.clongdouble", "dpnp.complex128", @@ -1177,7 +1177,7 @@ def test_fallback(self, low, high): ], ) def test_invalid_dtype(self, dtype): - if dtype == dpnp.int and dtype == dpnp.dtype("int32"): + if dtype == dpnp.int_ and dtype == dpnp.dtype("int32"): pytest.skip( "dtype is alias on dpnp.int32 on the target OS, so no error here" ) 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..ebed860fd29 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("n and p params as arrays are not supported") @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 901d1111b0b..e9a0fde7104 100644 --- a/dpnp/tests/third_party/cupy/testing/_loops.py +++ b/dpnp/tests/third_party/cupy/testing/_loops.py @@ -8,10 +8,12 @@ from typing import Tuple, Type import numpy +import pytest from dpctl import select_default_device from dpctl.tensor._numpy_helper import AxisError import dpnp as cupy +from dpnp.tests import config from dpnp.tests.third_party.cupy.testing import _array, _parameterized from dpnp.tests.third_party.cupy.testing._pytest_impl import is_available @@ -978,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: @@ -1009,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: @@ -1039,19 +1045,67 @@ def _get_supported_complex_dtypes(): return (numpy.complex64,) +def _get_int_dtypes(): + 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 -_signed_dtypes = () -_unsigned_dtypes = tuple(numpy.dtype(i).type for i in "BHILQ") -_int_dtypes = _signed_dtypes + _unsigned_dtypes -_int_bool_dtypes = _int_dtypes +_float_dtypes = _get_float_dtypes() +_signed_dtypes = _get_signed_dtypes() +_unsigned_dtypes = _get_unsigned_dtypes() +_int_dtypes = _get_int_dtypes() +_int_bool_dtypes = _get_int_bool_dtypes() _regular_dtypes = _regular_float_dtypes + _int_bool_dtypes _dtypes = _float_dtypes + _int_bool_dtypes def _make_all_dtypes(no_float16, no_bool, no_complex): - return (numpy.int64, numpy.int32) + _get_supported_float_dtypes() + if no_float16: + dtypes = _regular_float_dtypes + else: + dtypes = _float_dtypes + + if no_bool: + dtypes += _int_dtypes + else: + dtypes += _int_bool_dtypes + + if config.complex_types and not no_complex: + dtypes += _complex_dtypes + + return dtypes def for_all_dtypes(