|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
17 | | -import ctypes |
18 | 17 | import itertools |
19 | 18 |
|
20 | 19 | import numpy as np |
21 | 20 | import pytest |
22 | 21 | from numpy.testing import assert_array_equal |
23 | 22 |
|
24 | | -import dpctl |
25 | 23 | import dpctl.tensor as dpt |
26 | 24 | from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported |
27 | 25 |
|
28 | | -from .utils import _all_dtypes, _compare_dtypes, _usm_types |
| 26 | +from .utils import _all_dtypes, _compare_dtypes |
29 | 27 |
|
30 | 28 |
|
31 | 29 | @pytest.mark.parametrize("op1_dtype", _all_dtypes) |
@@ -172,143 +170,3 @@ def test_maximum_minimum_complex_special_cases(dtype): |
172 | 170 | Rnp = np.minimum(Xnp, Ynp) |
173 | 171 | assert_array_equal(dpt.asnumpy(dpt.real(R)), np.real(Rnp)) |
174 | 172 | assert_array_equal(dpt.asnumpy(dpt.imag(R)), np.imag(Rnp)) |
175 | | - |
176 | | - |
177 | | -@pytest.mark.parametrize("op1_usm_type", _usm_types) |
178 | | -@pytest.mark.parametrize("op2_usm_type", _usm_types) |
179 | | -def test_maximum_minimum_usm_type_matrix(op1_usm_type, op2_usm_type): |
180 | | - get_queue_or_skip() |
181 | | - |
182 | | - sz = 128 |
183 | | - ar1_np = np.arange(sz, dtype="i4") |
184 | | - np.random.shuffle(ar1_np) |
185 | | - ar1 = dpt.asarray(ar1_np, usm_type=op1_usm_type) |
186 | | - ar2_np = np.arange(sz, dtype="i4") |
187 | | - np.random.shuffle(ar2_np) |
188 | | - ar2 = dpt.asarray(ar2_np, usm_type=op2_usm_type) |
189 | | - |
190 | | - r = dpt.maximum(ar1, ar2) |
191 | | - assert isinstance(r, dpt.usm_ndarray) |
192 | | - expected_usm_type = dpctl.utils.get_coerced_usm_type( |
193 | | - (op1_usm_type, op2_usm_type) |
194 | | - ) |
195 | | - assert r.usm_type == expected_usm_type |
196 | | - |
197 | | - r = dpt.minimum(ar1, ar2) |
198 | | - assert isinstance(r, dpt.usm_ndarray) |
199 | | - expected_usm_type = dpctl.utils.get_coerced_usm_type( |
200 | | - (op1_usm_type, op2_usm_type) |
201 | | - ) |
202 | | - assert r.usm_type == expected_usm_type |
203 | | - |
204 | | - |
205 | | -def test_maximum_minimum_order(): |
206 | | - get_queue_or_skip() |
207 | | - |
208 | | - ar1_np = np.arange(20 * 20, dtype="i4").reshape(20, 20) |
209 | | - np.random.shuffle(ar1_np) |
210 | | - ar1 = dpt.asarray(ar1_np, order="C") |
211 | | - ar2_np = np.arange(20 * 20, dtype="i4").reshape(20, 20) |
212 | | - np.random.shuffle(ar2_np) |
213 | | - ar2 = dpt.asarray(ar2_np, order="C") |
214 | | - |
215 | | - r1 = dpt.maximum(ar1, ar2, order="C") |
216 | | - assert r1.flags.c_contiguous |
217 | | - r2 = dpt.maximum(ar1, ar2, order="F") |
218 | | - assert r2.flags.f_contiguous |
219 | | - r3 = dpt.maximum(ar1, ar2, order="A") |
220 | | - assert r3.flags.c_contiguous |
221 | | - r4 = dpt.maximum(ar1, ar2, order="K") |
222 | | - assert r4.flags.c_contiguous |
223 | | - |
224 | | - ar1 = dpt.asarray(ar1_np, order="F") |
225 | | - ar2 = dpt.asarray(ar2_np, order="F") |
226 | | - r1 = dpt.maximum(ar1, ar2, order="C") |
227 | | - assert r1.flags.c_contiguous |
228 | | - r2 = dpt.maximum(ar1, ar2, order="F") |
229 | | - assert r2.flags.f_contiguous |
230 | | - r3 = dpt.maximum(ar1, ar2, order="A") |
231 | | - assert r3.flags.f_contiguous |
232 | | - r4 = dpt.maximum(ar1, ar2, order="K") |
233 | | - assert r4.flags.f_contiguous |
234 | | - |
235 | | - ar1_np = np.arange(40 * 40, dtype="i4").reshape(40, 40) |
236 | | - np.random.shuffle(ar1_np) |
237 | | - ar1 = dpt.asarray(ar1_np, order="C")[:20, ::-2] |
238 | | - ar2_np = np.arange(40 * 40, dtype="i4").reshape(40, 40) |
239 | | - np.random.shuffle(ar2_np) |
240 | | - ar2 = dpt.asarray(ar2_np, order="C")[:20, ::-2] |
241 | | - r4 = dpt.maximum(ar1, ar2, order="K") |
242 | | - assert r4.strides == (20, -1) |
243 | | - |
244 | | - ar1 = dpt.asarray(ar1_np, order="C")[:20, ::-2].mT |
245 | | - ar2 = dpt.asarray(ar2_np, order="C")[:20, ::-2].mT |
246 | | - r4 = dpt.maximum(ar1, ar2, order="K") |
247 | | - assert r4.strides == (-1, 20) |
248 | | - |
249 | | - |
250 | | -@pytest.mark.parametrize("arr_dt", _all_dtypes) |
251 | | -def test_maximum_minimum_python_scalar(arr_dt): |
252 | | - q = get_queue_or_skip() |
253 | | - skip_if_dtype_not_supported(arr_dt, q) |
254 | | - |
255 | | - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) |
256 | | - py_ones = ( |
257 | | - bool(1), |
258 | | - int(1), |
259 | | - float(1), |
260 | | - complex(1), |
261 | | - np.float32(1), |
262 | | - ctypes.c_int(1), |
263 | | - ) |
264 | | - for sc in py_ones: |
265 | | - R = dpt.maximum(X, sc) |
266 | | - assert isinstance(R, dpt.usm_ndarray) |
267 | | - R = dpt.maximum(sc, X) |
268 | | - assert isinstance(R, dpt.usm_ndarray) |
269 | | - |
270 | | - R = dpt.minimum(X, sc) |
271 | | - assert isinstance(R, dpt.usm_ndarray) |
272 | | - R = dpt.minimum(sc, X) |
273 | | - assert isinstance(R, dpt.usm_ndarray) |
274 | | - |
275 | | - |
276 | | -class MockArray: |
277 | | - def __init__(self, arr): |
278 | | - self.data_ = arr |
279 | | - |
280 | | - @property |
281 | | - def __sycl_usm_array_interface__(self): |
282 | | - return self.data_.__sycl_usm_array_interface__ |
283 | | - |
284 | | - |
285 | | -def test_maximum_minimum_mock_array(): |
286 | | - get_queue_or_skip() |
287 | | - a = dpt.arange(10) |
288 | | - b = dpt.ones(10) |
289 | | - c = MockArray(b) |
290 | | - r = dpt.maximum(a, c) |
291 | | - assert isinstance(r, dpt.usm_ndarray) |
292 | | - |
293 | | - r = dpt.minimum(a, c) |
294 | | - assert isinstance(r, dpt.usm_ndarray) |
295 | | - |
296 | | - |
297 | | -def test_maximum_canary_mock_array(): |
298 | | - get_queue_or_skip() |
299 | | - a = dpt.arange(10) |
300 | | - |
301 | | - class Canary: |
302 | | - def __init__(self): |
303 | | - pass |
304 | | - |
305 | | - @property |
306 | | - def __sycl_usm_array_interface__(self): |
307 | | - return None |
308 | | - |
309 | | - c = Canary() |
310 | | - with pytest.raises(ValueError): |
311 | | - dpt.maximum(a, c) |
312 | | - |
313 | | - with pytest.raises(ValueError): |
314 | | - dpt.minimum(a, c) |
0 commit comments