-
-
Notifications
You must be signed in to change notification settings - Fork 409
Create containers with map instead of for loops #2070
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
Changes from 1 commit
8ce7535
05f4242
c771e5d
63ff9cc
974dfee
61d5e1a
bc881f7
37f9a0c
1192fd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
""" | ||
struct VectorizedProductIterator{T} | ||
prod::Iterators.ProductIterator{T} | ||
end | ||
Same as `Base.Iterators.ProductIterator` except that it is independent | ||
on the `IteratorSize` of the elements of `prod.iterators`. | ||
Cartesian product of the iterators `prod.iterators`. It is the same iterator as | ||
`Base.Iterators.ProductIterator` except that it is independent of the | ||
`IteratorSize` of the elements of `prod.iterators`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could benefit from a longer comment about why the behavior of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, every test passed with |
||
For instance: | ||
* `size(Iterators.product(1, 2))` is `tuple()` while | ||
`size(VectorizedProductIterator(1, 2))` is `(1, 1)`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@testset "Nested Iterator" begin | ||
iterators = (() -> 1:3, i -> 1:i) | ||
condition(i, j) = j > i | ||
@test isempty(Containers.nested(iterators..., condition=condition)) | ||
@test isempty(collect(Containers.nested(iterators..., condition=condition))) | ||
condition(i, j) = isodd(i) || isodd(j) | ||
@test collect(Containers.nested(iterators..., condition=condition)) == [ | ||
(1, 1) | ||
(2, 1) | ||
(3, 1) | ||
(3, 2) | ||
(3, 3) | ||
] | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@testset "Vectorized Product Iterator" begin | ||
I = [1 2 | ||
3 4] | ||
@test isempty(Containers.vectorized_product(2, I, 1:0)) | ||
@test isempty(collect(Containers.vectorized_product(2, I, 1:0))) | ||
@test collect(Containers.vectorized_product(2, I)) == [ | ||
(2, 1) (2, 3) (2, 2), (2, 4) | ||
] | ||
end |
Uh oh!
There was an error while loading. Please reload this page.