-
Notifications
You must be signed in to change notification settings - Fork 11
Fix iterator tests #54
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| @testitem "iterators.jl" begin | ||
| @testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (single iterator)" begin | ||
| len = 15 | ||
| weight = 7 | ||
| sgc = CodingTheory.SubsetGrayCode(len, weight) | ||
| len = 7 | ||
| weight = 5 | ||
| sgc = CodingTheory.SubsetGrayCode(len, weight, UInt(21), UInt(0)) | ||
| all_subsets_gray = fill(fill(0, weight), length(sgc)) | ||
| subset = collect(1:sgc.k) | ||
| state = (subset, 1, fill(-1, 3)) | ||
|
|
@@ -16,44 +16,7 @@ | |
| sort!(all_subsets_gray) | ||
| all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight) | ||
| sort!(all_subsets_hecke) | ||
| @test length(all_subsets_gray) == 6435 | ||
| @test all_subsets_gray == all_subsets_hecke | ||
| end | ||
|
|
||
| @testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (split iterator)" begin | ||
| len = 15 | ||
| weight = 7 | ||
| num_threads = 3 # split the iterator into 3 parts | ||
| itrs = CodingTheory._subset_gray_codes_from_num_threads(len, weight, num_threads) | ||
| @test length(itrs) == num_threads | ||
| initial_subset_vecs = fill(fill(0, weight), length(itrs)) | ||
| bin = extended_binomial(len, weight) | ||
| for j in eachindex(itrs) | ||
| itr = itrs[j] | ||
| @test length(itr) == fld(bin, num_threads) | ||
| subset_vec = zeros(Int, itr.k) | ||
| CodingTheory._subset_unrank!(itr.init_rank, UInt(itr.n), subset_vec) | ||
| initial_subset_vecs[j] = subset_vec | ||
| end | ||
|
|
||
| all_subsets_gray = fill(fill(0, weight), bin) | ||
|
|
||
| for j in 0:length(itrs)-1 | ||
| sgc = itrs[j + 1] | ||
| subset_vec = initial_subset_vecs[j + 1] | ||
| state = (subset_vec, 1, fill(-1, 3)) | ||
| for i in 1:length(sgc) | ||
| all_subsets_gray[j * fld(bin, num_threads) + i] = deepcopy(subset_vec) | ||
| next = iterate(sgc, state) | ||
| isnothing(next) && break | ||
| (_, state) = next | ||
| (subset_vec, _, _) = state | ||
| end | ||
| end | ||
| sort!(all_subsets_gray) | ||
| all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight) | ||
| sort!(all_subsets_hecke) | ||
| @test length(all_subsets_gray) == 6435 | ||
| @test length(all_subsets_gray) == 21 | ||
| @test all_subsets_gray == all_subsets_hecke | ||
| end | ||
|
|
||
|
|
@@ -79,28 +42,28 @@ | |
| k1 = UInt(3) | ||
| n1 = UInt(5) | ||
| rank1 = CodingTheory._subset_rank(subset1, k1) | ||
| @test rank1 == 0 | ||
| @test rank1 == 1 | ||
|
Collaborator
Author
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. iterators were changed to index from 1 and Id forgeten to change the test |
||
| result1 = zeros(Int, k1) | ||
| CodingTheory._subset_unrank!(rank1, n1, result1) | ||
| CodingTheory._subset_unrank!(UInt128(rank1), n1, result1) | ||
| @test result1 == subset1 | ||
|
|
||
| subset2 = UInt.([1, 3, 5]) | ||
| k2 = UInt(3) | ||
| n2 = UInt(5) | ||
| rank2 = CodingTheory._subset_rank(subset2, k2) | ||
| @test rank2 == 7 | ||
| @test rank2 == 8 | ||
| result2 = zeros(Int, k2) | ||
| CodingTheory._subset_unrank!(rank2, n2, result2) | ||
| CodingTheory._subset_unrank!(UInt128(rank2), n2, result2) | ||
| @test result2 == subset2 | ||
|
|
||
| k3 = UInt(3) | ||
| n3 = UInt(5) | ||
| result3 = zeros(Int, k3) | ||
| results = Set() | ||
| results = Set{Vector{UInt64}}() | ||
| bin = binomial(n3, k3) | ||
| for i::BigInt in collect(0: bin - 1) | ||
| CodingTheory._subset_unrank!(i, n3, result3) | ||
| pushOrDel!(results, deepcopy(result3)) | ||
| for i::BigInt in collect(1: bin) | ||
| CodingTheory._subset_unrank!(UInt128(i), n3, result3) | ||
| pushOrDel!(results, deepcopy(Vector{UInt64}(result3))) | ||
| end | ||
| all_subsets_hecke = Set(CodingTheory.Hecke.subsets(collect(1:n3), Int(k3))) | ||
| @test results == all_subsets_hecke | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
removed this test b/c not breaking itr up this way anymore