Skip to content
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

fix issue 25 #42

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/iterate_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ julia> for each in itercontrol(7, [1, 3, 4, 7], (1, 0, 1, 0))
# NOTE: positions should be vector (MVector is the best), since it need to be sorted
# do not use Tuple, or other immutables, it increases the sorting time.
function itercontrol(nbits::Int, positions::AbstractVector, bit_configs)
@assert all(x->iszero(x) || isone(x), bit_configs) "Bit configurations should be 0 or 1"
base = bmask(Int, positions[i] for (i, u) in enumerate(bit_configs) if u != 0)
masks, factors = group_shift!(nbits, positions)
S = length(masks)
Expand Down Expand Up @@ -111,6 +112,7 @@ function group_shift!(nbits::Int, positions::AbstractVector{Int})
k_prv = 0
i = 0
for k in positions
@assert k > k_prv "Conflict at location: $k"
if k != k_prv + 1
push!(factors, 1<<(k_prv-i))
gap = k - k_prv-1
Expand Down
5 changes: 5 additions & 0 deletions test/iterate_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ end
@test [ic...] == [ic[k] for k in 1:4]
end
end

@testset "regression test" begin
@test_throws AssertionError itercontrol(8, [8, 8], [1, 1])
@test_throws AssertionError itercontrol(8, [8], [-1])
end