-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
dpnp.ndarray.__iter__
method (#2206)
The PR proposes to add implementation of `dpnp.ndarray.__iter__` method. The new code is assumed to be covered by third party tests. - [x] Have you provided a meaningful PR description? - [ ] Have you added a test, reproducer or referred to issue with a reproducer? - [x] Have you tested your changes locally for CPU and GPU devices? - [x] Have you made sure that new changes do not introduce compiler warnings? - [ ] Have you checked performance impact of proposed changes? - [ ] If this PR is a work in progress, are you filing the PR as a draft?
- Loading branch information
1 parent
fbc9529
commit d36bc85
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import unittest | ||
|
||
import numpy | ||
import pytest | ||
|
||
import dpnp as cupy | ||
from dpnp.tests.third_party.cupy import testing | ||
|
||
|
||
@testing.parameterize( | ||
*testing.product( | ||
{"shape": [(3,), (2, 3, 4), (0,), (0, 2), (3, 0)]}, | ||
) | ||
) | ||
class TestIter(unittest.TestCase): | ||
|
||
@testing.for_all_dtypes() | ||
@testing.numpy_cupy_array_equal() | ||
def test_list(self, xp, dtype): | ||
x = testing.shaped_arange(self.shape, xp, dtype) | ||
return list(x) | ||
|
||
@testing.for_all_dtypes() | ||
@testing.numpy_cupy_equal() | ||
def test_len(self, xp, dtype): | ||
x = testing.shaped_arange(self.shape, xp, dtype) | ||
return len(x) | ||
|
||
|
||
class TestIterInvalid(unittest.TestCase): | ||
|
||
@testing.for_all_dtypes() | ||
def test_iter(self, dtype): | ||
for xp in (numpy, cupy): | ||
x = testing.shaped_arange((), xp, dtype) | ||
with pytest.raises(TypeError): | ||
iter(x) | ||
|
||
@testing.for_all_dtypes() | ||
def test_len(self, dtype): | ||
for xp in (numpy, cupy): | ||
x = testing.shaped_arange((), xp, dtype) | ||
with pytest.raises(TypeError): | ||
len(x) |