-
Notifications
You must be signed in to change notification settings - Fork 310
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
Itertools::multi_cartesian_product #235
Conversation
Itertools::multi_cartesian_product
Yes, please use its own file. Will review later, not sure when I have time. |
The 1.12 build is failing because of (at least) a syntax feature added in 1.17. Is there a reason that 1.12 is targeted? |
It's the current minimum version for itertools. Being a widely used library, we don't want to change that if we can avoid it. |
Thanks for working on this! This is a worthwhile feature that fits well inside the scope of itertools. There are several items that I'd like to be addressed with this code before it can be merged. Perhaps we can find a person from the community that can review it closer? Specifically look at
|
Thanks for taking the time to look at this.
I've reworked
After modifying
Could you elaborate on how it should behave please? Currently, at the end of iteration, a
I will look into this - I'm not quite sure what quickcheck achieves yet, but I'll do some research :) I've done some thinking about this adaptor API-wise, and could use your input: would we perhaps want to yield a wrapper struct which implements |
Great to see the progress
This is not even necessary. Fuse-preserving is good but we can't always have it. The most important part is to not call See qc tests in tests/quick.rs |
I've added some quickcheck tests equivalent to those already present for These seem to cover everything I was previously testing for in Additionally, I've added some benchmarks to compare to (Re: my suggestion to yield an iterable rather than a naked vec: I've realised that there is no type parameter to specify the type of Iterator you're collecting from :) so for the purpose of saving unnecessary memory copies, yielding vecs is probably best.) |
4f4e75d
to
327e55a
Compare
src/adaptors/multi_product.rs
Outdated
impl<I> ExactSizeIterator for MultiProduct<I> | ||
where I: ExactSizeIterator + Clone, | ||
I::Item: Clone | ||
{ } |
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.
It is not allowed to implement ESI since part of its contract is that the size of the iterator fits inside usize::max_value()
(and we can't ensure that). That kind of small change can be adjusted after merge.
Thanks for your solid work on this! |
src/adaptors/mod.rs
Outdated
@@ -332,7 +335,8 @@ impl<I, J> Iterator for Product<I, J> | |||
// Compute a * b_orig + b for both lower and upper bound | |||
size_hint::add( | |||
size_hint::mul(self.a.size_hint(), self.b_orig.size_hint()), | |||
(b_min * has_cur, b_max.map(move |x| x * has_cur))) | |||
(b_min * has_cur, b_max.map(move |x| x * has_cur)) | |||
) |
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.
changes unrelated to the PR in this file unfortunately (such should never be in the PR)
Could you do me a favour and clean up the commit history in the PR? how many commits it ends up with is not so imporant. If you don't do that, I can squash merge it in the end instead. |
Sure, I'll try and address your issues in the next day or so. |
327e55a
to
4873d84
Compare
4873d84
to
19edda4
Compare
Addressed your comments, removed some unnecessary casts, and squashed and rebased. You can see the latest actual changes here. |
Thank you! |
Hello!
I have created a new Itertools adaptor:
MultiProduct
. It is to be used on a meta-iterator (iterator which yield iterators) to produce the cartesian product of the iterators it yields. It is created by calling the.multi_cartesian_product()
method.This can be used, instead of the
iproduct
macro, when the number of iterators is not known at compile time.It currently uses a recursive function, which makes it susceptible to stack overflows for products with a huge number of elements. I could probably rework this to use a heap stack if desired, although I haven't thought about it too much so far.
It adds 7 new top-level items to
adaptors/mod.rs
, so maybe it'd be worth splitting into its own file?Any comments/questions, please let me know.