Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product iterator is not zipped properly #43921

Closed
aquohn opened this issue Jan 25, 2022 · 2 comments
Closed

Product iterator is not zipped properly #43921

aquohn opened this issue Jan 25, 2022 · 2 comments
Labels
domain:iteration Involves iteration or the iteration protocol good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior

Comments

@aquohn
Copy link

aquohn commented Jan 25, 2022

When zipping with a product iterator with no arguments (which produces only one output, the empty tuple), it seems the check for zip completion does not handle this case:

julia> for (z,) in zip(Iterators.product())
       @show z
       end
z = ()
ERROR: ArgumentError: tuple must be non-empty
Stacktrace:
 [1] first(#unused#::Tuple{})
   @ Base ./tuple.jl:140
 [2] _pisdone
   @ ./iterators.jl:1005 [inlined]
 [3] isdone
   @ ./iterators.jl:1012 [inlined]
 [4] _zip_isdone(is::Tuple{Base.Iterators.ProductIterator{Tuple{}}}, ss::Tuple{Tuple{Bool}})
   @ Base.Iterators ./iterators.jl:379
 [5] _zip_iterate_all
   @ ./iterators.jl:348 [inlined]
 [6] iterate
   @ ./iterators.jl:341 [inlined]
 [7] top-level scope
   @ ./REPL[79]:2

versioninfo() output:

Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = vim

EDIT: zip([()]) works fine though:

julia> for (z,) in zip([()])
       @show z
       end
z = ()

julia> 
@JeffBezanson JeffBezanson added kind:bug Indicates an unexpected problem or unintended behavior domain:iteration Involves iteration or the iteration protocol labels Jan 26, 2022
@JeffBezanson
Copy link
Sponsor Member

I think we just need this:

isdone(::Iterators.ProductIterator{Tuple{}}, states) = true

@JeffBezanson JeffBezanson added the good first issue Indicates a good issue for first-time contributors to Julia label Jan 26, 2022
sasi591 added a commit to sasi591/julia that referenced this issue Jan 27, 2022
@Aditya-Bhate

This comment was marked as duplicate.

@KristofferC KristofferC mentioned this issue Apr 19, 2022
40 tasks
KristofferC pushed a commit to sasi591/julia that referenced this issue Nov 2, 2022
KristofferC pushed a commit that referenced this issue Dec 14, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 14, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 14, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 14, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
staticfloat pushed a commit that referenced this issue Dec 23, 2022
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
KristofferC pushed a commit that referenced this issue Oct 10, 2023
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <kcarlsson89@gmail.com>
(cherry picked from commit b8a77da)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:iteration Involves iteration or the iteration protocol good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants