|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
17 | | -import ctypes |
18 | | - |
19 | 17 | import numpy as np |
20 | 18 | import pytest |
21 | 19 |
|
22 | | -import dpctl |
23 | 20 | import dpctl.tensor as dpt |
24 | 21 | from dpctl.tensor._type_utils import _can_cast |
25 | 22 | from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported |
26 | 23 |
|
27 | | -from .utils import _all_dtypes, _compare_dtypes, _usm_types |
| 24 | +from .utils import _all_dtypes, _compare_dtypes |
28 | 25 |
|
29 | 26 |
|
30 | 27 | @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) |
@@ -61,114 +58,6 @@ def test_power_dtype_matrix(op1_dtype, op2_dtype): |
61 | 58 | assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() |
62 | 59 |
|
63 | 60 |
|
64 | | -@pytest.mark.parametrize("op1_usm_type", _usm_types) |
65 | | -@pytest.mark.parametrize("op2_usm_type", _usm_types) |
66 | | -def test_power_usm_type_matrix(op1_usm_type, op2_usm_type): |
67 | | - get_queue_or_skip() |
68 | | - |
69 | | - sz = 128 |
70 | | - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) |
71 | | - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) |
72 | | - |
73 | | - r = dpt.pow(ar1, ar2) |
74 | | - assert isinstance(r, dpt.usm_ndarray) |
75 | | - expected_usm_type = dpctl.utils.get_coerced_usm_type( |
76 | | - (op1_usm_type, op2_usm_type) |
77 | | - ) |
78 | | - assert r.usm_type == expected_usm_type |
79 | | - |
80 | | - |
81 | | -def test_pow_order(): |
82 | | - get_queue_or_skip() |
83 | | - |
84 | | - ar1 = dpt.ones((20, 20), dtype="i4", order="C") |
85 | | - ar2 = dpt.ones((20, 20), dtype="i4", order="C") |
86 | | - r1 = dpt.pow(ar1, ar2, order="C") |
87 | | - assert r1.flags.c_contiguous |
88 | | - r2 = dpt.pow(ar1, ar2, order="F") |
89 | | - assert r2.flags.f_contiguous |
90 | | - r3 = dpt.pow(ar1, ar2, order="A") |
91 | | - assert r3.flags.c_contiguous |
92 | | - r4 = dpt.pow(ar1, ar2, order="K") |
93 | | - assert r4.flags.c_contiguous |
94 | | - |
95 | | - ar1 = dpt.ones((20, 20), dtype="i4", order="F") |
96 | | - ar2 = dpt.ones((20, 20), dtype="i4", order="F") |
97 | | - r1 = dpt.pow(ar1, ar2, order="C") |
98 | | - assert r1.flags.c_contiguous |
99 | | - r2 = dpt.pow(ar1, ar2, order="F") |
100 | | - assert r2.flags.f_contiguous |
101 | | - r3 = dpt.pow(ar1, ar2, order="A") |
102 | | - assert r3.flags.f_contiguous |
103 | | - r4 = dpt.pow(ar1, ar2, order="K") |
104 | | - assert r4.flags.f_contiguous |
105 | | - |
106 | | - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] |
107 | | - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] |
108 | | - r4 = dpt.pow(ar1, ar2, order="K") |
109 | | - assert r4.strides == (20, -1) |
110 | | - |
111 | | - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT |
112 | | - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT |
113 | | - r4 = dpt.pow(ar1, ar2, order="K") |
114 | | - assert r4.strides == (-1, 20) |
115 | | - |
116 | | - |
117 | | -def test_pow_broadcasting(): |
118 | | - get_queue_or_skip() |
119 | | - |
120 | | - v = dpt.arange(1, 6, dtype="i4") |
121 | | - m = dpt.full((100, 5), 2, dtype="i4") |
122 | | - |
123 | | - r = dpt.pow(m, v) |
124 | | - |
125 | | - expected = np.power( |
126 | | - np.full((100, 5), 2, dtype="i4"), np.arange(1, 6, dtype="i4") |
127 | | - ) |
128 | | - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() |
129 | | - |
130 | | - r2 = dpt.pow(v, m) |
131 | | - expected2 = np.power( |
132 | | - np.arange(1, 6, dtype="i4"), np.full((100, 5), 2, dtype="i4") |
133 | | - ) |
134 | | - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() |
135 | | - |
136 | | - |
137 | | -@pytest.mark.parametrize("arr_dt", _all_dtypes) |
138 | | -def test_pow_python_scalar(arr_dt): |
139 | | - q = get_queue_or_skip() |
140 | | - skip_if_dtype_not_supported(arr_dt, q) |
141 | | - |
142 | | - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) |
143 | | - py_ones = ( |
144 | | - bool(1), |
145 | | - int(1), |
146 | | - float(1), |
147 | | - complex(1), |
148 | | - np.float32(1), |
149 | | - ctypes.c_int(1), |
150 | | - ) |
151 | | - for sc in py_ones: |
152 | | - R = dpt.pow(X, sc) |
153 | | - assert isinstance(R, dpt.usm_ndarray) |
154 | | - R = dpt.pow(sc, X) |
155 | | - assert isinstance(R, dpt.usm_ndarray) |
156 | | - |
157 | | - |
158 | | -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) |
159 | | -def test_pow_inplace_python_scalar(dtype): |
160 | | - q = get_queue_or_skip() |
161 | | - skip_if_dtype_not_supported(dtype, q) |
162 | | - X = dpt.ones((10, 10), dtype=dtype, sycl_queue=q) |
163 | | - dt_kind = X.dtype.kind |
164 | | - if dt_kind in "ui": |
165 | | - X **= int(1) |
166 | | - elif dt_kind == "f": |
167 | | - X **= float(1) |
168 | | - elif dt_kind == "c": |
169 | | - X **= complex(1) |
170 | | - |
171 | | - |
172 | 61 | @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) |
173 | 62 | @pytest.mark.parametrize("op2_dtype", _all_dtypes[1:]) |
174 | 63 | def test_pow_inplace_dtype_matrix(op1_dtype, op2_dtype): |
|
0 commit comments