JuliaCollections / IterTools.jl

Common functional iterator patterns
Other
153 stars 29 forks source link

MethodError using IterTools.product #38

Closed mforets closed 6 years ago

mforets commented 6 years ago

in v0.6:

julia> using IterTools

julia> R = Iterators.repeated([1, -1], 2)
Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}(Base.Iterators.Repeated{Array{Int64,1}}([1, -1]), 2)

julia> collect(R)
2-element Array{Array{Int64,1},1}:
 [1, -1]
 [1, -1]

julia> IterTools.product(R)
IterTools.Product{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}((Base.Iterators.Take{Base.Iterators.Repeated{Array{
Int64,1}}}(Base.Iterators.Repeated{Array{Int64,1}}([1, -1]), 2),))

julia> collect(IterTools.product(R))
2-element Array{Tuple{Array{Int64,1}},1}:
 ([1, -1],)
 ([1, -1],)

in v0.7.0-beta2.0

julia> using IterTools

julia> R = Iterators.repeated([1, -1], 2)
Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}(Base.Iterators.Repeated{Array{Int64,1}}([1, -1]), 2)

julia>  collect(R)
2-element Array{Array{Int64,1},1}:
 [1, -1]
 [1, -1]

julia>  IterTools.product(R)
┌ Warning: `product(xss...)` is deprecated, use `Iterators.product(xss...)` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}((Base.Iterators.Take{Base.Iterators.Re
peated{Array{Int64,1}}}(Base.Iterators.Repeated{Array{Int64,1}}([1, -1]), 2),))

julia>  collect(IterTools.product(R))
┌ Warning: `product(xss...)` is deprecated, use `Iterators.product(xss...)` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
ERROR: MethodError: no method matching isless(::Array{Int64,1}, ::Int64)
Closest candidates are:

  isless(::Missing, ::Any) at missing.jl:66
  isless(::AbstractFloat, ::Real) at operators.jl:150
  isless(::Real, ::Real) at operators.jl:338
  ...
Stacktrace:
 [1] <(::Array{Int64,1}, ::Int64) at ./operators.jl:260
 [2] <=(::Array{Int64,1}, ::Int64) at ./operators.jl:309
 [3] isdone(::Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}, ::Tuple{Array{Int64,1},Tuple{Int64,Nothing}}) at ./iterators.j
l:587
 [4] _pisdone at ./iterators.jl:805 [inlined]
 [5] isdone at ./iterators.jl:811 [inlined]
 [6] iterate at ./iterators.jl:843 [inlined]
 [7] copyto! at ./abstractarray.jl:658 [inlined]
 [8] _collect(::UnitRange{Int64}, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}, :
:Base.HasEltype, ::Base.HasShape{1}) at ./array.jl:538
 [9] collect(::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}) at ./array.jl:532
 [10] top-level scope at none:0

could you confirm that this is a unresolved issue? or i need to upgrade some of the packages in my workflow? thanks.

iamed2 commented 6 years ago

This appears to be a bug in Julia's Iterators, probably in the implementation for isdone.

julia> collect(Iterators.product([[1, -1], [1, -1]]))
2-element Array{Tuple{Array{Int64,1}},1}:
 ([1, -1],)
 ([1, -1],)

julia> collect(Iterators.product(Iterators.repeated([1, -1], 2)))
ERROR: MethodError: no method matching isless(::Array{Int64,1}, ::Int64)
Closest candidates are:
  isless(::Missing, ::Any) at missing.jl:66
  isless(::AbstractFloat, ::Real) at operators.jl:150
  isless(::Real, ::Real) at operators.jl:338
  ...
Stacktrace:
 [1] <(::Array{Int64,1}, ::Int64) at ./operators.jl:260
 [2] <=(::Array{Int64,1}, ::Int64) at ./operators.jl:309
 [3] isdone(::Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}, ::Tuple{Array{Int64,1},Tuple{Int64,Nothing}}) at ./iterators.jl:588
 [4] _pisdone at ./iterators.jl:806 [inlined]
 [5] isdone at ./iterators.jl:812 [inlined]
 [6] iterate at ./iterators.jl:844 [inlined]
 [7] copyto! at ./abstractarray.jl:658 [inlined]
 [8] _collect(::UnitRange{Int64}, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}, ::Base.HasEltype, ::Base.HasShape{1}) at ./array.jl:563
 [9] collect(::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Array{Int64,1}}}}}) at ./array.jl:557
 [10] top-level scope at none:0
iamed2 commented 6 years ago

Thanks for reporting, I'll look into the Julia issue

KristofferC commented 6 years ago

Seems fixed?

mforets commented 6 years ago

Yes.