Skip to content

Commit 93d288c

Browse files
committed
Add test for gh-2055 resolution and refactor tests for _copy_utils internal functions
1 parent de4b40a commit 93d288c

File tree

2 files changed

+100
-45
lines changed

2 files changed

+100
-45
lines changed

dpctl/tests/elementwise/test_type_utils.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import dpctl
2121
import dpctl.tensor as dpt
22-
import dpctl.tensor._copy_utils as cu
2322
import dpctl.tensor._type_utils as tu
2423

2524
from .utils import _all_dtypes, _map_to_device_dtype
@@ -70,50 +69,6 @@ def test_type_util_can_cast():
7069
assert isinstance(r, bool)
7170

7271

73-
def test_type_utils_empty_like_orderK():
74-
try:
75-
a = dpt.empty((10, 10), dtype=dpt.int32, order="F")
76-
except dpctl.SyclDeviceCreationError:
77-
pytest.skip("No SYCL devices available")
78-
X = cu._empty_like_orderK(a, dpt.int32, a.usm_type, a.device)
79-
assert X.flags["F"]
80-
81-
82-
def test_type_utils_empty_like_orderK_invalid_args():
83-
with pytest.raises(TypeError):
84-
cu._empty_like_orderK([1, 2, 3], dpt.int32, "device", None)
85-
with pytest.raises(TypeError):
86-
cu._empty_like_pair_orderK(
87-
[1, 2, 3],
88-
(
89-
1,
90-
2,
91-
3,
92-
),
93-
dpt.int32,
94-
(3,),
95-
"device",
96-
None,
97-
)
98-
try:
99-
a = dpt.empty(10, dtype=dpt.int32)
100-
except dpctl.SyclDeviceCreationError:
101-
pytest.skip("No SYCL devices available")
102-
with pytest.raises(TypeError):
103-
cu._empty_like_pair_orderK(
104-
a,
105-
(
106-
1,
107-
2,
108-
3,
109-
),
110-
dpt.int32,
111-
(10,),
112-
"device",
113-
None,
114-
)
115-
116-
11772
def test_type_utils_find_buf_dtype():
11873
def _denier_fn(dt):
11974
return False

dpctl/tests/test_tensor_copy_utils.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2025 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import numpy as np
18+
import pytest
19+
20+
import dpctl.tensor as dpt
21+
import dpctl.tensor._copy_utils as cu
22+
from dpctl.tests.helper import get_queue_or_skip
23+
24+
25+
def test_copy_utils_empty_like_orderK():
26+
get_queue_or_skip()
27+
a = dpt.empty((10, 10), dtype=dpt.int32, order="F")
28+
X = cu._empty_like_orderK(a, dpt.int32, a.usm_type, a.device)
29+
assert X.flags["F"]
30+
31+
32+
def test_copy_utils_empty_like_orderK_invalid_args():
33+
get_queue_or_skip()
34+
with pytest.raises(TypeError):
35+
cu._empty_like_orderK([1, 2, 3], dpt.int32, "device", None)
36+
with pytest.raises(TypeError):
37+
cu._empty_like_pair_orderK(
38+
[1, 2, 3],
39+
(
40+
1,
41+
2,
42+
3,
43+
),
44+
dpt.int32,
45+
(3,),
46+
"device",
47+
None,
48+
)
49+
50+
a = dpt.empty(10, dtype=dpt.int32)
51+
with pytest.raises(TypeError):
52+
cu._empty_like_pair_orderK(
53+
a,
54+
(
55+
1,
56+
2,
57+
3,
58+
),
59+
dpt.int32,
60+
(10,),
61+
"device",
62+
None,
63+
)
64+
65+
66+
def test_copy_utils_from_numpy_empty_like_orderK():
67+
q = get_queue_or_skip()
68+
69+
a = np.empty((10, 10), dtype=np.int32, order="C")
70+
r0 = cu._from_numpy_empty_like_orderK(a, dpt.int32, "device", q)
71+
assert r0.flags["C"]
72+
73+
b = np.empty((10, 10), dtype=np.int32, order="F")
74+
r1 = cu._from_numpy_empty_like_orderK(b, dpt.int32, "device", q)
75+
assert r1.flags["F"]
76+
77+
c = np.empty((2, 3, 4), dtype=np.int32, order="C")
78+
c = np.transpose(c, (1, 0, 2))
79+
r2 = cu._from_numpy_empty_like_orderK(c, dpt.int32, "device", q)
80+
assert not r2.flags["C"] and not r2.flags["F"]
81+
82+
83+
def test_copy_utils_from_numpy_empty_like_orderK_invalid_args():
84+
with pytest.raises(TypeError):
85+
cu._from_numpy_empty_like_orderK([1, 2, 3], dpt.int32, "device", None)
86+
87+
88+
def test_gh_2055():
89+
"""
90+
Test that `dpt.asarray` works on contiguous NumPy arrays with `order="K"`
91+
when dimensions are permuted.
92+
93+
See: https://github.com/IntelPython/dpctl/issues/2055
94+
"""
95+
get_queue_or_skip()
96+
97+
a = np.ones((2, 3, 4), dtype=dpt.int32)
98+
a_t = np.transpose(a, (2, 0, 1))
99+
r = dpt.asarray(a_t)
100+
assert not r.flags["C"] and not r.flags["F"]

0 commit comments

Comments
 (0)