|
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.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported |
25 | 22 |
|
26 | | -from .utils import _all_dtypes, _compare_dtypes, _usm_types |
| 23 | +from .utils import _all_dtypes, _compare_dtypes |
27 | 24 |
|
28 | 25 |
|
29 | 26 | @pytest.mark.parametrize("op1_dtype", _all_dtypes) |
@@ -136,135 +133,6 @@ def test_greater_complex_float(): |
136 | 133 | assert (dpt.asnumpy(r3) == expected3).all() |
137 | 134 |
|
138 | 135 |
|
139 | | -@pytest.mark.parametrize("op1_usm_type", _usm_types) |
140 | | -@pytest.mark.parametrize("op2_usm_type", _usm_types) |
141 | | -def test_greater_usm_type_matrix(op1_usm_type, op2_usm_type): |
142 | | - get_queue_or_skip() |
143 | | - |
144 | | - sz = 128 |
145 | | - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) |
146 | | - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) |
147 | | - |
148 | | - r = dpt.greater(ar1, ar2) |
149 | | - assert isinstance(r, dpt.usm_ndarray) |
150 | | - expected_usm_type = dpctl.utils.get_coerced_usm_type( |
151 | | - (op1_usm_type, op2_usm_type) |
152 | | - ) |
153 | | - assert r.usm_type == expected_usm_type |
154 | | - |
155 | | - |
156 | | -def test_greater_order(): |
157 | | - get_queue_or_skip() |
158 | | - |
159 | | - ar1 = dpt.ones((20, 20), dtype="i4", order="C") |
160 | | - ar2 = dpt.ones((20, 20), dtype="i4", order="C") |
161 | | - r1 = dpt.greater(ar1, ar2, order="C") |
162 | | - assert r1.flags.c_contiguous |
163 | | - r2 = dpt.greater(ar1, ar2, order="F") |
164 | | - assert r2.flags.f_contiguous |
165 | | - r3 = dpt.greater(ar1, ar2, order="A") |
166 | | - assert r3.flags.c_contiguous |
167 | | - r4 = dpt.greater(ar1, ar2, order="K") |
168 | | - assert r4.flags.c_contiguous |
169 | | - |
170 | | - ar1 = dpt.ones((20, 20), dtype="i4", order="F") |
171 | | - ar2 = dpt.ones((20, 20), dtype="i4", order="F") |
172 | | - r1 = dpt.greater(ar1, ar2, order="C") |
173 | | - assert r1.flags.c_contiguous |
174 | | - r2 = dpt.greater(ar1, ar2, order="F") |
175 | | - assert r2.flags.f_contiguous |
176 | | - r3 = dpt.greater(ar1, ar2, order="A") |
177 | | - assert r3.flags.f_contiguous |
178 | | - r4 = dpt.greater(ar1, ar2, order="K") |
179 | | - assert r4.flags.f_contiguous |
180 | | - |
181 | | - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] |
182 | | - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2] |
183 | | - r4 = dpt.greater(ar1, ar2, order="K") |
184 | | - assert r4.strides == (20, -1) |
185 | | - |
186 | | - ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT |
187 | | - ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT |
188 | | - r4 = dpt.greater(ar1, ar2, order="K") |
189 | | - assert r4.strides == (-1, 20) |
190 | | - |
191 | | - |
192 | | -def test_greater_broadcasting(): |
193 | | - get_queue_or_skip() |
194 | | - |
195 | | - m = dpt.ones((100, 5), dtype="i4") |
196 | | - v = dpt.arange(1, 6, dtype="i4") |
197 | | - |
198 | | - r = dpt.greater(m, v) |
199 | | - |
200 | | - expected = np.greater( |
201 | | - np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4") |
202 | | - ) |
203 | | - assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all() |
204 | | - |
205 | | - r2 = dpt.greater(v, m) |
206 | | - expected2 = np.greater( |
207 | | - np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4") |
208 | | - ) |
209 | | - assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all() |
210 | | - |
211 | | - |
212 | | -@pytest.mark.parametrize("arr_dt", _all_dtypes) |
213 | | -def test_greater_python_scalar(arr_dt): |
214 | | - q = get_queue_or_skip() |
215 | | - skip_if_dtype_not_supported(arr_dt, q) |
216 | | - |
217 | | - X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q) |
218 | | - py_ones = ( |
219 | | - bool(1), |
220 | | - int(1), |
221 | | - float(1), |
222 | | - complex(1), |
223 | | - np.float32(1), |
224 | | - ctypes.c_int(1), |
225 | | - ) |
226 | | - for sc in py_ones: |
227 | | - R = dpt.greater(X, sc) |
228 | | - assert isinstance(R, dpt.usm_ndarray) |
229 | | - R = dpt.greater(sc, X) |
230 | | - assert isinstance(R, dpt.usm_ndarray) |
231 | | - |
232 | | - |
233 | | -class MockArray: |
234 | | - def __init__(self, arr): |
235 | | - self.data_ = arr |
236 | | - |
237 | | - @property |
238 | | - def __sycl_usm_array_interface__(self): |
239 | | - return self.data_.__sycl_usm_array_interface__ |
240 | | - |
241 | | - |
242 | | -def test_greater_mock_array(): |
243 | | - get_queue_or_skip() |
244 | | - a = dpt.arange(10) |
245 | | - b = dpt.ones(10) |
246 | | - c = MockArray(b) |
247 | | - r = dpt.greater(a, c) |
248 | | - assert isinstance(r, dpt.usm_ndarray) |
249 | | - |
250 | | - |
251 | | -def test_greater_canary_mock_array(): |
252 | | - get_queue_or_skip() |
253 | | - a = dpt.arange(10) |
254 | | - |
255 | | - class Canary: |
256 | | - def __init__(self): |
257 | | - pass |
258 | | - |
259 | | - @property |
260 | | - def __sycl_usm_array_interface__(self): |
261 | | - return None |
262 | | - |
263 | | - c = Canary() |
264 | | - with pytest.raises(ValueError): |
265 | | - dpt.greater(a, c) |
266 | | - |
267 | | - |
268 | 136 | def test_greater_mixed_integer_kinds(): |
269 | 137 | get_queue_or_skip() |
270 | 138 |
|
|
0 commit comments