Opened 2 years ago

Closed 2 years ago

#28521 closed defect (fixed)

Bug of cartesian_product_iterator in Python3

Reported by: SimonKing Owned by:
Priority: major Milestone: sage-9.0
Component: python3 Keywords: cartesian_product_iterator
Cc: Merged in:
Authors: David Coudert Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: efb811c (Commits, GitHub, GitLab) Commit: efb811cbd86d92be1dc8336748d012f83d35ab85
Dependencies: Stopgaps:

Status badges

Description

In Sage-with-py3:

sage: list(cartesian_product_iterator([[],[1]]))
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
/home/king/Sage/git/py3/local/lib/python3.7/site-packages/sage/misc/mrange.py in _xmrange_iter(iter_list, typ)
    138     curr_iters = [iter(i) for i in iter_list]
--> 139     curr_elt = [next(i) for i in curr_iters[:-1]] + [None]
    140     place = len(iter_list) - 1

/home/king/Sage/git/py3/local/lib/python3.7/site-packages/sage/misc/mrange.py in <listcomp>(.0)
    138     curr_iters = [iter(i) for i in iter_list]
--> 139     curr_elt = [next(i) for i in curr_iters[:-1]] + [None]
    140     place = len(iter_list) - 1

StopIteration: 

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-10-4d60fd891cf3> in <module>()
----> 1 list(cartesian_product_iterator([[],[Integer(1)]]))

RuntimeError: generator raised StopIteration

When the second instead of the first of the two lists is empty, things work:

sage: list(cartesian_product_iterator([[1],[]]))
[]

In Sage-with-py2, things work as well:

sage: list(cartesian_product_iterator([[],[1]]))
[]

Change History (3)

comment:1 Changed 2 years ago by dcoudert

  • Authors set to David Coudert
  • Branch set to public/misc/28521_cartesian_product_iterator
  • Commit set to efb811cbd86d92be1dc8336748d012f83d35ab85
  • Status changed from new to needs_review

A simple fix. I don't know if there is a smatter way.


New commits:

efb811ctrac #28521: fix _xmrange_iter

comment:2 Changed 2 years ago by vdelecroix

  • Reviewers set to Vincent Delecroix
  • Status changed from needs_review to positive_review

comment:3 Changed 2 years ago by vbraun

  • Branch changed from public/misc/28521_cartesian_product_iterator to efb811cbd86d92be1dc8336748d012f83d35ab85
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.