-
Notifications
You must be signed in to change notification settings - Fork 79
More combinatorial functions #1026
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
More combinatorial functions #1026
Conversation
|
📖 Docs for this PR can be previewed here |
Codecov Report
@@ Coverage Diff @@
## main #1026 +/- ##
==========================================
+ Coverage 93.69% 93.71% +0.02%
==========================================
Files 26 26
Lines 20848 20920 +72
Branches 859 875 +16
==========================================
+ Hits 19533 19606 +73
Misses 1277 1277
+ Partials 38 37 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
eca6fc6 to
2e6920b
Compare
|
This is ready for review now I think. The main thing that's added is the I've made sure that the generated trees are identical to the trees we'd get from unrank, and documented how we allocate internal nodes there. @daniel-goldstein, would you mind taking a quick look here to makre sure I haven't done anything silly? |
2e6920b to
5939fe6
Compare
|
@benjeffery - any idea how we should do abstract test classes using pytest? It's annoying me that we need to duplicate the code for tests like Also, good to get your thoughts on the style that's evolving here for pytest... |
|
Well you can still use a Mixin if you like! Often i think a plain function at module-level is simpler, but there are times Mixins feel right. Generally i think the tests here look good - using the parameterisation decorator is good as it isolates failing cases easily, note that if you want all combinations you can stack the decorator. Also I like that we're grouping tests by class. |
5939fe6 to
0a083b0
Compare
|
@benjeffery, any chance of another look at the tests? I'm quite pleased how this turned out, might be quite a nice pattern to adopt/adapt elsewhere? |
0a083b0 to
b879c24
Compare
I've just realised another way to do this as you can parameterise a whole class: @pytest.mark.parametrize('method', ["flip", "catch", "hurl"])
class TestCommonsStuff:
def test_foobar(self, method):
assert ....
def test_other(self, method):
assert ....and then put the specific tests in their own class. It is a matter of taste as always - I find what you have already very clear. |
|
Good idea @benjeffery! I think I'll stick with the subclasses here as it's nice to be able to tack on extra specific tests as well as the common ones. |
- Tree.generate_balanced and improvements to unrank. - Update some of the testing code for combinatorial functions. - Add Tree.generate_comb. - Implement balanced tree for arbitrary arity.
b879c24 to
645ae81
Compare
|
Thanks for the feedback, I've addressed your comments @hyanwong. I'm marked this as "merge-ready" so it just needs an approval and it'll go in. |
|
Sorry spent all yesterday moving out for the holidays. I can still give it a look now if you'd like |
That would be great, thanks @daniel-goldstein! No particular hurry. |
daniel-goldstein
left a comment
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.
This looks really great! Loving the pytest decorators. Just one little comment
| raise ValueError("Number of chunks must be a positive integer") | ||
|
|
||
| if n > 0: | ||
| chunk_size = max(1, n // k) |
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.
Can you do this instead with yield from itertools.islice(lst, chunk_size)?
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.
Hey, good idea. No, I don't think islice will do it, the semantics of what we want are really quite specific in order to line up with the unranked trees. numpy has a function which almost does what we want, but not quite.
Adds some more generators for common tree shapes, and makes some overall improvements to the combintorics code.
Supersedes #944
PR Checklist: