From 96b80e83fcdafa224b0d26e6216fa3f5f7b83c80 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 29 Apr 2026 08:09:15 -0700 Subject: [PATCH] pare down tensor test suite --- dpnp/tests/tensor/elementwise/test_abs.py | 71 ++-- dpnp/tests/tensor/elementwise/test_add.py | 88 +---- dpnp/tests/tensor/elementwise/test_atan2.py | 24 +- .../tensor/elementwise/test_bitwise_and.py | 12 - .../tensor/elementwise/test_bitwise_invert.py | 47 --- .../elementwise/test_bitwise_left_shift.py | 8 - .../tensor/elementwise/test_bitwise_or.py | 12 - .../elementwise/test_bitwise_right_shift.py | 8 - .../tensor/elementwise/test_bitwise_xor.py | 12 - dpnp/tests/tensor/elementwise/test_complex.py | 31 -- .../tests/tensor/elementwise/test_copysign.py | 22 -- dpnp/tests/tensor/elementwise/test_divide.py | 122 ------- dpnp/tests/tensor/elementwise/test_equal.py | 132 -------- dpnp/tests/tensor/elementwise/test_exp.py | 47 --- dpnp/tests/tensor/elementwise/test_exp2.py | 49 --- dpnp/tests/tensor/elementwise/test_expm1.py | 49 --- .../elementwise/test_floor_ceil_trunc.py | 42 --- .../tensor/elementwise/test_floor_divide.py | 142 -------- dpnp/tests/tensor/elementwise/test_greater.py | 131 -------- .../tensor/elementwise/test_greater_equal.py | 131 -------- dpnp/tests/tensor/elementwise/test_hypot.py | 135 -------- .../tests/tensor/elementwise/test_isfinite.py | 20 -- dpnp/tests/tensor/elementwise/test_isinf.py | 20 -- dpnp/tests/tensor/elementwise/test_isnan.py | 19 -- dpnp/tests/tensor/elementwise/test_less.py | 131 -------- .../tensor/elementwise/test_less_equal.py | 131 -------- dpnp/tests/tensor/elementwise/test_log.py | 49 --- dpnp/tests/tensor/elementwise/test_log10.py | 51 --- dpnp/tests/tensor/elementwise/test_log1p.py | 49 --- dpnp/tests/tensor/elementwise/test_log2.py | 51 --- .../tensor/elementwise/test_logaddexp.py | 106 ------ .../tensor/elementwise/test_logical_and.py | 147 --------- .../tensor/elementwise/test_logical_not.py | 47 --- .../tensor/elementwise/test_logical_or.py | 146 --------- .../tensor/elementwise/test_logical_xor.py | 147 --------- .../elementwise/test_maximum_minimum.py | 139 -------- .../tests/tensor/elementwise/test_multiply.py | 112 ------- .../tests/tensor/elementwise/test_negative.py | 44 +-- .../tensor/elementwise/test_nextafter.py | 22 -- .../tensor/elementwise/test_not_equal.py | 132 -------- .../tests/tensor/elementwise/test_positive.py | 44 +-- dpnp/tests/tensor/elementwise/test_pow.py | 110 ------- .../tensor/elementwise/test_remainder.py | 87 ----- dpnp/tests/tensor/elementwise/test_round.py | 43 --- dpnp/tests/tensor/elementwise/test_sign.py | 42 --- dpnp/tests/tensor/elementwise/test_sqrt.py | 47 --- dpnp/tests/tensor/elementwise/test_square.py | 44 +-- .../tests/tensor/elementwise/test_subtract.py | 131 -------- .../tensor/elementwise/test_usm_types.py | 307 ++++++++++++++++++ 49 files changed, 369 insertions(+), 3364 deletions(-) create mode 100644 dpnp/tests/tensor/elementwise/test_usm_types.py diff --git a/dpnp/tests/tensor/elementwise/test_abs.py b/dpnp/tests/tensor/elementwise/test_abs.py index 535aebfb4d5..083be5d672d 100644 --- a/dpnp/tests/tensor/elementwise/test_abs.py +++ b/dpnp/tests/tensor/elementwise/test_abs.py @@ -27,8 +27,10 @@ # ***************************************************************************** import itertools +import re import warnings +import dpctl import numpy as np import pytest @@ -42,7 +44,6 @@ _all_dtypes, _complex_fp_dtypes, _real_fp_dtypes, - _usm_types, ) @@ -71,33 +72,6 @@ def test_abs_out_type(dtype): assert np.allclose(dpt.asnumpy(r), dpt.asnumpy(dpt.abs(X))) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_abs_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("i4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - Y = dpt.abs(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = dpt.asnumpy(X) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - -def test_abs_types_property(): - get_queue_or_skip() - types = dpt.abs.types - assert isinstance(types, list) - assert len(types) > 0 - assert types == dpt.abs.types_ - - @pytest.mark.parametrize("dtype", _all_dtypes[1:]) def test_abs_order(dtype): q = get_queue_or_skip() @@ -222,3 +196,44 @@ def test_abs_alignment(dtype): dpt.abs(x[:-1], out=r[1:]) assert np.allclose(dpt.asnumpy(r[1:]), dpt.asnumpy(r2)) + + +def test_abs_errors(): + q1 = get_queue_or_skip() + q2 = dpctl.SyclQueue() + + x = dpt.ones(2, dtype="float32", sycl_queue=q1) + y = dpt.empty_like(x, sycl_queue=q2) + with pytest.raises(dpt.ExecutionPlacementError) as excinfo: + dpt.abs(x, out=y) + assert "Input and output allocation queues are not compatible" in str( + excinfo.value + ) + + x = dpt.ones(2, dtype="float32") + y = dpt.empty(3, dtype=x.dtype) + with pytest.raises(ValueError) as excinfo: + dpt.abs(x, out=y) + assert "The shape of input and output arrays are inconsistent" in str( + excinfo.value + ) + + x = np.ones(2, dtype="float32") + with pytest.raises(TypeError) as excinfo: + dpt.abs(x) + assert re.match( + "Expected dpnp.tensor.usm_ndarray, got.*", + str(excinfo.value), + ) + + x = dpt.ones(2, dtype="float32") + y = np.empty(x.shape, dtype=x.dtype) + with pytest.raises(TypeError) as excinfo: + dpt.abs(x, out=y) + assert "output array must be of usm_ndarray type" in str(excinfo.value) + + x = dpt.ones(5, dtype="f4") + y = dpt.zeros_like(x, dtype="int8") + with pytest.raises(ValueError) as excinfo: + dpt.abs(x, out=y) + assert re.match("Output array of type.*is needed", str(excinfo.value)) diff --git a/dpnp/tests/tensor/elementwise/test_add.py b/dpnp/tests/tensor/elementwise/test_add.py index 28a4efb21e9..ce94d863384 100644 --- a/dpnp/tests/tensor/elementwise/test_add.py +++ b/dpnp/tests/tensor/elementwise/test_add.py @@ -43,7 +43,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -89,21 +88,6 @@ def test_add_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r2) == np.full(r2.shape, 2, dtype=r2.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_add_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.add(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - def test_add_order(): get_queue_or_skip() @@ -283,23 +267,17 @@ def test_add_types_property(): def test_add_errors(): - get_queue_or_skip() - try: - gpu_queue = dpctl.SyclQueue("gpu") - except dpctl.SyclQueueCreationError: - pytest.skip("SyclQueue('gpu') failed, skipping") - try: - cpu_queue = dpctl.SyclQueue("cpu") - except dpctl.SyclQueueCreationError: - pytest.skip("SyclQueue('cpu') failed, skipping") - - ar1 = dpt.ones(2, dtype="float32", sycl_queue=gpu_queue) - ar2 = dpt.ones_like(ar1, sycl_queue=gpu_queue) - y = dpt.empty_like(ar1, sycl_queue=cpu_queue) + q1 = get_queue_or_skip() + q2 = dpctl.SyclQueue() + + ar1 = dpt.ones(2, dtype="float32", sycl_queue=q1) + ar2 = dpt.ones_like(ar1, dtype="float32", sycl_queue=q2) + y = dpt.empty_like(ar1, sycl_queue=q2) with pytest.raises(dpt.ExecutionPlacementError) as excinfo: dpt.add(ar1, ar2, out=y) - assert "Input and output allocation queues are not compatible" in str( - excinfo.value + assert re.match( + "Execution placement can not be unambiguously inferred.*", + str(excinfo.value), ) ar1 = dpt.ones(2, dtype="float32") @@ -327,17 +305,8 @@ def test_add_errors(): dpt.add(ar1, ar2, out=y) assert "output array must be of usm_ndarray type" in str(excinfo.value) - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_add_dtype_error( - dtype, -): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - ar1 = dpt.ones(5, dtype=dtype) + ar1 = dpt.ones(5, dtype="f4") ar2 = dpt.ones_like(ar1, dtype="f4") - y = dpt.zeros_like(ar1, dtype="int8") with pytest.raises(ValueError) as excinfo: dpt.add(ar1, ar2, out=y) @@ -469,39 +438,12 @@ def test_add_inplace_operator_mutual_broadcast(): def test_add_inplace_errors(): - get_queue_or_skip() - try: - gpu_queue = dpctl.SyclQueue("gpu") - except dpctl.SyclQueueCreationError: - pytest.skip("SyclQueue('gpu') failed, skipping") - try: - cpu_queue = dpctl.SyclQueue("cpu") - except dpctl.SyclQueueCreationError: - pytest.skip("SyclQueue('cpu') failed, skipping") - - ar1 = dpt.ones(2, dtype="float32", sycl_queue=gpu_queue) - ar2 = dpt.ones_like(ar1, sycl_queue=cpu_queue) - with pytest.raises(dpt.ExecutionPlacementError): - dpt.add(ar1, ar2, out=ar1) - - ar1 = dpt.ones(2, dtype="float32") - ar2 = dpt.ones(3, dtype="float32") - with pytest.raises(ValueError): - dpt.add(ar1, ar2, out=ar1) - - ar1 = np.ones(2, dtype="float32") - ar2 = dpt.ones(2, dtype="float32") - with pytest.raises(TypeError): - dpt.add(ar1, ar2, out=ar1) - - ar1 = dpt.ones(2, dtype="float32") - ar2 = {} - with pytest.raises(ValueError): - dpt.add(ar1, ar2, out=ar1) + q1 = get_queue_or_skip() + q2 = dpctl.SyclQueue() - ar1 = dpt.ones((2, 1), dtype="float32") - ar2 = dpt.ones((1, 2), dtype="float32") - with pytest.raises(ValueError): + ar1 = dpt.ones(2, dtype="float32", sycl_queue=q1) + ar2 = dpt.ones_like(ar1, sycl_queue=q2) + with pytest.raises(dpt.ExecutionPlacementError): dpt.add(ar1, ar2, out=ar1) diff --git a/dpnp/tests/tensor/elementwise/test_atan2.py b/dpnp/tests/tensor/elementwise/test_atan2.py index 7a7bb92cdd7..6b77bbcbc72 100644 --- a/dpnp/tests/tensor/elementwise/test_atan2.py +++ b/dpnp/tests/tensor/elementwise/test_atan2.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - import numpy as np import pytest from numpy.testing import assert_allclose @@ -86,26 +84,6 @@ def test_atan2_dtype_matrix(op1_dtype, op2_dtype): assert_allclose(dpt.asnumpy(r), expected, atol=tol, rtol=tol) -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes[1:]) -def test_atan2_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.atan2(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.atan2(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - @pytest.mark.parametrize("dt", ["f2", "f4", "f8"]) def test_atan2_special_case_one_nan(dt): """If either x1_i or x2_i is NaN, the result is NaN.""" @@ -212,7 +190,7 @@ def test_atan2_special_case_pzero_and_nzero(dt): @pytest.mark.parametrize("dt", ["f2", "f4", "f8"]) -def test_atan2_special_case_pzero_and_negatvie(dt): +def test_atan2_special_case_pzero_and_negative(dt): """ If x1_i is +0 and x2_i is less than 0, the result is an approximation to +pi. diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_and.py b/dpnp/tests/tensor/elementwise/test_bitwise_and.py index c9172cb9d7d..739a84b9803 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_and.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_and.py @@ -103,18 +103,6 @@ def test_bitwise_and_bool(): assert dpt.all(dpt.equal(r_bw, r_lo)) -@pytest.mark.parametrize("dtype", ["?"] + _integral_dtypes) -def test_bitwise_and_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind == "b": - X &= False - else: - X &= int(0) - - @pytest.mark.parametrize("op1_dtype", ["?"] + _integral_dtypes) @pytest.mark.parametrize("op2_dtype", ["?"] + _integral_dtypes) def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_invert.py b/dpnp/tests/tensor/elementwise/test_bitwise_invert.py index 2b7a7c3a6f9..76e45fded5d 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_invert.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_invert.py @@ -38,7 +38,6 @@ from .utils import ( _compare_dtypes, _integral_dtypes, - _usm_types, ) @@ -92,52 +91,6 @@ def test_bitwise_invert_dtype_matrix(op_dtype): assert dpt.all(dpt.equal(r, r3)) -@pytest.mark.parametrize("op_usm_type", _usm_types) -def test_bitwise_invert_usm_type_matrix(op_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.asarray( - np.random.randint(0, 2, sz), dtype="i4", usm_type=op_usm_type - ) - - r = dpt.bitwise_invert(ar1) - assert isinstance(r, dpt.usm_ndarray) - assert r.usm_type == op_usm_type - - -def test_bitwise_invert_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.bitwise_invert(ar1, order="C") - assert r1.flags.c_contiguous - r2 = dpt.bitwise_invert(ar1, order="F") - assert r2.flags.f_contiguous - r3 = dpt.bitwise_invert(ar1, order="A") - assert r3.flags.c_contiguous - r4 = dpt.bitwise_invert(ar1, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.zeros((20, 20), dtype="i4", order="F") - r1 = dpt.bitwise_invert(ar1, order="C") - assert r1.flags.c_contiguous - r2 = dpt.bitwise_invert(ar1, order="F") - assert r2.flags.f_contiguous - r3 = dpt.bitwise_invert(ar1, order="A") - assert r3.flags.f_contiguous - r4 = dpt.bitwise_invert(ar1, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.bitwise_invert(ar1, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.zeros((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.bitwise_invert(ar1, order="K") - assert r4.strides == (-1, 20) - - def test_bitwise_invert_large_boolean(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_left_shift.py b/dpnp/tests/tensor/elementwise/test_bitwise_left_shift.py index bb68aab227a..df09a48582b 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_left_shift.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_left_shift.py @@ -115,14 +115,6 @@ def test_bitwise_left_shift_range(op_dtype): assert dpt.all(dpt.equal(z, 0)) -@pytest.mark.parametrize("dtype", _integral_dtypes) -def test_bitwise_left_shift_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - X <<= int(0) - - @pytest.mark.parametrize("op1_dtype", _integral_dtypes) @pytest.mark.parametrize("op2_dtype", _integral_dtypes) def test_bitwise_left_shift_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_or.py b/dpnp/tests/tensor/elementwise/test_bitwise_or.py index 0e1a5bfeab1..1d9ebf1ae9e 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_or.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_or.py @@ -103,18 +103,6 @@ def test_bitwise_or_bool(): assert dpt.all(dpt.equal(r_bw, r_lo)) -@pytest.mark.parametrize("dtype", ["?"] + _integral_dtypes) -def test_bitwise_or_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind == "b": - X |= False - else: - X |= int(0) - - @pytest.mark.parametrize("op1_dtype", ["?"] + _integral_dtypes) @pytest.mark.parametrize("op2_dtype", ["?"] + _integral_dtypes) def test_bitwise_or_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_right_shift.py b/dpnp/tests/tensor/elementwise/test_bitwise_right_shift.py index cdd2da9ba86..24ebd2e4bc0 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_right_shift.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_right_shift.py @@ -115,14 +115,6 @@ def test_bitwise_right_shift_range(op_dtype): assert dpt.all(dpt.equal(z, 0)) -@pytest.mark.parametrize("dtype", _integral_dtypes) -def test_bitwise_right_shift_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - X >>= int(0) - - @pytest.mark.parametrize("op1_dtype", _integral_dtypes) @pytest.mark.parametrize("op2_dtype", _integral_dtypes) def test_bitwise_right_shift_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_bitwise_xor.py b/dpnp/tests/tensor/elementwise/test_bitwise_xor.py index 60bc2c518e2..565edac2d41 100644 --- a/dpnp/tests/tensor/elementwise/test_bitwise_xor.py +++ b/dpnp/tests/tensor/elementwise/test_bitwise_xor.py @@ -103,18 +103,6 @@ def test_bitwise_xor_bool(): assert dpt.all(dpt.equal(r_bw, r_lo)) -@pytest.mark.parametrize("dtype", ["?"] + _integral_dtypes) -def test_bitwise_xor_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind == "b": - X ^= False - else: - X ^= int(0) - - @pytest.mark.parametrize("op1_dtype", ["?"] + _integral_dtypes) @pytest.mark.parametrize("op2_dtype", ["?"] + _integral_dtypes) def test_bitwise_xor_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_complex.py b/dpnp/tests/tensor/elementwise/test_complex.py index 2a006a7c519..d1c75056408 100644 --- a/dpnp/tests/tensor/elementwise/test_complex.py +++ b/dpnp/tests/tensor/elementwise/test_complex.py @@ -42,7 +42,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -92,36 +91,6 @@ def test_complex_output(np_call, dpt_call, dtype): assert_allclose(dpt.asnumpy(Z), np_call(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize( - "np_call, dpt_call", - [(np.real, dpt.real), (np.imag, dpt.imag), (np.conj, dpt.conj)], -) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_complex_usm_type(np_call, dpt_call, usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("c8") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = np.pi / 6 + 1j * np.pi / 3 - X[..., 1::2] = np.pi / 3 + 1j * np.pi / 6 - - Y = dpt_call(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - X_np = np.empty(input_shape, dtype=arg_dt) - X_np[..., 0::2] = np.complex64(np.pi / 6 + 1j * np.pi / 3) - X_np[..., 1::2] = np.complex64(np.pi / 3 + 1j * np.pi / 6) - - expected_Y = np_call(X_np) - - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - @pytest.mark.parametrize( "np_call, dpt_call", [(np.real, dpt.real), (np.imag, dpt.imag), (np.conj, dpt.conj)], diff --git a/dpnp/tests/tensor/elementwise/test_copysign.py b/dpnp/tests/tensor/elementwise/test_copysign.py index f9ec5345d25..ef5c48cbbe2 100644 --- a/dpnp/tests/tensor/elementwise/test_copysign.py +++ b/dpnp/tests/tensor/elementwise/test_copysign.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - import numpy as np import pytest @@ -78,26 +76,6 @@ def test_copysign_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("arr_dt", _real_fp_dtypes) -def test_copysign_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.copysign(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.copysign(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - @pytest.mark.parametrize("dt", _real_fp_dtypes) def test_copysign(dt): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_divide.py b/dpnp/tests/tensor/elementwise/test_divide.py index 99de5a51214..adedb847116 100644 --- a/dpnp/tests/tensor/elementwise/test_divide.py +++ b/dpnp/tests/tensor/elementwise/test_divide.py @@ -28,7 +28,6 @@ import ctypes -import dpctl import numpy as np import pytest from dpctl.utils import SequentialOrderManager @@ -44,9 +43,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _complex_fp_dtypes, - _real_fp_dtypes, - _usm_types, ) @@ -84,77 +80,6 @@ def test_divide_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_divide_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.divide(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_divide_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.divide(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.divide(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.divide(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.divide(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.divide(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.divide(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.divide(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.divide(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.divide(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.divide(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_divide_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.divide(m, v) - - expected = np.divide( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.divide(v, m) - expected2 = np.divide( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - @pytest.mark.parametrize("arr_dt", _all_dtypes) def test_divide_python_scalar(arr_dt): q = get_queue_or_skip() @@ -176,53 +101,6 @@ def test_divide_python_scalar(arr_dt): assert isinstance(R, dpt.usm_ndarray) -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_divide_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.divide(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_divide_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.divide(a, c) - - -@pytest.mark.parametrize("dtype", _real_fp_dtypes + _complex_fp_dtypes) -def test_divide_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind == "f": - X /= float(1) - elif dt_kind == "c": - X /= complex(1) - - @pytest.mark.parametrize("op1_dtype", _all_dtypes) @pytest.mark.parametrize("op2_dtype", _all_dtypes) def test_divide_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_equal.py b/dpnp/tests/tensor/elementwise/test_equal.py index f5e0cd52076..18043c4d3bb 100644 --- a/dpnp/tests/tensor/elementwise/test_equal.py +++ b/dpnp/tests/tensor/elementwise/test_equal.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -77,131 +73,3 @@ def test_equal_dtype_matrix(op1_dtype, op2_dtype): assert _compare_dtypes(r.dtype, expected_dtype, sycl_queue=q) assert r.shape == ar3.shape assert (dpt.asnumpy(r) == np.full(r.shape, True, dtype=r.dtype)).all() - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_equal_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.equal(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_equal_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.equal(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.equal(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.equal(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.equal(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.equal(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.equal(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_equal_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(5, dtype="i4") - - r = dpt.equal(m, v) - expected = np.full((100, 5), [False, True, False, False, False], dtype="?") - - assert (dpt.asnumpy(r) == expected).all() - - r2 = dpt.equal(v, m) - assert (dpt.asnumpy(r2) == expected).all() - - r3 = dpt.empty_like(m, dtype="?") - dpt.equal(m, v, out=r3) - assert (dpt.asnumpy(r3) == expected).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_equal_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) - py_zeros = ( - bool(0), - int(0), - float(0), - complex(0), - np.float32(0), - ctypes.c_int(0), - ) - for sc in py_zeros: - R = dpt.equal(X, sc) - assert isinstance(R, dpt.usm_ndarray) - assert dpt.all(R) - R = dpt.equal(sc, X) - assert isinstance(R, dpt.usm_ndarray) - assert dpt.all(R) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_equal_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.equal(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_equal_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.equal(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_exp.py b/dpnp/tests/tensor/elementwise/test_exp.py index ca204128317..64ffa408e34 100644 --- a/dpnp/tests/tensor/elementwise/test_exp.py +++ b/dpnp/tests/tensor/elementwise/test_exp.py @@ -41,7 +41,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -108,52 +107,6 @@ def test_exp_complex_contig(dtype): ) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_exp_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 16.0 - X[..., 1::2] = 23.0 - - Y = dpt.exp(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.exp(np.float32(16.0)) - expected_Y[..., 1::2] = np.exp(np.float32(23.0)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_exp_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 8.0 - X[..., 1::2] = 11.0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.exp(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.exp(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_exp_analytical_values(dtype): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_exp2.py b/dpnp/tests/tensor/elementwise/test_exp2.py index ae2ab43c39b..6c518be0ccd 100644 --- a/dpnp/tests/tensor/elementwise/test_exp2.py +++ b/dpnp/tests/tensor/elementwise/test_exp2.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_allclose @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -88,52 +85,6 @@ def test_exp2_output_strided(dtype): assert_allclose(dpt.asnumpy(Y), np.exp2(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_exp2_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 / 4 - X[..., 1::2] = 1 / 2 - - Y = dpt.exp2(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.exp2(np.float32(1 / 4)) - expected_Y[..., 1::2] = np.exp2(np.float32(1 / 2)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_exp2_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 1 / 4 - X[..., 1::2] = 1 / 2 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.exp2(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.exp2(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - def test_exp2_special_cases(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_expm1.py b/dpnp/tests/tensor/elementwise/test_expm1.py index bb665c42456..49d0445cf9c 100644 --- a/dpnp/tests/tensor/elementwise/test_expm1.py +++ b/dpnp/tests/tensor/elementwise/test_expm1.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_allclose @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -88,52 +85,6 @@ def test_expm1_output_strided(dtype): assert_allclose(dpt.asnumpy(Y), np.expm1(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_expm1_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 / 50 - X[..., 1::2] = 1 / 25 - - Y = dpt.expm1(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.expm1(np.float32(1 / 50)) - expected_Y[..., 1::2] = np.expm1(np.float32(1 / 25)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_expm1_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 1 / 50 - X[..., 1::2] = 1 / 25 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.expm1(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.expm1(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - def test_expm1_special_cases(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_floor_ceil_trunc.py b/dpnp/tests/tensor/elementwise/test_floor_ceil_trunc.py index f9af864b29f..c6c496b9a52 100644 --- a/dpnp/tests/tensor/elementwise/test_floor_ceil_trunc.py +++ b/dpnp/tests/tensor/elementwise/test_floor_ceil_trunc.py @@ -26,7 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools import re import numpy as np @@ -66,47 +65,6 @@ def test_floor_ceil_trunc_out_type(dpt_call, dtype): assert_allclose(dpt.asnumpy(dpt_call(X)), dpt.asnumpy(Y)) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("usm_type", ["device", "shared", "host"]) -def test_floor_ceil_trunc_usm_type(np_call, dpt_call, usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = -0.4 - X[..., 1::2] = 0.7 - - Y = dpt_call(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np_call(dpt.asnumpy(X)) - tol = 8 * dpt.finfo(Y.dtype).resolution - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", _no_complex_dtypes) -def test_floor_ceil_trunc_order(np_call, dpt_call, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (4, 4, 4, 4) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = -0.4 - X[..., 1::2] = 0.7 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np_call(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt_call(U, order=ord) - assert_allclose(dpt.asnumpy(Y), expected_Y) - - @pytest.mark.parametrize("dpt_call", [dpt.floor, dpt.ceil, dpt.trunc]) @pytest.mark.parametrize("dtype", _real_value_dtypes) def test_floor_ceil_trunc_error_dtype(dpt_call, dtype): diff --git a/dpnp/tests/tensor/elementwise/test_floor_divide.py b/dpnp/tests/tensor/elementwise/test_floor_divide.py index 5762b09afdb..352f7166594 100644 --- a/dpnp/tests/tensor/elementwise/test_floor_divide.py +++ b/dpnp/tests/tensor/elementwise/test_floor_divide.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -43,7 +40,6 @@ _compare_dtypes, _integral_dtypes, _no_complex_dtypes, - _usm_types, ) @@ -81,132 +77,6 @@ def test_floor_divide_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_floor_divide_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.floor_divide(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_floor_divide_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.floor_divide(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.floor_divide(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.floor_divide(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.floor_divide(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.floor_divide(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.floor_divide(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.floor_divide(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.floor_divide(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.floor_divide(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.floor_divide(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_floor_divide_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.floor_divide(m, v) - - expected = np.floor_divide( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.floor_divide(v, m) - expected2 = np.floor_divide( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes[1:]) -def test_floor_divide_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.floor_divide(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.floor_divide(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_floor_divide_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.floor_divide(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_floor_divide_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.floor_divide(a, c) - - def test_floor_divide_gh_1247(): get_queue_or_skip() @@ -276,18 +146,6 @@ def test_floor_divide_special_cases(): np.testing.assert_array_equal(dpt.asnumpy(res), res_np) -@pytest.mark.parametrize("dtype", _no_complex_dtypes[1:]) -def test_divide_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind in "ui": - X //= int(1) - elif dt_kind == "f": - X //= float(1) - - @pytest.mark.parametrize("op1_dtype", _no_complex_dtypes[1:]) @pytest.mark.parametrize("op2_dtype", _no_complex_dtypes[1:]) def test_floor_divide_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_greater.py b/dpnp/tests/tensor/elementwise/test_greater.py index eb5f2b3929d..21a737d7e66 100644 --- a/dpnp/tests/tensor/elementwise/test_greater.py +++ b/dpnp/tests/tensor/elementwise/test_greater.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -155,133 +151,6 @@ def test_greater_complex_float(): assert (dpt.asnumpy(r3) == expected3).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_greater_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.greater(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_greater_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.greater(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.greater(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.greater(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.greater(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.greater(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.greater(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.greater(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.greater(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.greater(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.greater(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_greater_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.greater(m, v) - - expected = np.greater( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.greater(v, m) - expected2 = np.greater( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_greater_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.greater(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.greater(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_greater_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.greater(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_greater_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.greater(a, c) - - def test_greater_mixed_integer_kinds(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_greater_equal.py b/dpnp/tests/tensor/elementwise/test_greater_equal.py index f2e97bf6218..f4eaa844c4d 100644 --- a/dpnp/tests/tensor/elementwise/test_greater_equal.py +++ b/dpnp/tests/tensor/elementwise/test_greater_equal.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -153,133 +149,6 @@ def test_greater_equal_complex_float(): assert (dpt.asnumpy(r3) == expected3).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_greater_equal_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.greater_equal(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_greater_equal_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.greater_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.greater_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.greater_equal(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.greater_equal(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.greater_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.greater_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.greater_equal(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.greater_equal(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.greater_equal(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.greater_equal(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_greater_equal_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.greater_equal(m, v) - - expected = np.greater_equal( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.greater_equal(v, m) - expected2 = np.greater_equal( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_greater_equal_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.greater_equal(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.greater_equal(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_greater_equal_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.greater_equal(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_greater_equal_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.greater_equal(a, c) - - def test_greater_equal_mixed_integer_kinds(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_hypot.py b/dpnp/tests/tensor/elementwise/test_hypot.py index bc87736318e..e74e00c45fc 100644 --- a/dpnp/tests/tensor/elementwise/test_hypot.py +++ b/dpnp/tests/tensor/elementwise/test_hypot.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _compare_dtypes, _no_complex_dtypes, - _usm_types, ) @@ -77,134 +73,3 @@ def test_hypot_dtype_matrix(op1_dtype, op2_dtype): assert _compare_dtypes(r.dtype, expected.dtype, sycl_queue=q) assert r.shape == ar3.shape assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_hypot_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.hypot(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_hypot_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.hypot(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.hypot(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.hypot(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.hypot(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.hypot(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.hypot(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.hypot(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.hypot(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.hypot(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.hypot(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_hypot_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.hypot(m, v) - - expected = np.hypot( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - tol = 8 * np.finfo(r.dtype).resolution - assert np.allclose( - dpt.asnumpy(r), expected.astype(r.dtype), atol=tol, rtol=tol - ) - - r2 = dpt.hypot(v, m) - expected2 = np.hypot( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert np.allclose( - dpt.asnumpy(r2), expected2.astype(r2.dtype), atol=tol, rtol=tol - ) - - -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes[1:]) -def test_hypot_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.hypot(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.hypot(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_hypot_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.hypot(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_hypot_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.hypot(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_isfinite.py b/dpnp/tests/tensor/elementwise/test_isfinite.py index f3a6664e691..a2d8cd10d24 100644 --- a/dpnp/tests/tensor/elementwise/test_isfinite.py +++ b/dpnp/tests/tensor/elementwise/test_isfinite.py @@ -26,11 +26,8 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest -from numpy.testing import assert_allclose import dpnp.tensor as dpt @@ -95,20 +92,3 @@ def test_isfinite_floats(dtype): r = dpt.empty_like(Y, dtype="bool") dpt.isfinite(Y, out=r) assert np.array_equal(dpt.asnumpy(r)[()], np.isfinite(Ynp)) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_isfinite_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.ones(input_shape, dtype=arg_dt, sycl_queue=q) - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[::2, ::-1, ::-1, ::5], perms) - expected_Y = np.full(U.shape, fill_value=True, dtype=dpt.bool) - for ord in ["C", "F", "A", "K"]: - Y = dpt.isfinite(U, order=ord) - assert_allclose(dpt.asnumpy(Y), expected_Y) diff --git a/dpnp/tests/tensor/elementwise/test_isinf.py b/dpnp/tests/tensor/elementwise/test_isinf.py index 91b2e942044..5ed8e25dc29 100644 --- a/dpnp/tests/tensor/elementwise/test_isinf.py +++ b/dpnp/tests/tensor/elementwise/test_isinf.py @@ -26,11 +26,8 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest -from numpy.testing import assert_allclose import dpnp.tensor as dpt @@ -89,20 +86,3 @@ def test_isinf_floats(dtype): Ynp = np.repeat(np.array([y1, y2, y3, y4], dtype=dtype), mult) Y = dpt.asarray(Ynp, sycl_queue=q) assert np.array_equal(dpt.asnumpy(dpt.isinf(Y)), np.isinf(Ynp)) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_isinf_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.ones(input_shape, dtype=arg_dt, sycl_queue=q) - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[::2, ::-1, ::-1, ::5], perms) - expected_Y = np.full(U.shape, fill_value=False, dtype=dpt.bool) - for ord in ["C", "F", "A", "K"]: - Y = dpt.isinf(U, order=ord) - assert_allclose(dpt.asnumpy(Y), expected_Y) diff --git a/dpnp/tests/tensor/elementwise/test_isnan.py b/dpnp/tests/tensor/elementwise/test_isnan.py index fe6f2660734..56799d9d5e1 100644 --- a/dpnp/tests/tensor/elementwise/test_isnan.py +++ b/dpnp/tests/tensor/elementwise/test_isnan.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest @@ -94,20 +92,3 @@ def test_isnan_floats(dtype): r = dpt.empty_like(Y, dtype="bool") dpt.isnan(Y, out=r) assert np.array_equal(dpt.asnumpy(r)[()], np.isnan(Ynp)) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_isnan_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.ones(input_shape, dtype=arg_dt, sycl_queue=q) - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[::2, ::-1, ::-1, ::5], perms) - expected_Y = np.full(U.shape, fill_value=False, dtype=dpt.bool) - for ord in ["C", "F", "A", "K"]: - Y = dpt.isnan(U, order=ord) - assert np.allclose(dpt.asnumpy(Y), expected_Y) diff --git a/dpnp/tests/tensor/elementwise/test_less.py b/dpnp/tests/tensor/elementwise/test_less.py index 0abf1e44064..2d212f66d1e 100644 --- a/dpnp/tests/tensor/elementwise/test_less.py +++ b/dpnp/tests/tensor/elementwise/test_less.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -155,133 +151,6 @@ def test_less_complex_float(): assert (dpt.asnumpy(r3) == expected3).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_less_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.less(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_less_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.less(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.less(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.less(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.less(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.less(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.less(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.less(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.less(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.less(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.less(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_less_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.less(m, v) - - expected = np.less( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.less(v, m) - expected2 = np.less( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_less_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.less(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.less(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_less_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.less(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_less_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.less(a, c) - - def test_less_mixed_integer_kinds(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_less_equal.py b/dpnp/tests/tensor/elementwise/test_less_equal.py index 1a574447521..bca5158c60a 100644 --- a/dpnp/tests/tensor/elementwise/test_less_equal.py +++ b/dpnp/tests/tensor/elementwise/test_less_equal.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -154,133 +150,6 @@ def test_less_equal_complex_float(): assert (dpt.asnumpy(r3) == expected3).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_less_equal_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.less_equal(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_less_equal_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.less_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.less_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.less_equal(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.less_equal(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.less_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.less_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.less_equal(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.less_equal(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.less_equal(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.less_equal(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_less_equal_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.less_equal(m, v) - - expected = np.less_equal( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.less_equal(v, m) - expected2 = np.less_equal( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_less_equal_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.less_equal(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.less_equal(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_less_equal_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.less_equal(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_less_equal_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.less_equal(a, c) - - def test_less_equal_mixed_integer_kinds(): get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_log.py b/dpnp/tests/tensor/elementwise/test_log.py index b41fa85df05..f218eb6d996 100644 --- a/dpnp/tests/tensor/elementwise/test_log.py +++ b/dpnp/tests/tensor/elementwise/test_log.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_allclose, assert_equal @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -88,52 +85,6 @@ def test_log_output_strided(dtype): assert_allclose(dpt.asnumpy(Y), np.log(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_log_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - Y = dpt.log(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.log(np.float32(4 * dpt.e)) - expected_Y[..., 1::2] = np.log(np.float32(10 * dpt.e)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_log_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.log(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.log(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - def test_log_special_cases(): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_log10.py b/dpnp/tests/tensor/elementwise/test_log10.py index 02c652293b9..d9e591d4ce7 100644 --- a/dpnp/tests/tensor/elementwise/test_log10.py +++ b/dpnp/tests/tensor/elementwise/test_log10.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_equal @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -92,54 +89,6 @@ def test_log_output_strided(dtype): ) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_log_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - Y = dpt.log10(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.log10(np.float32(4 * dpt.e)) - expected_Y[..., 1::2] = np.log10(np.float32(10 * dpt.e)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - np.testing.assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_log_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.log10(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.log10(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - np.testing.assert_allclose( - dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol - ) - - def test_log_special_cases(): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_log1p.py b/dpnp/tests/tensor/elementwise/test_log1p.py index eb6205650e1..769e10cc333 100644 --- a/dpnp/tests/tensor/elementwise/test_log1p.py +++ b/dpnp/tests/tensor/elementwise/test_log1p.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_allclose @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -88,52 +85,6 @@ def test_log1p_output_strided(dtype): assert_allclose(dpt.asnumpy(Y), np.log1p(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_log1p_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = dpt.e / 1000 - X[..., 1::2] = dpt.e / 100 - - Y = dpt.log1p(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.log1p(np.float32(dpt.e / 1000)) - expected_Y[..., 1::2] = np.log1p(np.float32(dpt.e / 100)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_log1p_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = dpt.e / 1000 - X[..., 1::2] = dpt.e / 100 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.log1p(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.log1p(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - def test_log1p_special_cases(): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_log2.py b/dpnp/tests/tensor/elementwise/test_log2.py index 7cd2f461513..dd622932dfc 100644 --- a/dpnp/tests/tensor/elementwise/test_log2.py +++ b/dpnp/tests/tensor/elementwise/test_log2.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest from numpy.testing import assert_equal @@ -41,7 +39,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -88,54 +85,6 @@ def test_log_output_strided(dtype): np.testing.assert_allclose(dpt.asnumpy(Y), np.log2(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_log_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - Y = dpt.log2(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.log2(np.float32(4 * dpt.e)) - expected_Y[..., 1::2] = np.log2(np.float32(10 * dpt.e)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - np.testing.assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_log_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 4 * dpt.e - X[..., 1::2] = 10 * dpt.e - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.log2(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.log2(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - np.testing.assert_allclose( - dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol - ) - - def test_log_special_cases(): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_logaddexp.py b/dpnp/tests/tensor/elementwise/test_logaddexp.py index fc16c1722d9..3f9ff5bbf79 100644 --- a/dpnp/tests/tensor/elementwise/test_logaddexp.py +++ b/dpnp/tests/tensor/elementwise/test_logaddexp.py @@ -26,10 +26,8 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes import re -import dpctl import numpy as np import pytest from numpy.testing import assert_allclose @@ -43,7 +41,6 @@ from .utils import ( _compare_dtypes, _no_complex_dtypes, - _usm_types, ) @@ -84,89 +81,6 @@ def test_logaddexp_dtype_matrix(op1_dtype, op2_dtype): ) -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_logaddexp_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.logaddexp(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_logaddexp_order(): - get_queue_or_skip() - - test_shape = ( - 20, - 20, - ) - test_shape2 = tuple(2 * dim for dim in test_shape) - n = test_shape[-1] - - for dt1, dt2 in zip(["i4", "i4", "f4"], ["i4", "f4", "i4"]): - ar1 = dpt.ones(test_shape, dtype=dt1, order="C") - ar2 = dpt.ones(test_shape, dtype=dt2, order="C") - r1 = dpt.logaddexp(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logaddexp(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logaddexp(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.logaddexp(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones(test_shape, dtype=dt1, order="F") - ar2 = dpt.ones(test_shape, dtype=dt2, order="F") - r1 = dpt.logaddexp(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logaddexp(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logaddexp(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.logaddexp(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2] - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2] - r4 = dpt.logaddexp(ar1, ar2, order="K") - assert r4.strides == (n, -1) - r5 = dpt.logaddexp(ar1, ar2, order="C") - assert r5.strides == (n, 1) - - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2].mT - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2].mT - r4 = dpt.logaddexp(ar1, ar2, order="K") - assert r4.strides == (-1, n) - r5 = dpt.logaddexp(ar1, ar2, order="C") - assert r5.strides == (n, 1) - - -def test_logaddexp_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.logaddexp(m, v) - - expected = np.logaddexp( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.logaddexp(v, m) - expected2 = np.logaddexp( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - def test_logaddexp_broadcasting_error(): get_queue_or_skip() m = dpt.ones((10, 10), dtype="i4") @@ -175,26 +89,6 @@ def test_logaddexp_broadcasting_error(): dpt.logaddexp(m, v) -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes) -def test_logaddexp_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) - py_zeros = ( - bool(0), - int(0), - float(0), - np.float32(0), - ctypes.c_int(0), - ) - for sc in py_zeros: - R = dpt.logaddexp(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.logaddexp(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - @pytest.mark.parametrize("dtype", _no_complex_dtypes) def test_logaddexp_dtype_error( dtype, diff --git a/dpnp/tests/tensor/elementwise/test_logical_and.py b/dpnp/tests/tensor/elementwise/test_logical_and.py index 09f5838265a..e210229bcbe 100644 --- a/dpnp/tests/tensor/elementwise/test_logical_and.py +++ b/dpnp/tests/tensor/elementwise/test_logical_and.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -176,146 +172,3 @@ def test_logical_and_complex_float(): r3 = dpt.logical_and(ar3, ar1) expected3 = np.logical_and(ar3_np, ar1_np) assert (dpt.asnumpy(r3) == expected3).all() - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_logical_and_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.asarray( - np.random.randint(0, 2, sz), dtype="i4", usm_type=op1_usm_type - ) - ar2 = dpt.asarray( - np.random.randint(0, 2, sz), dtype=ar1.dtype, usm_type=op2_usm_type - ) - - r = dpt.logical_and(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_logical_and_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.logical_and(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_and(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_and(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.logical_and(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.logical_and(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_and(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_and(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.logical_and(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.logical_and(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.logical_and(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_logical_and_broadcasting(): - get_queue_or_skip() - - m = dpt.asarray(np.random.randint(0, 2, (100, 5)), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.logical_and(m, v) - - expected = np.logical_and(dpt.asnumpy(m), dpt.asnumpy(v)) - assert (dpt.asnumpy(r) == expected).all() - - r2 = dpt.logical_and(v, m) - expected2 = np.logical_and(dpt.asnumpy(v), dpt.asnumpy(m)) - assert (dpt.asnumpy(r2) == expected2).all() - - r3 = dpt.empty_like(r) - dpt.logical_and(m, v, out=r3) - assert (dpt.asnumpy(r3) == expected).all() - - r4 = dpt.empty_like(r) - dpt.logical_and(v, m, out=r4) - assert (dpt.asnumpy(r4) == expected).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -@pytest.mark.parametrize("scalar_val", [0, 1]) -def test_logical_and_python_scalar(arr_dt, scalar_val): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.asarray( - np.random.randint(0, 2, (10, 10)), dtype=arr_dt, sycl_queue=q - ) - py_ones = ( - bool(scalar_val), - int(scalar_val), - float(scalar_val), - complex(scalar_val), - np.float32(scalar_val), - ctypes.c_int(scalar_val), - ) - for sc in py_ones: - R = dpt.logical_and(X, sc) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_and(dpt.asnumpy(X), sc) - assert (dpt.asnumpy(R) == E).all() - - R = dpt.logical_and(sc, X) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_and(sc, dpt.asnumpy(X)) - assert (dpt.asnumpy(R) == E).all() - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_logical_and_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.logical_and(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_logical_and_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.logical_and(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_logical_not.py b/dpnp/tests/tensor/elementwise/test_logical_not.py index fa1d5e786bd..65fa65db416 100644 --- a/dpnp/tests/tensor/elementwise/test_logical_not.py +++ b/dpnp/tests/tensor/elementwise/test_logical_not.py @@ -38,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -150,49 +149,3 @@ def test_logical_not_complex_float(): r2 = dpt.logical_not(ar2) expected2 = np.logical_not(dpt.asnumpy(ar2)) assert (dpt.asnumpy(r2) == expected2).all() - - -@pytest.mark.parametrize("op_usm_type", _usm_types) -def test_logical_not_usm_type_matrix(op_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.asarray( - np.random.randint(0, 2, sz), dtype="i4", usm_type=op_usm_type - ) - - r = dpt.logical_not(ar1) - assert isinstance(r, dpt.usm_ndarray) - assert r.usm_type == op_usm_type - - -def test_logical_not_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.logical_not(ar1, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_not(ar1, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_not(ar1, order="A") - assert r3.flags.c_contiguous - r4 = dpt.logical_not(ar1, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.zeros((20, 20), dtype="i4", order="F") - r1 = dpt.logical_not(ar1, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_not(ar1, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_not(ar1, order="A") - assert r3.flags.f_contiguous - r4 = dpt.logical_not(ar1, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.logical_not(ar1, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.zeros((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.logical_not(ar1, order="K") - assert r4.strides == (-1, 20) diff --git a/dpnp/tests/tensor/elementwise/test_logical_or.py b/dpnp/tests/tensor/elementwise/test_logical_or.py index 42c7e6f645b..44fd524ebd4 100644 --- a/dpnp/tests/tensor/elementwise/test_logical_or.py +++ b/dpnp/tests/tensor/elementwise/test_logical_or.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -177,146 +174,3 @@ def test_logical_or_complex_float(): r3 = dpt.logical_or(ar3, ar1) expected3 = np.logical_or(ar3_np, ar1_np) assert (dpt.asnumpy(r3) == expected3).all() - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_logical_or_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.asarray( - np.random.randint(0, 2, sz), dtype="i4", usm_type=op1_usm_type - ) - ar2 = dpt.asarray( - np.random.randint(0, 2, sz), dtype=ar1.dtype, usm_type=op2_usm_type - ) - - r = dpt.logical_or(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_logical_or_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.logical_or(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_or(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_or(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.logical_or(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.logical_or(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_or(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_or(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.logical_or(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.logical_or(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.logical_or(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_logical_or_broadcasting(): - get_queue_or_skip() - - m = dpt.asarray(np.random.randint(0, 2, (100, 5)), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.logical_or(m, v) - - expected = np.logical_or(dpt.asnumpy(m), dpt.asnumpy(v)) - assert (dpt.asnumpy(r) == expected).all() - - r2 = dpt.logical_or(v, m) - expected2 = np.logical_or(dpt.asnumpy(v), dpt.asnumpy(m)) - assert (dpt.asnumpy(r2) == expected2).all() - - r3 = dpt.empty_like(r) - dpt.logical_or(m, v, out=r3) - assert (dpt.asnumpy(r3) == expected).all() - - r4 = dpt.empty_like(r) - dpt.logical_or(v, m, out=r4) - assert (dpt.asnumpy(r4) == expected).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -@pytest.mark.parametrize("scalar_val", [0, 1]) -def test_logical_or_python_scalar(arr_dt, scalar_val): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.asarray( - np.random.randint(0, 2, (10, 10)), dtype=arr_dt, sycl_queue=q - ) - py_ones = ( - bool(scalar_val), - int(scalar_val), - float(scalar_val), - complex(scalar_val), - np.float32(scalar_val), - ctypes.c_int(scalar_val), - ) - for sc in py_ones: - R = dpt.logical_or(X, sc) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_or(dpt.asnumpy(X), sc) - assert (dpt.asnumpy(R) == E).all() - - R = dpt.logical_or(sc, X) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_or(sc, dpt.asnumpy(X)) - assert (dpt.asnumpy(R) == E).all() - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_logical_or_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.logical_or(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_logical_or_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.logical_or(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_logical_xor.py b/dpnp/tests/tensor/elementwise/test_logical_xor.py index da2b79974f1..43664d7ce20 100644 --- a/dpnp/tests/tensor/elementwise/test_logical_xor.py +++ b/dpnp/tests/tensor/elementwise/test_logical_xor.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -178,146 +174,3 @@ def test_logical_xor_complex_float(): r3 = dpt.logical_xor(ar3, ar1) expected3 = np.logical_xor(ar3_np, ar1_np) assert (dpt.asnumpy(r3) == expected3).all() - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_logical_xor_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.asarray( - np.random.randint(0, 2, sz), dtype="i4", usm_type=op1_usm_type - ) - ar2 = dpt.asarray( - np.random.randint(0, 2, sz), dtype=ar1.dtype, usm_type=op2_usm_type - ) - - r = dpt.logical_xor(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_logical_xor_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.logical_xor(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_xor(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_xor(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.logical_xor(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.logical_xor(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.logical_xor(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.logical_xor(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.logical_xor(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.logical_xor(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.logical_xor(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_logical_xor_broadcasting(): - get_queue_or_skip() - - m = dpt.asarray(np.random.randint(0, 2, (100, 5)), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.logical_xor(m, v) - - expected = np.logical_xor(dpt.asnumpy(m), dpt.asnumpy(v)) - assert (dpt.asnumpy(r) == expected).all() - - r2 = dpt.logical_xor(v, m) - expected2 = np.logical_xor(dpt.asnumpy(v), dpt.asnumpy(m)) - assert (dpt.asnumpy(r2) == expected2).all() - - r3 = dpt.empty_like(r) - dpt.logical_xor(m, v, out=r3) - assert (dpt.asnumpy(r3) == expected).all() - - r4 = dpt.empty_like(r) - dpt.logical_xor(v, m, out=r4) - assert (dpt.asnumpy(r4) == expected).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -@pytest.mark.parametrize("scalar_val", [0, 1]) -def test_logical_xor_python_scalar(arr_dt, scalar_val): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.asarray( - np.random.randint(0, 2, (10, 10)), dtype=arr_dt, sycl_queue=q - ) - py_ones = ( - bool(scalar_val), - int(scalar_val), - float(scalar_val), - complex(scalar_val), - np.float32(scalar_val), - ctypes.c_int(scalar_val), - ) - for sc in py_ones: - R = dpt.logical_xor(X, sc) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_xor(dpt.asnumpy(X), sc) - assert (dpt.asnumpy(R) == E).all() - - R = dpt.logical_xor(sc, X) - assert isinstance(R, dpt.usm_ndarray) - E = np.logical_xor(sc, dpt.asnumpy(X)) - assert (dpt.asnumpy(R) == E).all() - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_logical_xor_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.logical_xor(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_logical_xor_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.logical_xor(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_maximum_minimum.py b/dpnp/tests/tensor/elementwise/test_maximum_minimum.py index 2eb6d9de758..90671d8ae21 100644 --- a/dpnp/tests/tensor/elementwise/test_maximum_minimum.py +++ b/dpnp/tests/tensor/elementwise/test_maximum_minimum.py @@ -26,10 +26,8 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes import itertools -import dpctl import numpy as np import pytest from numpy.testing import assert_array_equal @@ -43,7 +41,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -191,139 +188,3 @@ def test_maximum_minimum_complex_special_cases(dtype): Rnp = np.minimum(Xnp, Ynp) assert_array_equal(dpt.asnumpy(dpt.real(R)), np.real(Rnp)) assert_array_equal(dpt.asnumpy(dpt.imag(R)), np.imag(Rnp)) - - -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_maximum_minimum_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1_np = np.arange(sz, dtype="i4") - np.random.shuffle(ar1_np) - ar1 = dpt.asarray(ar1_np, usm_type=op1_usm_type) - ar2_np = np.arange(sz, dtype="i4") - np.random.shuffle(ar2_np) - ar2 = dpt.asarray(ar2_np, usm_type=op2_usm_type) - - r = dpt.maximum(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - r = dpt.minimum(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_maximum_minimum_order(): - get_queue_or_skip() - - ar1_np = np.arange(20 * 20, dtype="i4").reshape(20, 20) - np.random.shuffle(ar1_np) - ar1 = dpt.asarray(ar1_np, order="C") - ar2_np = np.arange(20 * 20, dtype="i4").reshape(20, 20) - np.random.shuffle(ar2_np) - ar2 = dpt.asarray(ar2_np, order="C") - - r1 = dpt.maximum(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.maximum(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.maximum(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.maximum(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.asarray(ar1_np, order="F") - ar2 = dpt.asarray(ar2_np, order="F") - r1 = dpt.maximum(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.maximum(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.maximum(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.maximum(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1_np = np.arange(40 * 40, dtype="i4").reshape(40, 40) - np.random.shuffle(ar1_np) - ar1 = dpt.asarray(ar1_np, order="C")[:20, ::-2] - ar2_np = np.arange(40 * 40, dtype="i4").reshape(40, 40) - np.random.shuffle(ar2_np) - ar2 = dpt.asarray(ar2_np, order="C")[:20, ::-2] - r4 = dpt.maximum(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.asarray(ar1_np, order="C")[:20, ::-2].mT - ar2 = dpt.asarray(ar2_np, order="C")[:20, ::-2].mT - r4 = dpt.maximum(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_maximum_minimum_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.maximum(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.maximum(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - R = dpt.minimum(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.minimum(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_maximum_minimum_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.maximum(a, c) - assert isinstance(r, dpt.usm_ndarray) - - r = dpt.minimum(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_maximum_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.maximum(a, c) - - with pytest.raises(ValueError): - dpt.minimum(a, c) diff --git a/dpnp/tests/tensor/elementwise/test_multiply.py b/dpnp/tests/tensor/elementwise/test_multiply.py index 33dbef03f34..8a41471312d 100644 --- a/dpnp/tests/tensor/elementwise/test_multiply.py +++ b/dpnp/tests/tensor/elementwise/test_multiply.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -42,7 +39,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -80,98 +76,6 @@ def test_multiply_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_multiply_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.multiply(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_multiply_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.multiply(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.multiply(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.multiply(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.multiply(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.multiply(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.multiply(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.multiply(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.multiply(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.multiply(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.multiply(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_multiply_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(1, 6, dtype="i4") - - r = dpt.multiply(m, v) - - expected = np.multiply( - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.multiply(v, m) - expected2 = np.multiply( - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_multiply_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.multiply(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.multiply(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - @pytest.mark.parametrize("arr_dt", _all_dtypes) @pytest.mark.parametrize("sc", [bool(1), int(1), float(1), complex(1)]) def test_multiply_python_scalar_gh1219(arr_dt, sc): @@ -192,22 +96,6 @@ def test_multiply_python_scalar_gh1219(arr_dt, sc): assert _compare_dtypes(R.dtype, Rnp.dtype, sycl_queue=q) -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_multiply_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.ones((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind in "ui": - X *= int(1) - elif dt_kind == "f": - X *= float(1) - elif dt_kind == "c": - X *= complex(1) - elif dt_kind == "b": - X *= bool(1) - - @pytest.mark.parametrize("op1_dtype", _all_dtypes) @pytest.mark.parametrize("op2_dtype", _all_dtypes) def test_multiply_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_negative.py b/dpnp/tests/tensor/elementwise/test_negative.py index 9713f0ecb36..7813acd767e 100644 --- a/dpnp/tests/tensor/elementwise/test_negative.py +++ b/dpnp/tests/tensor/elementwise/test_negative.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest @@ -37,7 +35,7 @@ get_queue_or_skip, skip_if_dtype_not_supported, ) -from .utils import _all_dtypes, _usm_types +from .utils import _all_dtypes @pytest.mark.parametrize("dtype", _all_dtypes[1:]) @@ -59,43 +57,3 @@ def test_negative_bool(): x = dpt.ones(64, dtype="?") with pytest.raises(ValueError): dpt.negative(x) - - -@pytest.mark.parametrize("usm_type", _usm_types) -def test_negative_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("i4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - Y = dpt.negative(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.negative(dpt.asnumpy(X)) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_negative_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.negative(np.ones(U.shape, dtype=U.dtype)) - expected_Y[..., 1::2] = 0 - expected_Y = np.transpose(expected_Y, perms) - for ord in ["C", "F", "A", "K"]: - Y = dpt.negative(U, order=ord) - assert np.allclose(dpt.asnumpy(Y), expected_Y) diff --git a/dpnp/tests/tensor/elementwise/test_nextafter.py b/dpnp/tests/tensor/elementwise/test_nextafter.py index b904bc42c6b..bf87147c254 100644 --- a/dpnp/tests/tensor/elementwise/test_nextafter.py +++ b/dpnp/tests/tensor/elementwise/test_nextafter.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - import dpctl import numpy as np import pytest @@ -78,26 +76,6 @@ def test_nextafter_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes[1:]) -def test_nextafter_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.nextafter(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.nextafter(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - @pytest.mark.parametrize("dt", ["f2", "f4", "f8"]) def test_nextafter_special_cases_nan(dt): """If either x1_i or x2_i is NaN, the result is NaN.""" diff --git a/dpnp/tests/tensor/elementwise/test_not_equal.py b/dpnp/tests/tensor/elementwise/test_not_equal.py index 3f0eb58cf8b..9f1db24b473 100644 --- a/dpnp/tests/tensor/elementwise/test_not_equal.py +++ b/dpnp/tests/tensor/elementwise/test_not_equal.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -41,7 +38,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -79,134 +75,6 @@ def test_not_equal_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == np.full(r.shape, False, dtype=r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_not_equal_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.not_equal(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_not_equal_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.not_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.not_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.not_equal(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.not_equal(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.not_equal(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.not_equal(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.not_equal(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.not_equal(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.not_equal(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.not_equal(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_not_equal_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(5, dtype="i4") - - r = dpt.not_equal(m, v) - expected = np.full((100, 5), [True, False, True, True, True], dtype="?") - - assert (dpt.asnumpy(r) == expected).all() - - r2 = dpt.not_equal(v, m) - assert (dpt.asnumpy(r2) == expected).all() - - r3 = dpt.empty_like(m, dtype="?") - dpt.not_equal(m, v, out=r3) - assert (dpt.asnumpy(r3) == expected).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_not_equal_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) - py_zeros = ( - bool(0), - int(0), - float(0), - complex(0), - np.float32(0), - ctypes.c_int(0), - ) - for sc in py_zeros: - R = dpt.not_equal(X, sc) - assert isinstance(R, dpt.usm_ndarray) - assert not dpt.all(R) - R = dpt.not_equal(sc, X) - assert isinstance(R, dpt.usm_ndarray) - assert not dpt.all(R) - - -class MockArray: - def __init__(self, arr): - self.data_ = arr - - @property - def __sycl_usm_array_interface__(self): - return self.data_.__sycl_usm_array_interface__ - - -def test_not_equal_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - b = dpt.ones(10) - c = MockArray(b) - r = dpt.not_equal(a, c) - assert isinstance(r, dpt.usm_ndarray) - - -def test_not_equal_canary_mock_array(): - get_queue_or_skip() - a = dpt.arange(10) - - class Canary: - def __init__(self): - pass - - @property - def __sycl_usm_array_interface__(self): - return None - - c = Canary() - with pytest.raises(ValueError): - dpt.not_equal(a, c) - - @pytest.mark.parametrize("dtype", _all_dtypes) def test_not_equal_alignment(dtype): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_positive.py b/dpnp/tests/tensor/elementwise/test_positive.py index d4358e5827d..fa94d9ebe67 100644 --- a/dpnp/tests/tensor/elementwise/test_positive.py +++ b/dpnp/tests/tensor/elementwise/test_positive.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest @@ -37,7 +35,7 @@ get_queue_or_skip, skip_if_dtype_not_supported, ) -from .utils import _all_dtypes, _usm_types +from .utils import _all_dtypes @pytest.mark.parametrize("dtype", _all_dtypes[1:]) @@ -52,43 +50,3 @@ def test_positive_out_type(dtype): r = dpt.empty_like(X, dtype=arg_dt) dpt.positive(X, out=r) assert np.allclose(dpt.asnumpy(r), dpt.asnumpy(dpt.positive(X))) - - -@pytest.mark.parametrize("usm_type", _usm_types) -def test_positive_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("i4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - Y = dpt.positive(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = dpt.asnumpy(X) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_positive_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.ones(U.shape, dtype=U.dtype) - expected_Y[..., 1::2] = 0 - expected_Y = np.transpose(expected_Y, perms) - for ord in ["C", "F", "A", "K"]: - Y = dpt.positive(U, order=ord) - assert np.allclose(dpt.asnumpy(Y), expected_Y) diff --git a/dpnp/tests/tensor/elementwise/test_pow.py b/dpnp/tests/tensor/elementwise/test_pow.py index c68e6ad13b0..bd34d3d87ff 100644 --- a/dpnp/tests/tensor/elementwise/test_pow.py +++ b/dpnp/tests/tensor/elementwise/test_pow.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -42,7 +39,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -80,112 +76,6 @@ def test_power_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_power_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.pow(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_pow_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.pow(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.pow(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.pow(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.pow(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.pow(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.pow(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.pow(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.pow(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.pow(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.pow(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - -def test_pow_broadcasting(): - get_queue_or_skip() - - v = dpt.arange(1, 6, dtype="i4") - m = dpt.full((100, 5), 2, dtype="i4") - - r = dpt.pow(m, v) - - expected = np.power( - np.full((100, 5), 2, dtype="i4"), np.arange(1, 6, dtype="i4") - ) - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() - - r2 = dpt.pow(v, m) - expected2 = np.power( - np.arange(1, 6, dtype="i4"), np.full((100, 5), 2, dtype="i4") - ) - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes) -def test_pow_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - complex(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.pow(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.pow(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_pow_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.ones((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind in "ui": - X **= int(1) - elif dt_kind == "f": - X **= float(1) - elif dt_kind == "c": - X **= complex(1) - - @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) @pytest.mark.parametrize("op2_dtype", _all_dtypes[1:]) def test_pow_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_remainder.py b/dpnp/tests/tensor/elementwise/test_remainder.py index b8d5ca1cf8a..2d95003ffe3 100644 --- a/dpnp/tests/tensor/elementwise/test_remainder.py +++ b/dpnp/tests/tensor/elementwise/test_remainder.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -42,7 +39,6 @@ from .utils import ( _compare_dtypes, _no_complex_dtypes, - _usm_types, ) @@ -80,57 +76,6 @@ def test_remainder_dtype_matrix(op1_dtype, op2_dtype): assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_remainder_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.remainder(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_remainder_order(): - get_queue_or_skip() - - ar1 = dpt.ones((20, 20), dtype="i4", order="C") - ar2 = dpt.ones((20, 20), dtype="i4", order="C") - r1 = dpt.remainder(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.remainder(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.remainder(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.remainder(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones((20, 20), dtype="i4", order="F") - ar2 = dpt.ones((20, 20), dtype="i4", order="F") - r1 = dpt.remainder(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.remainder(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.remainder(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.remainder(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] - r4 = dpt.remainder(ar1, ar2, order="K") - assert r4.strides == (20, -1) - - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT - r4 = dpt.remainder(ar1, ar2, order="K") - assert r4.strides == (-1, 20) - - @pytest.mark.parametrize("dt", _no_complex_dtypes[1:8:2]) def test_remainder_negative_integers(dt): q = get_queue_or_skip() @@ -206,38 +151,6 @@ def test_remainder_special_cases(): np.allclose(dpt.asnumpy(res), np.remainder(x_np, y_np)) -@pytest.mark.parametrize("arr_dt", _no_complex_dtypes) -def test_remainder_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) - py_ones = ( - bool(1), - int(1), - float(1), - np.float32(1), - ctypes.c_int(1), - ) - for sc in py_ones: - R = dpt.remainder(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.remainder(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -@pytest.mark.parametrize("dtype", _no_complex_dtypes[1:]) -def test_remainder_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.ones((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind in "ui": - X %= int(1) - elif dt_kind == "f": - X %= float(1) - - @pytest.mark.parametrize("op1_dtype", _no_complex_dtypes[1:]) @pytest.mark.parametrize("op2_dtype", _no_complex_dtypes[1:]) def test_remainder_inplace_dtype_matrix(op1_dtype, op2_dtype): diff --git a/dpnp/tests/tensor/elementwise/test_round.py b/dpnp/tests/tensor/elementwise/test_round.py index 5cfcb6dd598..b8c140679f8 100644 --- a/dpnp/tests/tensor/elementwise/test_round.py +++ b/dpnp/tests/tensor/elementwise/test_round.py @@ -41,7 +41,6 @@ from .utils import ( _all_dtypes, _map_to_device_dtype, - _usm_types, ) @@ -106,48 +105,6 @@ def test_round_complex_contig(dtype): ) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_round_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 16.2 - X[..., 1::2] = 23.7 - - Y = dpt.round(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.round(np.float32(16.2)) - expected_Y[..., 1::2] = np.round(np.float32(23.7)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_round_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 8.8 - X[..., 1::2] = 11.3 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.round(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.round(U, order=ord) - assert_allclose(dpt.asnumpy(Y), expected_Y) - - @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_round_real_special_cases(dtype): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_sign.py b/dpnp/tests/tensor/elementwise/test_sign.py index e2addb23b71..a303cbd5e06 100644 --- a/dpnp/tests/tensor/elementwise/test_sign.py +++ b/dpnp/tests/tensor/elementwise/test_sign.py @@ -40,7 +40,6 @@ from .utils import ( _all_dtypes, _no_complex_dtypes, - _usm_types, ) @@ -58,47 +57,6 @@ def test_sign_out_type(dtype): assert np.allclose(dpt.asnumpy(r), dpt.asnumpy(dpt.sign(X))) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_sign_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("i4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - Y = dpt.sign(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = dpt.asnumpy(X) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_sign_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - expected_dt = np.sign(np.ones(tuple(), dtype=arg_dt)).dtype - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.ones(U.shape, dtype=expected_dt) - expected_Y[..., 1::2] = 0 - expected_Y = np.transpose(expected_Y, perms) - for ord in ["C", "F", "A", "K"]: - Y = dpt.sign(U, order=ord) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - @pytest.mark.parametrize("dtype", ["c8", "c16"]) def test_sign_complex(dtype): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_sqrt.py b/dpnp/tests/tensor/elementwise/test_sqrt.py index d6bc7a42434..966f1f52497 100644 --- a/dpnp/tests/tensor/elementwise/test_sqrt.py +++ b/dpnp/tests/tensor/elementwise/test_sqrt.py @@ -44,7 +44,6 @@ _complex_fp_dtypes, _map_to_device_dtype, _real_fp_dtypes, - _usm_types, ) @@ -91,52 +90,6 @@ def test_sqrt_output_strided(dtype): assert_allclose(dpt.asnumpy(Y), np.sqrt(Xnp), atol=tol, rtol=tol) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_sqrt_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("f4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 16.0 - X[..., 1::2] = 23.0 - - Y = dpt.sqrt(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = np.empty(input_shape, dtype=arg_dt) - expected_Y[..., 0::2] = np.sqrt(np.float32(16.0)) - expected_Y[..., 1::2] = np.sqrt(np.float32(23.0)) - tol = 8 * dpt.finfo(Y.dtype).resolution - - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_sqrt_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 16.0 - X[..., 1::2] = 23.0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.sqrt(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt.sqrt(U, order=ord) - tol = 8 * max( - dpt.finfo(Y.dtype).resolution, - np.finfo(expected_Y.dtype).resolution, - ) - assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) - - @pytest.mark.usefixtures("suppress_invalid_numpy_warnings") def test_sqrt_special_cases(): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_square.py b/dpnp/tests/tensor/elementwise/test_square.py index 0b65e9af53c..bf9909a7b28 100644 --- a/dpnp/tests/tensor/elementwise/test_square.py +++ b/dpnp/tests/tensor/elementwise/test_square.py @@ -26,8 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import itertools - import numpy as np import pytest @@ -37,7 +35,7 @@ get_queue_or_skip, skip_if_dtype_not_supported, ) -from .utils import _all_dtypes, _usm_types +from .utils import _all_dtypes @pytest.mark.parametrize("dtype", _all_dtypes[1:]) @@ -54,46 +52,6 @@ def test_square_out_type(dtype): assert np.allclose(dpt.asnumpy(r), dpt.asnumpy(dpt.square(X))) -@pytest.mark.parametrize("usm_type", _usm_types) -def test_square_usm_type(usm_type): - q = get_queue_or_skip() - - arg_dt = np.dtype("i4") - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q) - X[..., 0::2] = 1 - X[..., 1::2] = 0 - - Y = dpt.square(X) - assert Y.usm_type == X.usm_type - assert Y.sycl_queue == X.sycl_queue - assert Y.flags.c_contiguous - - expected_Y = dpt.asnumpy(X) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_square_order(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - arg_dt = np.dtype(dtype) - input_shape = (10, 10, 10, 10) - X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q) - X[..., 0::2] = 2 - X[..., 1::2] = 0 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - expected_Y = np.full(U.shape, 4, dtype=U.dtype) - expected_Y[..., 1::2] = 0 - expected_Y = np.transpose(expected_Y, perms) - for ord in ["C", "F", "A", "K"]: - Y = dpt.square(U, order=ord) - assert np.allclose(dpt.asnumpy(Y), expected_Y) - - @pytest.mark.parametrize("dtype", ["c8", "c16"]) def test_square_special_cases(dtype): q = get_queue_or_skip() diff --git a/dpnp/tests/tensor/elementwise/test_subtract.py b/dpnp/tests/tensor/elementwise/test_subtract.py index 70d05f926c2..bac13adca30 100644 --- a/dpnp/tests/tensor/elementwise/test_subtract.py +++ b/dpnp/tests/tensor/elementwise/test_subtract.py @@ -26,9 +26,6 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -import ctypes - -import dpctl import numpy as np import pytest @@ -42,7 +39,6 @@ from .utils import ( _all_dtypes, _compare_dtypes, - _usm_types, ) @@ -96,121 +92,6 @@ def test_subtract_bool(): dpt.subtract(ar1, ar2) -@pytest.mark.parametrize("op1_usm_type", _usm_types) -@pytest.mark.parametrize("op2_usm_type", _usm_types) -def test_subtract_usm_type_matrix(op1_usm_type, op2_usm_type): - get_queue_or_skip() - - sz = 128 - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) - - r = dpt.subtract(ar1, ar2) - assert isinstance(r, dpt.usm_ndarray) - expected_usm_type = dpt.get_coerced_usm_type((op1_usm_type, op2_usm_type)) - assert r.usm_type == expected_usm_type - - -def test_subtract_order(): - get_queue_or_skip() - - test_shape = ( - 20, - 20, - ) - test_shape2 = tuple(2 * dim for dim in test_shape) - n = test_shape[-1] - - for dt1, dt2 in zip(["i4", "i4", "f4"], ["i4", "f4", "i4"]): - ar1 = dpt.ones(test_shape, dtype=dt1, order="C") - ar2 = dpt.ones(test_shape, dtype=dt2, order="C") - r1 = dpt.subtract(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.subtract(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.subtract(ar1, ar2, order="A") - assert r3.flags.c_contiguous - r4 = dpt.subtract(ar1, ar2, order="K") - assert r4.flags.c_contiguous - - ar1 = dpt.ones(test_shape, dtype=dt1, order="F") - ar2 = dpt.ones(test_shape, dtype=dt2, order="F") - r1 = dpt.subtract(ar1, ar2, order="C") - assert r1.flags.c_contiguous - r2 = dpt.subtract(ar1, ar2, order="F") - assert r2.flags.f_contiguous - r3 = dpt.subtract(ar1, ar2, order="A") - assert r3.flags.f_contiguous - r4 = dpt.subtract(ar1, ar2, order="K") - assert r4.flags.f_contiguous - - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2] - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2] - r4 = dpt.subtract(ar1, ar2, order="K") - assert r4.strides == (n, -1) - r5 = dpt.subtract(ar1, ar2, order="C") - assert r5.strides == (n, 1) - - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2].mT - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2].mT - r4 = dpt.subtract(ar1, ar2, order="K") - assert r4.strides == (-1, n) - r5 = dpt.subtract(ar1, ar2, order="C") - assert r5.strides == (n, 1) - - -def test_subtract_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(5, dtype="i4") - - r = dpt.subtract(m, v) - assert ( - dpt.asnumpy(r) == np.arange(1, -4, step=-1, dtype="i4")[np.newaxis, :] - ).all() - - r2 = dpt.subtract(v, m) - assert ( - dpt.asnumpy(r2) == np.arange(-1, 4, dtype="i4")[np.newaxis, :] - ).all() - - -@pytest.mark.parametrize("arr_dt", _all_dtypes[1:]) -def test_subtract_python_scalar(arr_dt): - q = get_queue_or_skip() - skip_if_dtype_not_supported(arr_dt, q) - - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) - py_zeros = ( - bool(0), - int(0), - float(0), - complex(0), - np.float32(0), - ctypes.c_int(0), - ) - for sc in py_zeros: - R = dpt.subtract(X, sc) - assert isinstance(R, dpt.usm_ndarray) - R = dpt.subtract(sc, X) - assert isinstance(R, dpt.usm_ndarray) - - -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) -def test_subtract_inplace_python_scalar(dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) - dt_kind = X.dtype.kind - if dt_kind in "ui": - X -= int(0) - elif dt_kind == "f": - X -= float(0) - elif dt_kind == "c": - X -= complex(0) - - @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) @pytest.mark.parametrize("op2_dtype", _all_dtypes[1:]) def test_subtract_inplace_dtype_matrix(op1_dtype, op2_dtype): @@ -238,15 +119,3 @@ def test_subtract_inplace_dtype_matrix(op1_dtype, op2_dtype): else: with pytest.raises(ValueError): ar1 -= ar2 - - -def test_subtract_inplace_broadcasting(): - get_queue_or_skip() - - m = dpt.ones((100, 5), dtype="i4") - v = dpt.arange(5, dtype="i4") - - m -= v - assert ( - dpt.asnumpy(m) == np.arange(1, -4, step=-1, dtype="i4")[np.newaxis, :] - ).all() diff --git a/dpnp/tests/tensor/elementwise/test_usm_types.py b/dpnp/tests/tensor/elementwise/test_usm_types.py new file mode 100644 index 00000000000..25447d9c91c --- /dev/null +++ b/dpnp/tests/tensor/elementwise/test_usm_types.py @@ -0,0 +1,307 @@ +# ***************************************************************************** +# Copyright (c) 2026, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + +import pytest + +import dpnp.tensor as dpt +from dpnp.tests.tensor.helper import get_queue_or_skip + +from .utils import _usm_types + + +@pytest.mark.parametrize("usm_type", _usm_types) +class TestUnaryUSMType: + def unary_elementwise(self, fn, usm_type, dtype="f4"): + q = get_queue_or_skip() + x = dpt.asarray( + [1, 2, 3, 4], dtype=dtype, usm_type=usm_type, sycl_queue=q + ) + return getattr(dpt, fn)(x) + + def test_abs(self, usm_type): + self.unary_elementwise("abs", usm_type) + + def test_acos(self, usm_type): + self.unary_elementwise("acos", usm_type) + + def test_acosh(self, usm_type): + self.unary_elementwise("acosh", usm_type) + + def test_angle(self, usm_type): + self.unary_elementwise("angle", usm_type, dtype="c8") + + def test_asin(self, usm_type): + self.unary_elementwise("asin", usm_type) + + def test_asinh(self, usm_type): + self.unary_elementwise("asinh", usm_type) + + def test_atan(self, usm_type): + self.unary_elementwise("atan", usm_type) + + def test_atanh(self, usm_type): + self.unary_elementwise("atanh", usm_type) + + def test_bitwise_invert(self, usm_type): + self.unary_elementwise("bitwise_invert", usm_type, dtype="i4") + + def test_cbrt(self, usm_type): + self.unary_elementwise("cbrt", usm_type) + + def test_ceil(self, usm_type): + self.unary_elementwise("ceil", usm_type) + + def test_conj(self, usm_type): + self.unary_elementwise("conj", usm_type) + + def test_cos(self, usm_type): + self.unary_elementwise("cos", usm_type) + + def test_cosh(self, usm_type): + self.unary_elementwise("cosh", usm_type) + + def test_exp(self, usm_type): + self.unary_elementwise("exp", usm_type) + + def test_exp2(self, usm_type): + self.unary_elementwise("exp2", usm_type) + + def test_expm1(self, usm_type): + self.unary_elementwise("expm1", usm_type) + + def test_floor(self, usm_type): + self.unary_elementwise("floor", usm_type) + + def test_imag(self, usm_type): + self.unary_elementwise("imag", usm_type) + + def test_isfinite(self, usm_type): + self.unary_elementwise("isfinite", usm_type) + + def test_isinf(self, usm_type): + self.unary_elementwise("isinf", usm_type) + + def test_isnan(self, usm_type): + self.unary_elementwise("isnan", usm_type) + + def test_log(self, usm_type): + self.unary_elementwise("log", usm_type) + + def test_log1p(self, usm_type): + self.unary_elementwise("log1p", usm_type) + + def test_log2(self, usm_type): + self.unary_elementwise("log2", usm_type) + + def test_log10(self, usm_type): + self.unary_elementwise("log10", usm_type) + + def test_logical_not(self, usm_type): + self.unary_elementwise("logical_not", usm_type, dtype="i4") + + def test_negative(self, usm_type): + self.unary_elementwise("negative", usm_type) + + def test_positive(self, usm_type): + self.unary_elementwise("positive", usm_type) + + def test_proj(self, usm_type): + self.unary_elementwise("proj", usm_type, dtype="c8") + + def test_real(self, usm_type): + self.unary_elementwise("real", usm_type, dtype="c8") + + def test_reciprocal(self, usm_type): + self.unary_elementwise("reciprocal", usm_type) + + def test_round(self, usm_type): + self.unary_elementwise("round", usm_type) + + def test_rsqrt(self, usm_type): + self.unary_elementwise("rsqrt", usm_type) + + def test_sign(self, usm_type): + self.unary_elementwise("sign", usm_type) + + def test_signbit(self, usm_type): + self.unary_elementwise("signbit", usm_type) + + def test_sin(self, usm_type): + self.unary_elementwise("sin", usm_type) + + def test_sinh(self, usm_type): + self.unary_elementwise("sinh", usm_type) + + def test_square(self, usm_type): + self.unary_elementwise("square", usm_type) + + def test_sqrt(self, usm_type): + self.unary_elementwise("sqrt", usm_type) + + def test_tan(self, usm_type): + self.unary_elementwise("tan", usm_type) + + def test_tanh(self, usm_type): + self.unary_elementwise("tanh", usm_type) + + def test_trunc(self, usm_type): + self.unary_elementwise("trunc", usm_type) + + def test_usm_basic(self, usm_type): + q = get_queue_or_skip() + + sz = 128 + dt = dpt.int32 + x = dpt.ones(sz, dtype=dt, usm_type=usm_type, sycl_queue=q) + + r = dpt.abs(x) + assert isinstance(r, dpt.usm_ndarray) + assert r.usm_type == x.usm_type + + +@pytest.mark.parametrize("op1_usm_type", _usm_types) +@pytest.mark.parametrize("op2_usm_type", _usm_types) +class TestBinaryUSMType: + def binary_elementwise(self, fn, op1_usm_type, op2_usm_type, dtype="f4"): + q = get_queue_or_skip() + x = dpt.asarray( + [1, 2, 3, 4, 5, 6], dtype=dtype, usm_type=op1_usm_type, sycl_queue=q + ) + y = dpt.asarray( + [1, 2, 3, 4, 5, 6], dtype=dtype, usm_type=op2_usm_type, sycl_queue=q + ) + return getattr(dpt, fn)(x, y) + + def test_add(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("add", op1_usm_type, op2_usm_type) + + def test_atan2(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("atan2", op1_usm_type, op2_usm_type) + + def test_bitwise_and(self, op1_usm_type, op2_usm_type): + self.binary_elementwise( + "bitwise_and", op1_usm_type, op2_usm_type, dtype="i4" + ) + + def test_bitwise_left_shift(self, op1_usm_type, op2_usm_type): + self.binary_elementwise( + "bitwise_left_shift", op1_usm_type, op2_usm_type, dtype="i4" + ) + + def test_bitwise_or(self, op1_usm_type, op2_usm_type): + self.binary_elementwise( + "bitwise_or", op1_usm_type, op2_usm_type, dtype="i4" + ) + + def test_bitwise_right_shift(self, op1_usm_type, op2_usm_type): + self.binary_elementwise( + "bitwise_right_shift", op1_usm_type, op2_usm_type, dtype="i4" + ) + + def test_bitwise_xor(self, op1_usm_type, op2_usm_type): + self.binary_elementwise( + "bitwise_xor", op1_usm_type, op2_usm_type, dtype="i4" + ) + + def test_copysign(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("copysign", op1_usm_type, op2_usm_type) + + def test_divide(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("divide", op1_usm_type, op2_usm_type) + + def test_equal(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("equal", op1_usm_type, op2_usm_type) + + def test_floor_divide(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("floor_divide", op1_usm_type, op2_usm_type) + + def test_hypot(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("hypot", op1_usm_type, op2_usm_type) + + def test_greater(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("greater", op1_usm_type, op2_usm_type) + + def test_greater_equal(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("greater_equal", op1_usm_type, op2_usm_type) + + def test_less(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("less", op1_usm_type, op2_usm_type) + + def test_less_equal(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("less_equal", op1_usm_type, op2_usm_type) + + def test_logaddexp(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("logaddexp", op1_usm_type, op2_usm_type) + + def test_logical_and(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("logical_and", op1_usm_type, op2_usm_type) + + def test_logical_or(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("logical_or", op1_usm_type, op2_usm_type) + + def test_logical_xor(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("logical_xor", op1_usm_type, op2_usm_type) + + def test_maximum(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("maximum", op1_usm_type, op2_usm_type) + + def test_minimum(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("minimum", op1_usm_type, op2_usm_type) + + def test_multiply(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("multiply", op1_usm_type, op2_usm_type) + + def test_nextafter(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("nextafter", op1_usm_type, op2_usm_type) + + def test_not_equal(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("not_equal", op1_usm_type, op2_usm_type) + + def test_pow(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("pow", op1_usm_type, op2_usm_type) + + def test_remainder(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("remainder", op1_usm_type, op2_usm_type) + + def test_subtract(self, op1_usm_type, op2_usm_type): + self.binary_elementwise("subtract", op1_usm_type, op2_usm_type) + + def test_binary_usm_type_coercion(self, op1_usm_type, op2_usm_type): + q = get_queue_or_skip() + + sz = 128 + dt = dpt.int32 + ar1 = dpt.ones(sz, dtype=dt, usm_type=op1_usm_type, sycl_queue=q) + ar2 = dpt.ones_like(ar1, dtype=dt, usm_type=op2_usm_type, sycl_queue=q) + + r = dpt.add(ar1, ar2) + assert isinstance(r, dpt.usm_ndarray) + expected_usm_type = dpt.get_coerced_usm_type( + (op1_usm_type, op2_usm_type) + ) + assert r.usm_type == expected_usm_type