diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 75ae72a31d08..17957e154044 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -62,7 +62,7 @@ class dpnp_array: def __init__( self, shape, - dtype="f8", + dtype=None, buffer=None, offset=0, strides=None, diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index ff5494e5f71e..cd00837d0379 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -39,43 +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_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/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 4fc12eff1aba..d0a477666efa 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -239,43 +239,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 832a721d97ce..7c5bb8b1b503 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) + assert_allclose(expected, result) - result = dpnp.amax(ia) - expected = numpy.amax(a) - numpy.testing.assert_array_equal(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): @@ -71,22 +56,18 @@ 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(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) 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() @@ -94,23 +75,19 @@ def test_amax(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(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) 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 adde904ca42e..f846a74ef38e 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -14,7 +14,10 @@ import dpnp -from .helper import get_all_dtypes +from .helper import ( + get_all_dtypes, + has_support_aspect64, +) @pytest.mark.parametrize( @@ -115,7 +118,12 @@ 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): buffer = b"12345678ABCDEF00" func = lambda xp: xp.frombuffer(buffer, dtype=dtype) @@ -607,7 +615,11 @@ 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(): + 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 051f449b856e..47d8c5ca9310 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -1,11 +1,16 @@ 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, + get_complex_dtypes, + get_float_dtypes, + has_support_aspect64, +) @pytest.mark.parametrize("res_dtype", get_all_dtypes()) @@ -20,7 +25,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 +105,27 @@ def test_print_dpnp_int(): assert result == expected -def test_print_dpnp_float(): - result = repr(dpnp.array([1, -1, 21], dtype=float)) +@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.])" - 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)" - assert result == expected + if dtype is dpnp.float32: + expected = expected[:-1] + ", dtype=float32)" - 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)) +@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 = expected[:-1] + ", dtype=complex64)" 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 +140,55 @@ 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])) + 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, 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)" +def test_print_dpnp_1d(): + dtype = dpnp.default_float_type() + result = repr(dpnp.arange(10000, dtype=dtype)) + 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="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)) + +def test_print_dpnp_2d(): + dtype = dpnp.default_float_type() + result = repr(dpnp.array([[1, 2], [3, 4]], dtype=dtype)) 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]])) 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 2be8e0880c3a..38185f3e5f09 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: SAT-6028" +) + @pytest.mark.parametrize( "type", ["complex128", "complex64", "float32", "float64", "int32", "int64"] diff --git a/tests/test_histograms.py b/tests/test_histograms.py index b62f653b0c97..2fb4cd71fa6c 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, _ = dpnp.histogram(dpnp.linspace(0, 10, 100)) + a, _ = 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_sort.py b/tests/test_sort.py index 9bf4d9adf76d..7ef6c23f734e 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,27 @@ 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], + [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]' + "[-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): diff --git a/tests/test_special.py b/tests/test_special.py index c85d02348473..7d2e1b7cb7b0 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)