|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import unittest |
2 | 4 | import warnings |
3 | 5 |
|
|
6 | 8 |
|
7 | 9 | import dpnp as cupy |
8 | 10 | from dpnp.tests.third_party.cupy import testing |
| 11 | +from dpnp.tests.third_party.cupy.testing._protocol_helpers import ( |
| 12 | + DummyObjectWithCudaArrayInterface, |
| 13 | + DummyObjectWithCuPyGetNDArray, |
| 14 | +) |
9 | 15 |
|
10 | 16 | if numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0b1": |
11 | 17 | from numpy.exceptions import ComplexWarning |
|
130 | 136 | ) |
131 | 137 | class TestArrayIndexingParameterized(unittest.TestCase): |
132 | 138 |
|
| 139 | + _getitem_hip_skip_condition = [ |
| 140 | + ((1, 0, 2), (2, 3, 4), None), |
| 141 | + ((-1, 0, -2), (2, 3, 4), None), |
| 142 | + ((1, 0, 2), (2, 3, 4), (2, 0, 1)), |
| 143 | + ((-1, 0, -2), (2, 3, 4), (2, 0, 1)), |
| 144 | + ((slice(None, None, None), None), (2,), None), |
| 145 | + ((slice(-9, -10, -1),), (10,), None), |
| 146 | + ((slice(-4, -5, -1),), (10,), None), |
| 147 | + ((slice(-5, -6, -1),), (10,), None), |
| 148 | + ] |
| 149 | + |
| 150 | + def _check_getitem_hip_skip_condition(self): |
| 151 | + return ( |
| 152 | + self.indexes, |
| 153 | + self.shape, |
| 154 | + self.transpose, |
| 155 | + ) in self._getitem_hip_skip_condition |
| 156 | + |
133 | 157 | @testing.for_all_dtypes() |
134 | 158 | @testing.numpy_cupy_array_equal() |
135 | 159 | def test_getitem(self, xp, dtype): |
| 160 | + # if cupy.cuda.runtime.is_hip: |
| 161 | + # if self._check_getitem_hip_skip_condition(): |
| 162 | + # pytest.xfail("HIP may have a bug") |
136 | 163 | a = testing.shaped_arange(self.shape, xp, dtype) |
137 | 164 | if self.transpose: |
138 | 165 | a = a.transpose(self.transpose) |
@@ -261,3 +288,18 @@ def test_remain0d(self, xp): |
261 | 288 | a = xp.zeros((2, 3, 4), dtype=dtype) |
262 | 289 | a[0, 1, 2] = testing.shaped_arange((), xp, dtype) |
263 | 290 | return a |
| 291 | + |
| 292 | + |
| 293 | +@pytest.mark.skip("CUDA array interface is not supported") |
| 294 | +@pytest.mark.parametrize( |
| 295 | + "cupy_like", |
| 296 | + [ |
| 297 | + DummyObjectWithCuPyGetNDArray, |
| 298 | + DummyObjectWithCudaArrayInterface, |
| 299 | + ], |
| 300 | +) |
| 301 | +def test_setitem_with_cupy_like(cupy_like): |
| 302 | + # Test that normal assignment supports interfaces |
| 303 | + a = cupy.zeros(10) |
| 304 | + a[...] = cupy_like(cupy.arange(10)) |
| 305 | + testing.assert_array_equal(a, cupy.arange(10)) |
0 commit comments