Skip to content

Commit 85c4906

Browse files
Initialize dpnp/tests/tensor and migrate test_tensor_* files
1 parent 9a7fae9 commit 85c4906

14 files changed

Lines changed: 4037 additions & 0 deletions

dpnp/tests/tensor/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2026, Intel Corporation
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# - Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# - Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
# - Neither the name of the copyright holder nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
# THE POSSIBILITY OF SUCH DAMAGE.
27+
# *****************************************************************************
28+
29+
__doc__ = r"""
30+
Test suite for tensor functionality migrated from dpctl.
31+
Running test suite requires Cython and a working compiler."""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2026, Intel Corporation
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# - Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# - Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
# - Neither the name of the copyright holder nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
# THE POSSIBILITY OF SUCH DAMAGE.
27+
# *****************************************************************************
28+
29+
"""Helper module for dpctl/tests"""
30+
31+
from ._helper import (
32+
create_invalid_capsule,
33+
get_queue_or_skip,
34+
has_cpu,
35+
has_gpu,
36+
has_sycl_platforms,
37+
skip_if_dtype_not_supported,
38+
)
39+
40+
__all__ = [
41+
"create_invalid_capsule",
42+
"has_cpu",
43+
"has_gpu",
44+
"has_sycl_platforms",
45+
"get_queue_or_skip",
46+
"skip_if_dtype_not_supported",
47+
]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2026, Intel Corporation
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# - Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# - Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
# - Neither the name of the copyright holder nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
# THE POSSIBILITY OF SUCH DAMAGE.
27+
# *****************************************************************************
28+
29+
import dpctl
30+
import pytest
31+
32+
33+
def has_gpu(backend="opencl"):
34+
return bool(dpctl.get_num_devices(backend=backend, device_type="gpu"))
35+
36+
37+
def has_cpu(backend="opencl"):
38+
return bool(dpctl.get_num_devices(backend=backend, device_type="cpu"))
39+
40+
41+
def has_sycl_platforms():
42+
return bool(len(dpctl.get_platforms()))
43+
44+
45+
def create_invalid_capsule():
46+
"""Creates an invalid capsule for the purpose of testing dpctl
47+
constructors that accept capsules.
48+
"""
49+
import ctypes
50+
51+
ctor = ctypes.pythonapi.PyCapsule_New
52+
ctor.restype = ctypes.py_object
53+
ctor.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p]
54+
return ctor(id(ctor), b"invalid", 0)
55+
56+
57+
def get_queue_or_skip(args=()):
58+
try:
59+
q = dpctl.SyclQueue(*args)
60+
except dpctl.SyclQueueCreationError:
61+
pytest.skip(f"Queue could not be created from {args}")
62+
return q
63+
64+
65+
def skip_if_dtype_not_supported(dt, q_or_dev):
66+
# TODO: revert to `import dpctl.tensor...`
67+
# when dpnp fully migrates dpctl/tensor
68+
import dpctl_ext.tensor as dpt
69+
70+
dt = dpt.dtype(dt)
71+
if type(q_or_dev) is dpctl.SyclQueue:
72+
dev = q_or_dev.sycl_device
73+
elif type(q_or_dev) is dpctl.SyclDevice:
74+
dev = q_or_dev
75+
else:
76+
raise TypeError(
77+
"Expected dpctl.SyclQueue or dpctl.SyclDevice, "
78+
f"got {type(q_or_dev)}"
79+
)
80+
dev_has_dp = dev.has_aspect_fp64
81+
if dev_has_dp is False and dt in [dpt.float64, dpt.complex128]:
82+
pytest.skip(
83+
f"{dev.name} does not support double precision floating point types"
84+
)
85+
dev_has_hp = dev.has_aspect_fp16
86+
if dev_has_hp is False and dt in [
87+
dpt.float16,
88+
]:
89+
pytest.skip(
90+
f"{dev.name} does not support half precision floating point type"
91+
)

0 commit comments

Comments
 (0)