From bd7e9a64045b26709f390ca50acc27f36c09c591 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 15:24:30 -0700 Subject: [PATCH 1/8] refactor test_trig_out_type --- dpctl/tests/elementwise/test_trigonometric.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index b1438cf5d7..54976c0223 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -43,17 +43,10 @@ def test_trig_out_type(np_call, dpt_call, dtype): q = get_queue_or_skip() skip_if_dtype_not_supported(dtype, q) - X = dpt.asarray(0, dtype=dtype, sycl_queue=q) + x = dpt.asarray(0, dtype=dtype, sycl_queue=q) expected_dtype = np_call(np.array(0, dtype=dtype)).dtype expected_dtype = _map_to_device_dtype(expected_dtype, q.sycl_device) - assert dpt_call(X).dtype == expected_dtype - - X = dpt.asarray(0, dtype=dtype, sycl_queue=q) - expected_dtype = np_call(np.array(0, dtype=dtype)).dtype - expected_dtype = _map_to_device_dtype(expected_dtype, q.sycl_device) - Y = dpt.empty_like(X, dtype=expected_dtype) - dpt_call(X, out=Y) - assert_allclose(dpt.asnumpy(dpt_call(X)), dpt.asnumpy(Y)) + assert dpt_call(x).dtype == expected_dtype @pytest.mark.parametrize("np_call, dpt_call", _all_funcs) From 76aaf9fcdf0e1bc4c2b83ce1a09a390fd38fc065 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 15:25:11 -0700 Subject: [PATCH 2/8] refactor test_hyper_out_type --- dpctl/tests/elementwise/test_hyperbolic.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index c71b141771..5f01811be6 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -45,17 +45,10 @@ def test_hyper_out_type(np_call, dpt_call, dtype): a = 1 if np_call == np.arccosh else 0 - X = dpt.asarray(a, dtype=dtype, sycl_queue=q) + x = dpt.asarray(a, dtype=dtype, sycl_queue=q) expected_dtype = np_call(np.array(a, dtype=dtype)).dtype expected_dtype = _map_to_device_dtype(expected_dtype, q.sycl_device) - assert dpt_call(X).dtype == expected_dtype - - X = dpt.asarray(a, dtype=dtype, sycl_queue=q) - expected_dtype = np_call(np.array(a, dtype=dtype)).dtype - expected_dtype = _map_to_device_dtype(expected_dtype, q.sycl_device) - Y = dpt.empty_like(X, dtype=expected_dtype) - dpt_call(X, out=Y) - assert_allclose(dpt.asnumpy(dpt_call(X)), dpt.asnumpy(Y)) + assert dpt_call(x).dtype == expected_dtype @pytest.mark.parametrize("np_call, dpt_call", _all_funcs) From a6a1c4883214f641f5befec75c87ddf18ebdd8bf Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 15:25:45 -0700 Subject: [PATCH 3/8] remove redundant usm_type tests --- dpctl/tests/elementwise/test_hyperbolic.py | 28 ------------------- dpctl/tests/elementwise/test_trigonometric.py | 28 ------------------- 2 files changed, 56 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index 5f01811be6..8164ba8027 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -112,34 +112,6 @@ def test_hyper_complex_contig(np_call, dpt_call, dtype): ) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("usm_type", ["device", "shared", "host"]) -def test_hyper_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) - if np_call == np.arctanh: - X[..., 0::2] = -0.4 - X[..., 1::2] = 0.3 - elif np_call == np.arccosh: - X[..., 0::2] = 2.2 - X[..., 1::2] = 5.5 - else: - X[..., 0::2] = -4.4 - X[..., 1::2] = 5.5 - - 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", _all_dtypes) def test_hyper_order(np_call, dpt_call, dtype): diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index 54976c0223..2049488c3e 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -120,34 +120,6 @@ def test_trig_complex_contig(np_call, dpt_call, dtype): assert_allclose(dpt.asnumpy(Z), expected, atol=tol, rtol=tol) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("usm_type", ["device", "shared", "host"]) -def test_trig_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) - if np_call in _trig_funcs: - X[..., 0::2] = np.pi / 6 - X[..., 1::2] = np.pi / 3 - if np_call == np.arctan: - X[..., 0::2] = -2.2 - X[..., 1::2] = 3.3 - else: - X[..., 0::2] = -0.3 - 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", _all_dtypes) def test_trig_order(np_call, dpt_call, dtype): From 878640b50b0aeb994097a0be0f37decbe0879513 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 15:27:11 -0700 Subject: [PATCH 4/8] remove redundant tests using out keyword --- dpctl/tests/elementwise/test_hyperbolic.py | 14 -------------- dpctl/tests/elementwise/test_trigonometric.py | 14 -------------- 2 files changed, 28 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index 8164ba8027..c4ba67cb99 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -16,7 +16,6 @@ import itertools import os -import re import numpy as np import pytest @@ -144,19 +143,6 @@ def test_hyper_order(np_call, dpt_call, dtype): assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) -@pytest.mark.parametrize("callable", _dpt_funcs) -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_hyper_error_dtype(callable, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = dpt.ones(5, dtype=dtype) - y = dpt.empty_like(x, dtype="int16") - with pytest.raises(ValueError) as excinfo: - callable(x, out=y) - assert re.match("Output array of type.*is needed", str(excinfo.value)) - - @pytest.mark.parametrize("np_call, dpt_call", _all_funcs) @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_hyper_real_strided(np_call, dpt_call, dtype): diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index 2049488c3e..530dc1ea5e 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -16,7 +16,6 @@ import itertools import os -import re import numpy as np import pytest @@ -151,19 +150,6 @@ def test_trig_order(np_call, dpt_call, dtype): assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol) -@pytest.mark.parametrize("callable", _dpt_funcs) -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_trig_error_dtype(callable, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = dpt.zeros(5, dtype=dtype) - y = dpt.empty_like(x, dtype="int16") - with pytest.raises(ValueError) as excinfo: - callable(x, out=y) - assert re.match("Output array of type.*is needed", str(excinfo.value)) - - @pytest.mark.parametrize("np_call, dpt_call", _all_funcs) @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_trig_real_strided(np_call, dpt_call, dtype): From 0a7c95ae6e9713b668d49517f4d562de1ae9bcb4 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 15:28:16 -0700 Subject: [PATCH 5/8] remove redundant memory order tests --- dpctl/tests/elementwise/test_hyperbolic.py | 32 ------------------- dpctl/tests/elementwise/test_trigonometric.py | 31 ------------------ 2 files changed, 63 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index c4ba67cb99..84c8d8f22e 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -111,38 +111,6 @@ def test_hyper_complex_contig(np_call, dpt_call, dtype): ) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_hyper_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) - if np_call == np.arctanh: - X[..., 0::2] = -0.4 - X[..., 1::2] = 0.3 - elif np_call == np.arccosh: - X[..., 0::2] = 2.2 - X[..., 1::2] = 5.5 - else: - X[..., 0::2] = -4.4 - X[..., 1::2] = 5.5 - - for perms in itertools.permutations(range(4)): - U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms) - with np.errstate(all="ignore"): - expected_Y = np_call(dpt.asnumpy(U)) - for ord in ["C", "F", "A", "K"]: - Y = dpt_call(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("np_call, dpt_call", _all_funcs) @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_hyper_real_strided(np_call, dpt_call, dtype): diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index 530dc1ea5e..6d437732de 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -119,37 +119,6 @@ def test_trig_complex_contig(np_call, dpt_call, dtype): assert_allclose(dpt.asnumpy(Z), expected, atol=tol, rtol=tol) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", _all_dtypes) -def test_trig_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) - if np_call in _trig_funcs: - X[..., 0::2] = np.pi / 6 - X[..., 1::2] = np.pi / 3 - if np_call == np.arctan: - X[..., 0::2] = -2.2 - X[..., 1::2] = 3.3 - else: - X[..., 0::2] = -0.3 - 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) - 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("np_call, dpt_call", _all_funcs) @pytest.mark.parametrize("dtype", ["f2", "f4", "f8"]) def test_trig_real_strided(np_call, dpt_call, dtype): From de8c3eec1760afb0067560ac8bb52a877e36f32a Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 21 Jul 2025 17:36:08 -0700 Subject: [PATCH 6/8] remove complex special case tests for trig elementwise funcs --- dpctl/tests/elementwise/test_hyperbolic.py | 46 ------------------ dpctl/tests/elementwise/test_trigonometric.py | 47 ------------------- 2 files changed, 93 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index 84c8d8f22e..20d4360006 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -14,9 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import itertools -import os - import numpy as np import pytest from numpy.testing import assert_allclose @@ -189,46 +186,3 @@ def test_hyper_real_special_cases(np_call, dpt_call, dtype): tol = 8 * dpt.finfo(dtype).resolution assert_allclose(dpt.asnumpy(dpt_call(yf)), Y_np, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", ["c8", "c16"]) -def test_hyper_complex_special_cases_conj_property(np_call, dpt_call, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = [np.nan, np.inf, -np.inf, +0.0, -0.0, +1.0, -1.0] - xc = [complex(*val) for val in itertools.product(x, repeat=2)] - - Xc_np = np.array(xc, dtype=dtype) - Xc = dpt.asarray(Xc_np, dtype=dtype, sycl_queue=q) - - tol = 50 * dpt.finfo(dtype).resolution - Y = dpt_call(Xc) - Yc = dpt_call(dpt.conj(Xc)) - - dpt.allclose(Y, dpt.conj(Yc), atol=tol, rtol=tol) - - -@pytest.mark.skipif( - os.name != "posix", reason="Known to fail on Windows due to bug in NumPy" -) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", ["c8", "c16"]) -def test_hyper_complex_special_cases(np_call, dpt_call, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = [np.nan, np.inf, -np.inf, +0.0, -0.0, +1.0, -1.0] - xc = [complex(*val) for val in itertools.product(x, repeat=2)] - - Xc_np = np.array(xc, dtype=dtype) - Xc = dpt.asarray(Xc_np, dtype=dtype, sycl_queue=q) - - with np.errstate(all="ignore"): - Ynp = np_call(Xc_np) - - tol = 50 * dpt.finfo(dtype).resolution - Y = dpt_call(Xc) - assert_allclose(dpt.asnumpy(dpt.real(Y)), np.real(Ynp), atol=tol, rtol=tol) - assert_allclose(dpt.asnumpy(dpt.imag(Y)), np.imag(Ynp), atol=tol, rtol=tol) diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index 6d437732de..f13c51d5e7 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -14,9 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import itertools -import os - import numpy as np import pytest from numpy.testing import assert_allclose @@ -218,47 +215,3 @@ def test_trig_real_special_cases(np_call, dpt_call, dtype): tol = 8 * dpt.finfo(dtype).resolution Y = dpt_call(yf) assert_allclose(dpt.asnumpy(Y), Y_np, atol=tol, rtol=tol) - - -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", ["c8", "c16"]) -def test_trig_complex_special_cases_conj_property(np_call, dpt_call, dtype): - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = [np.nan, np.inf, -np.inf, +0.0, -0.0, +1.0, -1.0] - xc = [complex(*val) for val in itertools.product(x, repeat=2)] - - Xc_np = np.array(xc, dtype=dtype) - Xc = dpt.asarray(Xc_np, dtype=dtype, sycl_queue=q) - - tol = 50 * dpt.finfo(dtype).resolution - Y = dpt_call(Xc) - Yc = dpt_call(dpt.conj(Xc)) - - dpt.allclose(Y, dpt.conj(Yc), atol=tol, rtol=tol) - - -@pytest.mark.skipif( - os.name != "posix", reason="Known to fail on Windows due to bug in NumPy" -) -@pytest.mark.parametrize("np_call, dpt_call", _all_funcs) -@pytest.mark.parametrize("dtype", ["c8", "c16"]) -def test_trig_complex_special_cases(np_call, dpt_call, dtype): - - q = get_queue_or_skip() - skip_if_dtype_not_supported(dtype, q) - - x = [np.nan, np.inf, -np.inf, +0.0, -0.0, +1.0, -1.0] - xc = [complex(*val) for val in itertools.product(x, repeat=2)] - - Xc_np = np.array(xc, dtype=dtype) - Xc = dpt.asarray(Xc_np, dtype=dtype, sycl_queue=q) - - with np.errstate(all="ignore"): - Ynp = np_call(Xc_np) - - tol = 50 * dpt.finfo(dtype).resolution - Y = dpt_call(Xc) - assert_allclose(dpt.asnumpy(dpt.real(Y)), np.real(Ynp), atol=tol, rtol=tol) - assert_allclose(dpt.asnumpy(dpt.imag(Y)), np.imag(Ynp), atol=tol, rtol=tol) From f6d9043f8ccbf6424d759aa9fd92eabd42fa0fde Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 22 Jul 2025 15:13:28 -0700 Subject: [PATCH 7/8] unpin NumPy in coverage and OS compiler CI --- .github/workflows/generate-coverage.yaml | 3 +-- .github/workflows/os-llvm-sycl-build.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/generate-coverage.yaml b/.github/workflows/generate-coverage.yaml index 77fb782469..e4fa16c591 100644 --- a/.github/workflows/generate-coverage.yaml +++ b/.github/workflows/generate-coverage.yaml @@ -91,8 +91,7 @@ jobs: - name: Install dpctl dependencies shell: bash -l {0} run: | - # TODO: unpin numpy when numpy#29167 resolved - pip install numpy"<2.3.0" cython setuptools"<80" pytest pytest-cov scikit-build cmake coverage[toml] versioneer[toml]==0.29 + pip install numpy cython setuptools"<80" pytest pytest-cov scikit-build cmake coverage[toml] versioneer[toml]==0.29 - name: Build dpctl with coverage shell: bash -l {0} diff --git a/.github/workflows/os-llvm-sycl-build.yml b/.github/workflows/os-llvm-sycl-build.yml index 9f66436777..c67fabea63 100644 --- a/.github/workflows/os-llvm-sycl-build.yml +++ b/.github/workflows/os-llvm-sycl-build.yml @@ -107,8 +107,7 @@ jobs: - name: Install dpctl dependencies shell: bash -l {0} run: | - # TODO: unpin numpy when numpy#29167 resolved - pip install numpy"<2.3.0" cython setuptools"<80" pytest scikit-build cmake ninja versioneer[toml]==0.29 + pip install numpy cython setuptools"<80" pytest scikit-build cmake ninja versioneer[toml]==0.29 - name: Checkout repo uses: actions/checkout@v4.2.2 From 636147dbf37da91a5814cfb975c0967a9595bdd3 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 22 Jul 2025 15:26:47 -0700 Subject: [PATCH 8/8] remove unused `_dpc_funcs` from both trig test files --- dpctl/tests/elementwise/test_hyperbolic.py | 1 - dpctl/tests/elementwise/test_trigonometric.py | 1 - 2 files changed, 2 deletions(-) diff --git a/dpctl/tests/elementwise/test_hyperbolic.py b/dpctl/tests/elementwise/test_hyperbolic.py index 20d4360006..731f71ae72 100644 --- a/dpctl/tests/elementwise/test_hyperbolic.py +++ b/dpctl/tests/elementwise/test_hyperbolic.py @@ -30,7 +30,6 @@ (np.arctanh, dpt.atanh), ] _all_funcs = _hyper_funcs + _inv_hyper_funcs -_dpt_funcs = [t[1] for t in _all_funcs] @pytest.mark.parametrize("np_call, dpt_call", _all_funcs) diff --git a/dpctl/tests/elementwise/test_trigonometric.py b/dpctl/tests/elementwise/test_trigonometric.py index f13c51d5e7..7fc3d84a56 100644 --- a/dpctl/tests/elementwise/test_trigonometric.py +++ b/dpctl/tests/elementwise/test_trigonometric.py @@ -30,7 +30,6 @@ (np.arctan, dpt.atan), ] _all_funcs = _trig_funcs + _inv_trig_funcs -_dpt_funcs = [t[1] for t in _all_funcs] @pytest.mark.parametrize("np_call, dpt_call", _all_funcs)