-
Notifications
You must be signed in to change notification settings - Fork 141
Add iterator for combinations #4735
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some more extensive tests? You can either get inspiration at https://github.com/Nemocas/AbstractAlgebra.jl/pull/2034/files#diff-9383dd485d4500b18b2bfa2797938c914f4a8df63c205e8ea8ddcfe23a1ad538 or test/Combinatorics/EnumerativeCombinatorics/compositions.jl
, but I would expect at least the following tests: edge-cases with zero (in particular combinations(0, 0)
), something with allunique
, testing the guaranteed iteration order (e.g. hardcoding the result of combinations(5,3)
which is the smallest example where lex and revlex order differ, and some large example with issorted
)
This implementation seems to be slower than julia> @b collect(AbstractAlgebra.combinations(5,3))
615.111 ns (28 allocs: 1.578 KiB)
julia> @b collect(combinations(5,3))
807.188 ns (34 allocs: 1.312 KiB)
julia> @b collect(AbstractAlgebra.combinations(15,10))
250.671 μs (6027 allocs: 547.938 KiB)
julia> @b collect(combinations(15,10))
280.748 μs (9014 allocs: 539.844 KiB)
julia> @b collect(AbstractAlgebra.combinations(18,9))
3.293 ms (97269 allocs: 7.905 MiB)
julia> @b collect(combinations(18,9))
5.897 ms (145865 allocs: 7.790 MiB) |
Added more tests and fixed the timings (usual inlining nonsense) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Just to say before anything becomes Official API: For the other functions of this kind (partitions, compositions, ...), we have a dedicated type |
I am not quite sure what value that would add here. |
We inherited the design from JuLie. From what I know, the idea was/is that this is helpful if one wants to work with combinations as objects themselves. So one can then write functions which take a combination as input or something. |
OK, makes sense. I can add that. |
Although, then it would not be a drop-in replacement for the current users of |
What about having a dedicated return type for calls to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice
end | ||
break | ||
end | ||
state[1] > C.n - C.k + 1 && return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe be explicit about returning nothing here, like in line 60?
state[1] > C.n - C.k + 1 && return | |
state[1] > C.n - C.k + 1 && return nothing |
Tagging triage to decide about the return type |
This looks good, and currently seems to be even a bit faster than the implementation used for The idea of having dedicated types is detailed here. Is there a reason it would break compatibility with the AbstractAlgebra version if it's done the same way as |
Discussed this in triage. My personal view: let's have this as Since we don't export During triage nobody (dared to) disagree. |
OK, I added a
It might provide enough functionality to still be usable in the LieAlgebra module (instead of |
@lgoettgens seems that the Lie algebra code is still happy with this change. Are you happy with it or should I restore the |
What guarantees does a |
No, the elements have no ordering. What is ordered are the indices in the lexicographically ascending ordering. (We only consider combinations of
No. The signature is
Yes, this seems to be the general opinion. |
Must the vector elements be distinct? If not, what is the behaviour? e.g. if the vector has length |
No, they don't have to be distinct and the example you give is the current behaviour. It is consistent with the other functions, e.g.,
|
One usually doesn't want the function checking for uniqueness as that may have a severe performance impact (think e.g. of MPolyIdeals). If this is not the behavior you want to have, you can call |
This was exactly the change the code in Could you also please remove the corresponding testset from |
No description provided.