|
| 1 | +import unittest |
| 2 | + |
| 3 | +import numpy |
| 4 | +import pytest |
| 5 | + |
| 6 | +import dpnp as cupy |
| 7 | +from dpnp.tests.third_party.cupy import testing |
| 8 | + |
| 9 | + |
| 10 | +@testing.parameterize( |
| 11 | + *testing.product( |
| 12 | + {"shape": [(3,), (2, 3, 4), (0,), (0, 2), (3, 0)]}, |
| 13 | + ) |
| 14 | +) |
| 15 | +class TestIter(unittest.TestCase): |
| 16 | + |
| 17 | + @testing.for_all_dtypes() |
| 18 | + @testing.numpy_cupy_array_equal() |
| 19 | + def test_list(self, xp, dtype): |
| 20 | + x = testing.shaped_arange(self.shape, xp, dtype) |
| 21 | + return list(x) |
| 22 | + |
| 23 | + @testing.for_all_dtypes() |
| 24 | + @testing.numpy_cupy_equal() |
| 25 | + def test_len(self, xp, dtype): |
| 26 | + x = testing.shaped_arange(self.shape, xp, dtype) |
| 27 | + return len(x) |
| 28 | + |
| 29 | + |
| 30 | +class TestIterInvalid(unittest.TestCase): |
| 31 | + |
| 32 | + @testing.for_all_dtypes() |
| 33 | + def test_iter(self, dtype): |
| 34 | + for xp in (numpy, cupy): |
| 35 | + x = testing.shaped_arange((), xp, dtype) |
| 36 | + with pytest.raises(TypeError): |
| 37 | + iter(x) |
| 38 | + |
| 39 | + @testing.for_all_dtypes() |
| 40 | + def test_len(self, dtype): |
| 41 | + for xp in (numpy, cupy): |
| 42 | + x = testing.shaped_arange((), xp, dtype) |
| 43 | + with pytest.raises(TypeError): |
| 44 | + len(x) |
0 commit comments