JuliaMath / Combinatorics.jl

A combinatorics library for Julia
http://juliamath.github.io/Combinatorics.jl/dev/
Other
214 stars 58 forks source link

Bug report: combinations does not work for Sets #119

Open schlichtanders opened 2 years ago

schlichtanders commented 2 years ago

to my full surprise the combinations function cannot deal with Sets directly.

As Sets support iterate and length, I think this is a bug

julia> collect(combinations(Set([1,2,3,4]), 2))
ERROR: MethodError: no method matching getindex(::Set{Int64}, ::Int64)
Stacktrace:
 [1] (::Combinatorics.var"#9#12"{Set{Int64}})(ci::Int64)
   @ Combinatorics ./none:0
 [2] iterate
   @ ./generator.jl:47 [inlined]
 [3] collect
   @ ./array.jl:724 [inlined]
 [4] reorder
   @ ~/.julia/packages/Combinatorics/Udg6X/src/combinations.jl:48 [inlined]
 [5] #10
   @ ./none:0 [inlined]
 [6] iterate
   @ ./generator.jl:47 [inlined]
 [7] collect(itr::Base.Generator{Combinatorics.Combinations, Combinatorics.var"#10#13"{Combinatorics.var"#reorder#11"{Set{Int64}}}})
   @ Base ./array.jl:724
 [8] top-level scope
   @ REPL[16]:1

Using Combinatorics v1.0.2 on Linux Julia 1.7.1

Stivanification commented 1 year ago

I don't think we should call this a bug, since the documentation for combinations says that it "generates all combinations of n elements from an indexable object". Since sets are not indexable, this behaviour is to be expected.