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

Collect subsets of tuple #68

Open
JobJob opened this issue Dec 11, 2019 · 2 comments
Open

Collect subsets of tuple #68

JobJob opened this issue Dec 11, 2019 · 2 comments

Comments

@JobJob
Copy link

JobJob commented Dec 11, 2019

Is this a bug in IterTools?

julia> using IterTools
julia> collect(subsets((0,2,6), 2))

ERROR: MethodError: Cannot `convert` an object of type Tuple{Int64,Int64} to an object of type Array{Int64,1}
...
Stacktrace:
 [1] setindex!(::Array{Array{Int64,1},1}, ::Tuple{Int64,Int64}, ::Int64) at ./array.jl:767
 [2] copyto!(::Array{Array{Int64,1},1}, ::IterTools.Binomial{Tuple{Int64,Int64,Int64}}) at ./abstractarray.jl:671
 [3] _collect at ./array.jl:550 [inlined]
 [4] collect(::IterTools.Binomial{Tuple{Int64,Int64,Int64}}) at ./array.jl:544
 [5] top-level scope at none:0

This works though:

julia> collect(x for x in subsets((0,2,6), 2))
3-element Array{Tuple{Int64,Int64},1}:
 (0, 2)
 (0, 6)
 (2, 6)

Julia 1.1
IterTools 1.3

@JobJob
Copy link
Author

JobJob commented Dec 11, 2019

Ok I looked, the problem is that eltype(typeof(subsets((0,2,6), 2))) is Vector{Int64}

code here:

eltype(::Type{Binomial{C}}) where {C} = Vector{eltype(C)}

@iamed2
Copy link
Contributor

iamed2 commented Dec 11, 2019

Yes that's a bug. I think the best fix would be to have subsets(::Tuple, ::Any) use StaticSizeBinomial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants