|
1 | 1 | import functools |
2 | 2 |
|
| 3 | +import dpctl.tensor as dpt |
3 | 4 | import numpy |
4 | 5 | import pytest |
5 | 6 | from dpctl.tensor._numpy_helper import AxisError |
|
12 | 13 | ) |
13 | 14 |
|
14 | 15 | import dpnp |
| 16 | +from dpnp.dpnp_array import dpnp_array |
15 | 17 |
|
16 | 18 | from .helper import get_all_dtypes, get_integer_dtypes, has_support_aspect64 |
17 | 19 |
|
@@ -272,6 +274,57 @@ def test_indexing_array_negative_strides(self): |
272 | 274 | assert_array_equal(arr, 10.0) |
273 | 275 |
|
274 | 276 |
|
| 277 | +class TestIx: |
| 278 | + @pytest.mark.parametrize( |
| 279 | + "x0", [[0, 1], [True, True]], ids=["[0, 1]", "[True, True]"] |
| 280 | + ) |
| 281 | + @pytest.mark.parametrize( |
| 282 | + "x1", |
| 283 | + [[2, 4], [False, False, True, False, True]], |
| 284 | + ids=["[2, 4]", "[False, False, True, False, True]"], |
| 285 | + ) |
| 286 | + def test_ix(self, x0, x1): |
| 287 | + expected = dpnp.ix_(dpnp.array(x0), dpnp.array(x1)) |
| 288 | + result = numpy.ix_(numpy.array(x0), numpy.array(x1)) |
| 289 | + |
| 290 | + assert_array_equal(result[0], expected[0]) |
| 291 | + assert_array_equal(result[1], expected[1]) |
| 292 | + |
| 293 | + @pytest.mark.parametrize("dt", [dpnp.intp, dpnp.float32]) |
| 294 | + def test_ix_empty_out(self, dt): |
| 295 | + a = numpy.array([], dtype=dt) |
| 296 | + ia = dpnp.array(a) |
| 297 | + |
| 298 | + (result,) = dpnp.ix_(ia) |
| 299 | + (expected,) = numpy.ix_(a) |
| 300 | + assert_array_equal(result, expected) |
| 301 | + assert a.dtype == dt |
| 302 | + |
| 303 | + def test_repeated_input(self): |
| 304 | + a = numpy.arange(5) |
| 305 | + ia = dpnp.array(a) |
| 306 | + |
| 307 | + result = dpnp.ix_(ia, ia) |
| 308 | + expected = numpy.ix_(a, a) |
| 309 | + assert_array_equal(result[0], expected[0]) |
| 310 | + assert_array_equal(result[1], expected[1]) |
| 311 | + |
| 312 | + @pytest.mark.parametrize("arr", [[2, 4, 0, 1], [True, False, True, True]]) |
| 313 | + def test_usm_ndarray_input(self, arr): |
| 314 | + a = numpy.array(arr) |
| 315 | + ia = dpt.asarray(a) |
| 316 | + |
| 317 | + (result,) = dpnp.ix_(ia) |
| 318 | + (expected,) = numpy.ix_(a) |
| 319 | + assert_array_equal(result, expected) |
| 320 | + assert isinstance(result, dpnp_array) |
| 321 | + |
| 322 | + @pytest.mark.parametrize("xp", [dpnp, numpy]) |
| 323 | + @pytest.mark.parametrize("shape", [(), (2, 2)]) |
| 324 | + def test_ix_error(self, xp, shape): |
| 325 | + assert_raises(ValueError, xp.ix_, xp.ones(shape)) |
| 326 | + |
| 327 | + |
275 | 328 | class TestNonzero: |
276 | 329 | @pytest.mark.parametrize("list_val", [[], [0], [1]]) |
277 | 330 | def test_trivial(self, list_val): |
@@ -1143,37 +1196,6 @@ def test_empty_indices(self): |
1143 | 1196 | ) |
1144 | 1197 |
|
1145 | 1198 |
|
1146 | | -class TestIx: |
1147 | | - @pytest.mark.parametrize( |
1148 | | - "x0", [[0, 1], [True, True]], ids=["[0, 1]", "[True, True]"] |
1149 | | - ) |
1150 | | - @pytest.mark.parametrize( |
1151 | | - "x1", |
1152 | | - [[2, 4], [False, False, True, False, True]], |
1153 | | - ids=["[2, 4]", "[False, False, True, False, True]"], |
1154 | | - ) |
1155 | | - def test_ix(self, x0, x1): |
1156 | | - expected = dpnp.ix_(dpnp.array(x0), dpnp.array(x1)) |
1157 | | - result = numpy.ix_(numpy.array(x0), numpy.array(x1)) |
1158 | | - |
1159 | | - assert_array_equal(expected[0], result[0]) |
1160 | | - assert_array_equal(expected[1], result[1]) |
1161 | | - |
1162 | | - def test_ix_empty_out(self): |
1163 | | - (a,) = dpnp.ix_(dpnp.array([], dtype=dpnp.intp)) |
1164 | | - assert_equal(a.dtype, dpnp.intp) |
1165 | | - |
1166 | | - (a,) = dpnp.ix_(dpnp.array([], dtype=dpnp.float32)) |
1167 | | - assert_equal(a.dtype, dpnp.float32) |
1168 | | - |
1169 | | - def test_ix_error(self): |
1170 | | - with pytest.raises(ValueError): |
1171 | | - dpnp.ix_(dpnp.ones(())) |
1172 | | - |
1173 | | - with pytest.raises(ValueError): |
1174 | | - dpnp.ix_(dpnp.ones((2, 2))) |
1175 | | - |
1176 | | - |
1177 | 1199 | class TestSelect: |
1178 | 1200 | choices_np = [ |
1179 | 1201 | numpy.array([1, 2, 3]), |
|
0 commit comments