Skip to content

Commit

Permalink
Implement ProductSet.__iter__ using product_cantor
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jan 30, 2016
1 parent 7b01884 commit cab56f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sympy/sets/sets.py
Expand Up @@ -624,8 +624,9 @@ def is_iterable(self):
return all(set.is_iterable for set in self.sets)

def __iter__(self):
from sympy.utilities.iterables import product_cantor
if self.is_iterable:
return itertools.product(*self.sets)
return product_cantor(*self.sets)
else:
raise TypeError("Not all constituent sets are iterable")

Expand Down
6 changes: 6 additions & 0 deletions sympy/sets/tests/test_fancysets.py
Expand Up @@ -262,3 +262,9 @@ def test_ImageSet_simplification():
assert imageset(Lambda(n, sin(n)),
imageset(Lambda(m, tan(m)), S.Integers)) == \
imageset(Lambda(m, sin(tan(m))), S.Integers)


def test_issue_10497():
# __iter__ for infinite product set
assert (list(itertools.islice(iter(S.Integers**2), 7)) ==
[(0, 0), (1, 0), (1, 1), (-1, 1), (-1, -1), (2, -1), (2, 2)])

0 comments on commit cab56f4

Please sign in to comment.