From 83bac140b954dc7c64a0fd93fa0c4439c0812a89 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 7 Jul 2023 19:39:26 +0200 Subject: [PATCH 1/8] Update tests to test_linalg --- dpnp/dpnp_array.py | 2 +- tests/helper.py | 19 +++++++ tests/skipped_tests.tbl | 37 ------------- tests/skipped_tests_gpu.tbl | 37 ------------- tests/test_amin_amax.py | 51 +++++++----------- tests/test_arraycreation.py | 19 ++++++- tests/test_dparray.py | 102 +++++++++++++++++++++--------------- tests/test_fft.py | 6 +++ tests/test_histograms.py | 11 +++- tests/test_indexing.py | 17 ++---- 10 files changed, 136 insertions(+), 165 deletions(-) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index c0fc412df10..60b8351230f 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -60,7 +60,7 @@ class dpnp_array: def __init__( self, shape, - dtype="f8", + dtype=None, buffer=None, offset=0, strides=None, diff --git a/tests/helper.py b/tests/helper.py index 902db51f850..a2875a17465 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,6 +1,7 @@ from sys import platform import dpctl +import pytest import dpnp @@ -97,3 +98,21 @@ def has_support_aspect64(device=None): """ dev = dpctl.select_default_device() if device is None else device return dev.has_aspect_fp64 + + +def skip_dtype_not_supported(dtype, device=None): + """ + The function to check input type supported in DPNP based on the device capabilities. + """ + + dev = dpctl.select_default_device() if device is None else device + if not dev.has_aspect_fp64 and dtype in [ + None, + float, + complex, + dpnp.float64, + dpnp.complex128, + ]: + pytest.skip( + f"{dev.name} does not support double precision floating point types" + ) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index d0fb01ec90a..8e69ac1612c 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -41,43 +41,6 @@ tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpct tests/test_arraymanipulation.py::TestHstack::test_generator tests/test_arraymanipulation.py::TestVstack::test_generator -tests/test_dparray.py::test_astype[[]-float64-float64] -tests/test_dparray.py::test_astype[[]-float64-float32] -tests/test_dparray.py::test_astype[[]-float64-int64] -tests/test_dparray.py::test_astype[[]-float64-int32] -tests/test_dparray.py::test_astype[[]-float64-bool] -tests/test_dparray.py::test_astype[[]-float64-complex] -tests/test_dparray.py::test_astype[[]-float32-float64] -tests/test_dparray.py::test_astype[[]-float32-float32] -tests/test_dparray.py::test_astype[[]-float32-int64] -tests/test_dparray.py::test_astype[[]-float32-int32] -tests/test_dparray.py::test_astype[[]-float32-bool] -tests/test_dparray.py::test_astype[[]-float32-complex] -tests/test_dparray.py::test_astype[[]-int64-float64] -tests/test_dparray.py::test_astype[[]-int64-float32] -tests/test_dparray.py::test_astype[[]-int64-int64] -tests/test_dparray.py::test_astype[[]-int64-int32] -tests/test_dparray.py::test_astype[[]-int64-bool] -tests/test_dparray.py::test_astype[[]-int64-complex] -tests/test_dparray.py::test_astype[[]-int32-float64] -tests/test_dparray.py::test_astype[[]-int32-float32] -tests/test_dparray.py::test_astype[[]-int32-int64] -tests/test_dparray.py::test_astype[[]-int32-int32] -tests/test_dparray.py::test_astype[[]-int32-bool] -tests/test_dparray.py::test_astype[[]-int32-complex] -tests/test_dparray.py::test_astype[[]-bool-float64] -tests/test_dparray.py::test_astype[[]-bool-float32] -tests/test_dparray.py::test_astype[[]-bool-int64] -tests/test_dparray.py::test_astype[[]-bool-int32] -tests/test_dparray.py::test_astype[[]-bool-bool] -tests/test_dparray.py::test_astype[[]-bool-complex] -tests/test_dparray.py::test_astype[[]-complex-float64] -tests/test_dparray.py::test_astype[[]-complex-float32] -tests/test_dparray.py::test_astype[[]-complex-int64] -tests/test_dparray.py::test_astype[[]-complex-int32] -tests/test_dparray.py::test_astype[[]-complex-bool] -tests/test_dparray.py::test_astype[[]-complex-complex] - tests/test_linalg.py::test_cond[None-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] tests/test_linalg.py::test_cond[None-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[1-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 727d9650bfb..db79c188603 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -256,43 +256,6 @@ tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpct tests/test_arraymanipulation.py::TestHstack::test_generator tests/test_arraymanipulation.py::TestVstack::test_generator -tests/test_dparray.py::test_astype[[]-float64-float64] -tests/test_dparray.py::test_astype[[]-float64-float32] -tests/test_dparray.py::test_astype[[]-float64-int64] -tests/test_dparray.py::test_astype[[]-float64-int32] -tests/test_dparray.py::test_astype[[]-float64-bool] -tests/test_dparray.py::test_astype[[]-float64-complex] -tests/test_dparray.py::test_astype[[]-float32-float64] -tests/test_dparray.py::test_astype[[]-float32-float32] -tests/test_dparray.py::test_astype[[]-float32-int64] -tests/test_dparray.py::test_astype[[]-float32-int32] -tests/test_dparray.py::test_astype[[]-float32-bool] -tests/test_dparray.py::test_astype[[]-float32-complex] -tests/test_dparray.py::test_astype[[]-int64-float64] -tests/test_dparray.py::test_astype[[]-int64-float32] -tests/test_dparray.py::test_astype[[]-int64-int64] -tests/test_dparray.py::test_astype[[]-int64-int32] -tests/test_dparray.py::test_astype[[]-int64-bool] -tests/test_dparray.py::test_astype[[]-int64-complex] -tests/test_dparray.py::test_astype[[]-int32-float64] -tests/test_dparray.py::test_astype[[]-int32-float32] -tests/test_dparray.py::test_astype[[]-int32-int64] -tests/test_dparray.py::test_astype[[]-int32-int32] -tests/test_dparray.py::test_astype[[]-int32-bool] -tests/test_dparray.py::test_astype[[]-int32-complex] -tests/test_dparray.py::test_astype[[]-bool-float64] -tests/test_dparray.py::test_astype[[]-bool-float32] -tests/test_dparray.py::test_astype[[]-bool-int64] -tests/test_dparray.py::test_astype[[]-bool-int32] -tests/test_dparray.py::test_astype[[]-bool-bool] -tests/test_dparray.py::test_astype[[]-bool-complex] -tests/test_dparray.py::test_astype[[]-complex-float64] -tests/test_dparray.py::test_astype[[]-complex-float32] -tests/test_dparray.py::test_astype[[]-complex-int64] -tests/test_dparray.py::test_astype[[]-complex-int32] -tests/test_dparray.py::test_astype[[]-complex-bool] -tests/test_dparray.py::test_astype[[]-complex-complex] - tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] diff --git a/tests/test_amin_amax.py b/tests/test_amin_amax.py index 832a721d97c..8a451058636 100644 --- a/tests/test_amin_amax.py +++ b/tests/test_amin_amax.py @@ -1,61 +1,46 @@ import numpy import pytest +from numpy.testing import assert_allclose, assert_array_equal import dpnp +from .helper import get_all_dtypes -@pytest.mark.parametrize("type", [numpy.float64], ids=["float64"]) -def test_amax_float64(type): + +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True)) +def test_amax(dtype): a = numpy.array( [ [[-2.0, 3.0], [9.1, 0.2]], [[-2.0, 5.0], [-2, -1.2]], [[1.0, -2.0], [5.0, -1.1]], - ] + ], + dtype=dtype, ) ia = dpnp.array(a) for axis in range(len(a)): result = dpnp.amax(ia, axis=axis) expected = numpy.amax(a, axis=axis) - numpy.testing.assert_array_equal(expected, result) - - -@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"]) -def test_amax_int(type): - a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9]) - ia = dpnp.array(a) - - result = dpnp.amax(ia) - expected = numpy.amax(a) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result) -@pytest.mark.parametrize("type", [numpy.float64], ids=["float64"]) -def test_amin_float64(type): +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True)) +def test_amin(dtype): a = numpy.array( [ [[-2.0, 3.0], [9.1, 0.2]], [[-2.0, 5.0], [-2, -1.2]], [[1.0, -2.0], [5.0, -1.1]], - ] + ], + dtype=dtype, ) ia = dpnp.array(a) for axis in range(len(a)): result = dpnp.amin(ia, axis=axis) expected = numpy.amin(a, axis=axis) - numpy.testing.assert_array_equal(expected, result) - - -@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"]) -def test_amin_int(type): - a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9]) - ia = dpnp.array(a) - - result = dpnp.amin(ia) - expected = numpy.amin(a) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result) def _get_min_max_input(type, shape): @@ -79,14 +64,14 @@ def _get_min_max_input(type, shape): @pytest.mark.parametrize( "shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"] ) -def test_amax(type, shape): +def test_amax_diff_shape(type, shape): a = _get_min_max_input(type, shape) ia = dpnp.array(a) np_res = numpy.amax(a) dpnp_res = dpnp.amax(ia) - numpy.testing.assert_array_equal(dpnp_res, np_res) + assert_array_equal(dpnp_res, np_res) np_res = a.max() dpnp_res = ia.max() @@ -102,15 +87,15 @@ def test_amax(type, shape): @pytest.mark.parametrize( "shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"] ) -def test_amin(type, shape): +def test_amin_diff_shape(type, shape): a = _get_min_max_input(type, shape) ia = dpnp.array(a) np_res = numpy.amin(a) dpnp_res = dpnp.amin(ia) - numpy.testing.assert_array_equal(dpnp_res, np_res) + assert_array_equal(dpnp_res, np_res) np_res = a.min() dpnp_res = ia.min() - numpy.testing.assert_array_equal(dpnp_res, np_res) + assert_array_equal(dpnp_res, np_res) diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index adde904ca42..c835f6e0dd6 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -14,7 +14,11 @@ import dpnp -from .helper import get_all_dtypes +from .helper import ( + get_all_dtypes, + has_support_aspect64, + skip_dtype_not_supported, +) @pytest.mark.parametrize( @@ -117,6 +121,7 @@ def test_eye(N, M, k, dtype, order): @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False)) def test_frombuffer(dtype): + skip_dtype_not_supported(dtype) buffer = b"12345678ABCDEF00" func = lambda xp: xp.frombuffer(buffer, dtype=dtype) assert_allclose(func(dpnp), func(numpy)) @@ -607,7 +612,17 @@ def test_linspace(start, stop, num, dtype): if numpy.issubdtype(dtype, dpnp.integer): assert_allclose(func(numpy), func(dpnp), rtol=1) else: - assert_allclose(func(numpy), func(dpnp), atol=numpy.finfo(dtype).eps) + if dtype is None and not has_support_aspect64(): + assert_allclose( + func(numpy), + func(dpnp), + rtol=1e-06, + atol=numpy.finfo("float32").eps, + ) + else: + assert_allclose( + func(numpy), func(dpnp), rtol=1e-06, atol=numpy.finfo(dtype).eps + ) @pytest.mark.parametrize( diff --git a/tests/test_dparray.py b/tests/test_dparray.py index 051f449b856..dce2f0dbc60 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -1,11 +1,15 @@ import dpctl.tensor as dpt import numpy import pytest -from numpy.testing import assert_array_equal +from numpy.testing import assert_allclose, assert_array_equal import dpnp -from .helper import get_all_dtypes +from .helper import ( + get_all_dtypes, + has_support_aspect64, + skip_dtype_not_supported, +) @pytest.mark.parametrize("res_dtype", get_all_dtypes()) @@ -20,7 +24,7 @@ def test_astype(arr, arr_dtype, res_dtype): dpnp_array = dpnp.array(numpy_array) expected = numpy_array.astype(res_dtype) result = dpnp_array.astype(res_dtype) - assert_array_equal(expected, result) + assert_allclose(expected, result) @pytest.mark.parametrize("arr_dtype", get_all_dtypes()) @@ -100,30 +104,31 @@ def test_print_dpnp_int(): assert result == expected -def test_print_dpnp_float(): - result = repr(dpnp.array([1, -1, 21], dtype=float)) - expected = "array([ 1., -1., 21.])" - assert result == expected - - result = str(dpnp.array([1, -1, 21], dtype=float)) - expected = "[ 1. -1. 21.]" - assert result == expected - # float32 - result = repr(dpnp.array([1, -1, 21], dtype=dpnp.float32)) - expected = "array([ 1., -1., 21.], dtype=float32)" +@pytest.mark.parametrize( + "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] +) +def test_print_dpnp_float(dtype): + skip_dtype_not_supported(dtype) + result = repr(dpnp.array([1, -1, 21], dtype=dtype)) + if dtype is dpnp.float32: + expected = "array([ 1., -1., 21.], dtype=float32)" + else: + expected = "array([ 1., -1., 21.])" assert result == expected - result = str(dpnp.array([1, -1, 21], dtype=dpnp.float32)) + result = str(dpnp.array([1, -1, 21], dtype=dtype)) expected = "[ 1. -1. 21.]" assert result == expected def test_print_dpnp_complex(): - result = repr(dpnp.array([1, -1, 21], dtype=complex)) + dtype = complex + skip_dtype_not_supported(dtype) + result = repr(dpnp.array([1, -1, 21], dtype=dtype)) expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" assert result == expected - result = str(dpnp.array([1, -1, 21], dtype=complex)) + result = str(dpnp.array([1, -1, 21], dtype=dtype)) expected = "[ 1.+0.j -1.+0.j 21.+0.j]" assert result == expected @@ -138,49 +143,64 @@ def test_print_dpnp_boolean(): assert result == expected -def test_print_dpnp_special_character(): - # NaN - result = repr(dpnp.array([1.0, 0.0, dpnp.nan, 3.0])) - expected = "array([ 1., 0., nan, 3.])" - assert result == expected - - result = str(dpnp.array([1.0, 0.0, dpnp.nan, 3.0])) - expected = "[ 1. 0. nan 3.]" - assert result == expected - # inf - result = repr(dpnp.array([1.0, 0.0, dpnp.inf, 3.0])) - expected = "array([ 1., 0., inf, 3.])" +@pytest.mark.parametrize( + "character", [dpnp.nan, dpnp.inf], ids=["dpnp.nan", "dpnp.inf"] +) +def test_print_dpnp_special_character(character): + result = repr(dpnp.array([1.0, 0.0, character, 3.0])) + if has_support_aspect64(): + expected = f"array([ 1., 0., {character}, 3.])" + else: + expected = f"array([ 1., 0., {character}, 3.], dtype=float32)" assert result == expected - result = str(dpnp.array([1.0, 0.0, dpnp.inf, 3.0])) - expected = "[ 1. 0. inf 3.]" + result = str(dpnp.array([1.0, 0.0, character, 3.0])) + expected = f"[ 1. 0. {character} 3.]" assert result == expected -def test_print_dpnp_nd(): - # 1D - result = repr(dpnp.arange(10000, dtype="float32")) - expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03], dtype=float32)" +@pytest.mark.parametrize( + "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] +) +def test_print_dpnp_1_nd(dtype): + skip_dtype_not_supported(dtype) + result = repr(dpnp.arange(10000, dtype=dtype)) + if has_support_aspect64(): + expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03])" + else: + expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03], dtype=float32)" assert result == expected - result = str(dpnp.arange(10000, dtype="float32")) + result = str(dpnp.arange(10000, dtype=dtype)) expected = ( "[0.000e+00 1.000e+00 2.000e+00 ... 9.997e+03 9.998e+03 9.999e+03]" ) assert result == expected - # 2D - result = repr(dpnp.array([[1, 2], [3, 4]], dtype=float)) - expected = "array([[1., 2.],\n [3., 4.]])" + +@pytest.mark.parametrize( + "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] +) +def test_print_dpnp_2_nd(dtype): + skip_dtype_not_supported(dtype) + result = repr(dpnp.array([[1, 2], [3, 4]], dtype=dtype)) + if has_support_aspect64(): + expected = "array([[1., 2.],\n [3., 4.]])" + else: + expected = "array([[1., 2.],\n [3., 4.]], dtype=float32)" assert result == expected result = str(dpnp.array([[1, 2], [3, 4]])) expected = "[[1 2]\n [3 4]]" assert result == expected - # 0 shape + +def test_print_dpnp_zero_shape(): result = repr(dpnp.empty(shape=(0, 0))) - expected = "array([])" + if has_support_aspect64(): + expected = "array([])" + else: + expected = "array([], dtype=float32)" assert result == expected result = str(dpnp.empty(shape=(0, 0))) diff --git a/tests/test_fft.py b/tests/test_fft.py index 2be8e0880c3..682dcdc243e 100644 --- a/tests/test_fft.py +++ b/tests/test_fft.py @@ -3,6 +3,12 @@ import dpnp +from .helper import has_support_aspect64 + +pytestmark = pytest.mark.skipif( + not has_support_aspect64(), reason="Aborted on Iris Xe" +) + @pytest.mark.parametrize( "type", ["complex128", "complex64", "float32", "float64", "int32", "int64"] diff --git a/tests/test_histograms.py b/tests/test_histograms.py index eeb8cbf563f..07ae9652193 100644 --- a/tests/test_histograms.py +++ b/tests/test_histograms.py @@ -3,6 +3,8 @@ import dpnp +from .helper import has_support_aspect64 + class TestHistogram: def setup(self): @@ -20,7 +22,14 @@ def test_simple(self): numpy.testing.assert_equal(dpnp.sum(a, axis=0), n) # check that the bin counts are evenly spaced when the data is from # a linear function - (a, b) = dpnp.histogram(numpy.linspace(0, 10, 100)) + (a, b) = dpnp.histogram( + numpy.linspace( + 0, + 10, + 100, + dtype="float64" if has_support_aspect64() else "float32", + ) + ) numpy.testing.assert_array_equal(a, 10) @pytest.mark.usefixtures("allow_fall_back_on_numpy") diff --git a/tests/test_indexing.py b/tests/test_indexing.py index 354cfa06ff1..ab373aeae99 100644 --- a/tests/test_indexing.py +++ b/tests/test_indexing.py @@ -4,7 +4,7 @@ import dpnp -from .helper import get_all_dtypes +from .helper import get_all_dtypes, has_support_aspect64 class TestIndexing: @@ -592,18 +592,7 @@ def test_select(): assert_array_equal(expected, result) -@pytest.mark.parametrize( - "array_type", - [ - numpy.bool8, - numpy.int32, - numpy.int64, - numpy.float32, - numpy.float64, - numpy.complex128, - ], - ids=["bool8", "int32", "int64", "float32", "float64", "complex128"], -) +@pytest.mark.parametrize("array_type", get_all_dtypes(no_none=True)) @pytest.mark.parametrize( "indices_type", [numpy.int32, numpy.int64], ids=["int32", "int64"] ) @@ -641,6 +630,8 @@ def test_select(): ], ) def test_take(array, indices, array_type, indices_type): + if not has_support_aspect64() and array_type is numpy.complex64: + pytest.skip("The device does not support result of take function") a = numpy.array(array, dtype=array_type) ind = numpy.array(indices, dtype=indices_type) ia = dpnp.array(a) From 396efb416b8ef532fca003fb9acda4848a291b69 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 20 Jul 2023 13:17:12 +0200 Subject: [PATCH 2/8] Remove skip_dtype_not_supported func --- tests/helper.py | 18 ------------------ tests/test_arraycreation.py | 9 ++++++--- tests/test_dparray.py | 28 +++++++++++----------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/tests/helper.py b/tests/helper.py index 99465c11020..e12b021a886 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -107,21 +107,3 @@ def has_support_aspect64(device=None): """ dev = dpctl.select_default_device() if device is None else device return dev.has_aspect_fp64 - - -def skip_dtype_not_supported(dtype, device=None): - """ - The function to check input type supported in DPNP based on the device capabilities. - """ - - dev = dpctl.select_default_device() if device is None else device - if not dev.has_aspect_fp64 and dtype in [ - None, - float, - complex, - dpnp.float64, - dpnp.complex128, - ]: - pytest.skip( - f"{dev.name} does not support double precision floating point types" - ) diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index c835f6e0dd6..a063cf219df 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -17,7 +17,6 @@ from .helper import ( get_all_dtypes, has_support_aspect64, - skip_dtype_not_supported, ) @@ -119,9 +118,13 @@ def test_eye(N, M, k, dtype, order): @pytest.mark.usefixtures("allow_fall_back_on_numpy") -@pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False)) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_float16=False, no_none=False if has_support_aspect64() else True + ), +) def test_frombuffer(dtype): - skip_dtype_not_supported(dtype) buffer = b"12345678ABCDEF00" func = lambda xp: xp.frombuffer(buffer, dtype=dtype) assert_allclose(func(dpnp), func(numpy)) diff --git a/tests/test_dparray.py b/tests/test_dparray.py index dce2f0dbc60..5f7d0c1a206 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -7,8 +7,9 @@ from .helper import ( get_all_dtypes, + get_complex_dtypes, + get_float_dtypes, has_support_aspect64, - skip_dtype_not_supported, ) @@ -104,11 +105,8 @@ def test_print_dpnp_int(): assert result == expected -@pytest.mark.parametrize( - "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] -) +@pytest.mark.parametrize("dtype", get_float_dtypes()) def test_print_dpnp_float(dtype): - skip_dtype_not_supported(dtype) result = repr(dpnp.array([1, -1, 21], dtype=dtype)) if dtype is dpnp.float32: expected = "array([ 1., -1., 21.], dtype=float32)" @@ -121,11 +119,13 @@ def test_print_dpnp_float(dtype): assert result == expected -def test_print_dpnp_complex(): - dtype = complex - skip_dtype_not_supported(dtype) +@pytest.mark.parametrize("dtype", get_complex_dtypes()) +def test_print_dpnp_complex(dtype): result = repr(dpnp.array([1, -1, 21], dtype=dtype)) - expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" + if dtype is dpnp.complex64: + expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j], dtype=complex64)" + else: + expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" assert result == expected result = str(dpnp.array([1, -1, 21], dtype=dtype)) @@ -159,11 +159,8 @@ def test_print_dpnp_special_character(character): assert result == expected -@pytest.mark.parametrize( - "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] -) +@pytest.mark.parametrize("dtype", get_float_dtypes()) def test_print_dpnp_1_nd(dtype): - skip_dtype_not_supported(dtype) result = repr(dpnp.arange(10000, dtype=dtype)) if has_support_aspect64(): expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03])" @@ -178,11 +175,8 @@ def test_print_dpnp_1_nd(dtype): assert result == expected -@pytest.mark.parametrize( - "dtype", [float, dpnp.float32], ids=["float", "dpnp.float32"] -) +@pytest.mark.parametrize("dtype", get_float_dtypes()) def test_print_dpnp_2_nd(dtype): - skip_dtype_not_supported(dtype) result = repr(dpnp.array([[1, 2], [3, 4]], dtype=dtype)) if has_support_aspect64(): expected = "array([[1., 2.],\n [3., 4.]])" From 270220a037f3d249fc43ff935b71c9b5e792796c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 20 Jul 2023 13:17:54 +0200 Subject: [PATCH 3/8] Add support complex64 for dpnp.take --- dpnp/backend/kernels/dpnp_krnl_indexing.cpp | 4 ++++ tests/test_indexing.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_indexing.cpp b/dpnp/backend/kernels/dpnp_krnl_indexing.cpp index c2f9e0d9bda..ee385f9cc08 100644 --- a/dpnp/backend/kernels/dpnp_krnl_indexing.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_indexing.cpp @@ -1071,6 +1071,8 @@ void func_map_init_indexing_func(func_map_t &fmap) eft_FLT, (void *)dpnp_take_ext_c}; fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_DBL][eft_INT] = { eft_DBL, (void *)dpnp_take_ext_c}; + fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_C64][eft_INT] = { + eft_C64, (void *)dpnp_take_ext_c, int32_t>}; fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_C128][eft_INT] = { eft_C128, (void *)dpnp_take_ext_c, int32_t>}; fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_BLN][eft_LNG] = { @@ -1083,6 +1085,8 @@ void func_map_init_indexing_func(func_map_t &fmap) eft_FLT, (void *)dpnp_take_ext_c}; fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_DBL][eft_LNG] = { eft_DBL, (void *)dpnp_take_ext_c}; + fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_C64][eft_LNG] = { + eft_C64, (void *)dpnp_take_ext_c, int64_t>}; fmap[DPNPFuncName::DPNP_FN_TAKE_EXT][eft_C128][eft_LNG] = { eft_C128, (void *)dpnp_take_ext_c, int64_t>}; diff --git a/tests/test_indexing.py b/tests/test_indexing.py index ab373aeae99..3f0c3cd23f7 100644 --- a/tests/test_indexing.py +++ b/tests/test_indexing.py @@ -630,8 +630,6 @@ def test_select(): ], ) def test_take(array, indices, array_type, indices_type): - if not has_support_aspect64() and array_type is numpy.complex64: - pytest.skip("The device does not support result of take function") a = numpy.array(array, dtype=array_type) ind = numpy.array(indices, dtype=indices_type) ia = dpnp.array(a) From fea3016a4259fa101d5337a138235e78262f81ed Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 20 Jul 2023 23:24:02 +0200 Subject: [PATCH 4/8] Fix test_sort.py --- tests/test_sort.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/test_sort.py b/tests/test_sort.py index 9bf4d9adf76..11f32986db1 100644 --- a/tests/test_sort.py +++ b/tests/test_sort.py @@ -35,9 +35,6 @@ def test_partition(array, dtype, kth): a = dpnp.array(array, dtype) p = dpnp.partition(a, kth) - # TODO: remove once dpnp.less_equal() support complex types - p = p.asnumpy() - assert (p[..., 0:kth] <= p[..., kth : kth + 1]).all() assert (p[..., kth : kth + 1] <= p[..., kth + 1 :]).all() @@ -67,21 +64,15 @@ def test_partition(array, dtype, kth): ], ) @pytest.mark.parametrize( - "dtype", - [numpy.float64, numpy.float32, numpy.int64, numpy.int32], - ids=["float64", "float32", "int64", "int32"], + "dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True) ) @pytest.mark.parametrize( "array", - [[1, 2, 3, 4], [-5, -1, 0, 3, 17, 100]], + [[1, 2, 3, 4], [-5, -1, 0, 3, 17, 100], [1, 0, 3, 0]], ids=[ "[1, 2, 3, 4]", - "[-5, -1, 0, 3, 17, 100]" - # '[1, 0, 3, 0]', - # '[3, 2, 1, 6]', - # '[4, 2, 3, 3, 4, 1]', - # '[1, -3, 3, 0, 5, 2, 0, 1, 1, 0, 0, 1]', - # '[8, 2, 3, 0, 5, 2, 0, 1, 1, 3, 3, 1, 5, 2, 0, 1]' + "[-5, -1, 0, 3, 17, 100]", + "[1, 0, 3, 0]", ], ) def test_searchsorted(array, dtype, v_, side): From be37a5666fe093ccd58e46df9da75dec0915873f Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 20 Jul 2023 23:24:21 +0200 Subject: [PATCH 5/8] Fix test_special.py --- tests/test_special.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_special.py b/tests/test_special.py index c85d0234847..7d2e1b7cb7b 100644 --- a/tests/test_special.py +++ b/tests/test_special.py @@ -1,6 +1,7 @@ import math import numpy +from numpy.testing import assert_allclose import dpnp @@ -9,7 +10,7 @@ def test_erf(): a = numpy.linspace(2.0, 3.0, num=10) ia = dpnp.linspace(2.0, 3.0, num=10) - numpy.testing.assert_allclose(a, ia) + assert_allclose(a, ia) expected = numpy.empty_like(a) for idx, val in enumerate(a): @@ -17,7 +18,7 @@ def test_erf(): result = dpnp.erf(ia) - numpy.testing.assert_array_equal(result, expected) + assert_allclose(result, expected) def test_erf_fallback(): @@ -30,4 +31,4 @@ def test_erf_fallback(): result = dpnp.erf(dpa) - numpy.testing.assert_array_equal(result, expected) + assert_allclose(result, expected) From b2d5b4222931848cb57a2412b536b50fde99a2e4 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Jul 2023 13:29:28 +0200 Subject: [PATCH 6/8] Use dpnp.default_float_type for test_print_dpnp_nd --- tests/test_dparray.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_dparray.py b/tests/test_dparray.py index 5f7d0c1a206..c41e2063d84 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -159,8 +159,8 @@ def test_print_dpnp_special_character(character): assert result == expected -@pytest.mark.parametrize("dtype", get_float_dtypes()) -def test_print_dpnp_1_nd(dtype): +def test_print_dpnp_1_nd(): + dtype = dpnp.default_float_type() result = repr(dpnp.arange(10000, dtype=dtype)) if has_support_aspect64(): expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03])" @@ -175,8 +175,8 @@ def test_print_dpnp_1_nd(dtype): assert result == expected -@pytest.mark.parametrize("dtype", get_float_dtypes()) -def test_print_dpnp_2_nd(dtype): +def test_print_dpnp_2_nd(): + dtype = dpnp.default_float_type() result = repr(dpnp.array([[1, 2], [3, 4]], dtype=dtype)) if has_support_aspect64(): expected = "array([[1., 2.],\n [3., 4.]])" From 1b93a6d544d339b10e4e04a487dc7bcb3612bbdb Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Jul 2023 13:53:39 +0200 Subject: [PATCH 7/8] A small update skipped_tests --- tests/skipped_tests.tbl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index 0c9c7da26f4..cd00837d037 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -39,11 +39,6 @@ tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpct tests/test_arraymanipulation.py::TestHstack::test_generator tests/test_arraymanipulation.py::TestVstack::test_generator -tests/test_linalg.py::test_cond[None-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[None-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[1-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[-1-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] From 16d1bc67d102277c2bd3cc2b5466765fa0be3156 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Jul 2023 14:39:20 +0200 Subject: [PATCH 8/8] Fix remarks --- tests/helper.py | 1 - tests/test_amin_amax.py | 20 ++++++-------------- tests/test_arraycreation.py | 14 ++++---------- tests/test_dparray.py | 36 +++++++++++++++--------------------- tests/test_fft.py | 2 +- tests/test_indexing.py | 2 +- tests/test_sort.py | 14 +++++++++++++- 7 files changed, 40 insertions(+), 49 deletions(-) diff --git a/tests/helper.py b/tests/helper.py index e12b021a886..6971feecb53 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,7 +1,6 @@ from sys import platform import dpctl -import pytest import dpnp diff --git a/tests/test_amin_amax.py b/tests/test_amin_amax.py index 8a451058636..7c5bb8b1b50 100644 --- a/tests/test_amin_amax.py +++ b/tests/test_amin_amax.py @@ -56,16 +56,12 @@ def _get_min_max_input(type, 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"], -) +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True)) @pytest.mark.parametrize( "shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"] ) -def test_amax_diff_shape(type, shape): - a = _get_min_max_input(type, shape) +def test_amax_diff_shape(dtype, shape): + a = _get_min_max_input(dtype, shape) ia = dpnp.array(a) @@ -79,16 +75,12 @@ def test_amax_diff_shape(type, 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"], -) +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True)) @pytest.mark.parametrize( "shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"] ) -def test_amin_diff_shape(type, shape): - a = _get_min_max_input(type, shape) +def test_amin_diff_shape(dtype, shape): + a = _get_min_max_input(dtype, shape) ia = dpnp.array(a) diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index a063cf219df..f846a74ef38 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -616,16 +616,10 @@ def test_linspace(start, stop, num, dtype): assert_allclose(func(numpy), func(dpnp), rtol=1) else: if dtype is None and not has_support_aspect64(): - assert_allclose( - func(numpy), - func(dpnp), - rtol=1e-06, - atol=numpy.finfo("float32").eps, - ) - else: - assert_allclose( - func(numpy), func(dpnp), rtol=1e-06, atol=numpy.finfo(dtype).eps - ) + dtype = dpnp.float32 + assert_allclose( + func(numpy), func(dpnp), rtol=1e-06, atol=numpy.finfo(dtype).eps + ) @pytest.mark.parametrize( diff --git a/tests/test_dparray.py b/tests/test_dparray.py index c41e2063d84..47d8c5ca931 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -108,11 +108,9 @@ def test_print_dpnp_int(): @pytest.mark.parametrize("dtype", get_float_dtypes()) def test_print_dpnp_float(dtype): result = repr(dpnp.array([1, -1, 21], dtype=dtype)) + expected = "array([ 1., -1., 21.])" if dtype is dpnp.float32: - expected = "array([ 1., -1., 21.], dtype=float32)" - else: - expected = "array([ 1., -1., 21.])" - assert result == expected + expected = expected[:-1] + ", dtype=float32)" result = str(dpnp.array([1, -1, 21], dtype=dtype)) expected = "[ 1. -1. 21.]" @@ -122,10 +120,9 @@ def test_print_dpnp_float(dtype): @pytest.mark.parametrize("dtype", get_complex_dtypes()) def test_print_dpnp_complex(dtype): result = repr(dpnp.array([1, -1, 21], dtype=dtype)) + expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" if dtype is dpnp.complex64: - expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j], dtype=complex64)" - else: - expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" + expected = expected[:-1] + ", dtype=complex64)" assert result == expected result = str(dpnp.array([1, -1, 21], dtype=dtype)) @@ -148,10 +145,9 @@ def test_print_dpnp_boolean(): ) def test_print_dpnp_special_character(character): result = repr(dpnp.array([1.0, 0.0, character, 3.0])) - if has_support_aspect64(): - expected = f"array([ 1., 0., {character}, 3.])" - else: - expected = f"array([ 1., 0., {character}, 3.], dtype=float32)" + expected = f"array([ 1., 0., {character}, 3.])" + if not has_support_aspect64(): + expected = expected[:-1] + ", dtype=float32)" assert result == expected result = str(dpnp.array([1.0, 0.0, character, 3.0])) @@ -159,13 +155,12 @@ def test_print_dpnp_special_character(character): assert result == expected -def test_print_dpnp_1_nd(): +def test_print_dpnp_1d(): dtype = dpnp.default_float_type() result = repr(dpnp.arange(10000, dtype=dtype)) - if has_support_aspect64(): - expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03])" - else: - expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03], dtype=float32)" + expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03])" + if not has_support_aspect64(): + expected = expected[:-1] + ", dtype=float32)" assert result == expected result = str(dpnp.arange(10000, dtype=dtype)) @@ -175,13 +170,12 @@ def test_print_dpnp_1_nd(): assert result == expected -def test_print_dpnp_2_nd(): +def test_print_dpnp_2d(): dtype = dpnp.default_float_type() result = repr(dpnp.array([[1, 2], [3, 4]], dtype=dtype)) - if has_support_aspect64(): - expected = "array([[1., 2.],\n [3., 4.]])" - else: - expected = "array([[1., 2.],\n [3., 4.]], dtype=float32)" + expected = "array([[1., 2.],\n [3., 4.]])" + if not has_support_aspect64(): + expected = expected[:-1] + ", dtype=float32)" assert result == expected result = str(dpnp.array([[1, 2], [3, 4]])) diff --git a/tests/test_fft.py b/tests/test_fft.py index 682dcdc243e..38185f3e5f0 100644 --- a/tests/test_fft.py +++ b/tests/test_fft.py @@ -6,7 +6,7 @@ from .helper import has_support_aspect64 pytestmark = pytest.mark.skipif( - not has_support_aspect64(), reason="Aborted on Iris Xe" + not has_support_aspect64(), reason="Aborted on Iris Xe: SAT-6028" ) diff --git a/tests/test_indexing.py b/tests/test_indexing.py index 2aaa2c9cefc..67600264356 100644 --- a/tests/test_indexing.py +++ b/tests/test_indexing.py @@ -4,7 +4,7 @@ import dpnp -from .helper import get_all_dtypes, has_support_aspect64 +from .helper import get_all_dtypes class TestIndexing: diff --git a/tests/test_sort.py b/tests/test_sort.py index 11f32986db1..7ef6c23f734 100644 --- a/tests/test_sort.py +++ b/tests/test_sort.py @@ -68,11 +68,23 @@ def test_partition(array, dtype, kth): ) @pytest.mark.parametrize( "array", - [[1, 2, 3, 4], [-5, -1, 0, 3, 17, 100], [1, 0, 3, 0]], + [ + [1, 2, 3, 4], + [-5, -1, 0, 3, 17, 100], + [1, 0, 3, 0], + [3, 2, 1, 6], + [4, 2, 3, 3, 4, 1], + [1, -3, 3, 0, 5, 2, 0, 1, 1, 0, 0, 1], + [8, 2, 3, 0, 5, 2, 0, 1, 1, 3, 3, 1, 5, 2, 0, 1], + ], ids=[ "[1, 2, 3, 4]", "[-5, -1, 0, 3, 17, 100]", "[1, 0, 3, 0]", + "[3, 2, 1, 6]", + "[4, 2, 3, 3, 4, 1]", + "[1, -3, 3, 0, 5, 2, 0, 1, 1, 0, 0, 1]", + "[8, 2, 3, 0, 5, 2, 0, 1, 1, 3, 3, 1, 5, 2, 0, 1]", ], ) def test_searchsorted(array, dtype, v_, side):