Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
version:
- '1.1'
- '1'
os:
- ubuntu-latest
arch:
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ version = "0.1.0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RegisterCore = "67712758-55e7-5c3c-8e85-dda1d7758434"

[compat]
julia = "^1.1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
22 changes: 11 additions & 11 deletions src/RegisterUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ end
Counter(sz::Tuple) = Counter(Int[sz...])
function Base.iterate(c::Counter)
N = length(c.max)
(N == 0 || any(c.max.<=0)) && return nothing
state = ones(Int,N)
copy(state), state
(N == 0 || any(c.max .<= 0)) && return nothing
state = ones(Int, N)
return copy(state), state
end
function Base.iterate(c::Counter, state)
state[1] += 1
Expand All @@ -25,7 +25,7 @@ function Base.iterate(c::Counter, state)
state[i] += 1
end
state[end] > c.max[end] && return nothing
copy(state), state
return copy(state), state
end

# Below functions are from RegisterTestUtilities
Expand All @@ -37,19 +37,19 @@ export quadratic, block_center, tighten
function quadratic(m, n, shift, Q)
A = zeros(m, n)
c = block_center(m, n)
cntr = [shift[1]+c[1], shift[2]+c[2]]
cntr = [shift[1] + c[1], shift[2] + c[2]]
u = zeros(2)
for j = 1:n, i = 1:m
u[1], u[2] = i-cntr[1], j-cntr[2]
A[i,j] = dot(u,Q*u)
for j in 1:n, i in 1:m
u[1], u[2] = i - cntr[1], j - cntr[2]
A[i, j] = dot(u, Q * u)
end
A
return A
end

quadratic(shift, Q, denom::Matrix) = MismatchArray(quadratic(size(denom)..., shift, Q), denom)

function block_center(sz...)
ntuple(i->sz[i]>>1+1, length(sz))
return ntuple(i -> sz[i] >> 1 + 1, length(sz))
end

function tighten(A::AbstractArray)
Expand All @@ -58,7 +58,7 @@ function tighten(A::AbstractArray)
T = promote_type(T, typeof(a))
end
At = similar(A, T)
copyto!(At, A)
return copyto!(At, A)
end

end
22 changes: 14 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ using Test
using RegisterUtilities

@testset "Counter test" begin
for empty_gridsize in ((), (0,), (1,0), (1,-1), (1,0,1))
for empty_gridsize in ((), (0,), (1, 0), (1, -1), (1, 0, 1))
for c in Counter(empty_gridsize)
@test c == nothing
end
end
for (gridsize, index_vec) in (((1,),[[1]]), ((2,3),[[1,1],[2,1],[1,2],[2,2],[1,3],[2,3]]),
((2,3,4), [[1, 1, 1],[2, 1, 1],[1, 2, 1],[2, 2, 1],[1, 3, 1],[2, 3, 1],
[1, 1, 2],[2, 1, 2],[1, 2, 2],[2, 2, 2],[1, 3, 2],[2, 3, 2],
[1, 1, 3],[2, 1, 3],[1, 2, 3],[2, 2, 3],[1, 3, 3],[2, 3, 3],
[1, 1, 4],[2, 1, 4],[1, 2, 4],[2, 2, 4],[1, 3, 4],[2, 3, 4]]))
cnt = Array{Array{Int64,1},1}()
for (gridsize, index_vec) in (
((1,), [[1]]), ((2, 3), [[1, 1], [2, 1], [1, 2], [2, 2], [1, 3], [2, 3]]),
(
(2, 3, 4), [
[1, 1, 1], [2, 1, 1], [1, 2, 1], [2, 2, 1], [1, 3, 1], [2, 3, 1],
[1, 1, 2], [2, 1, 2], [1, 2, 2], [2, 2, 2], [1, 3, 2], [2, 3, 2],
[1, 1, 3], [2, 1, 3], [1, 2, 3], [2, 2, 3], [1, 3, 3], [2, 3, 3],
[1, 1, 4], [2, 1, 4], [1, 2, 4], [2, 2, 4], [1, 3, 4], [2, 3, 4],
],
),
)
cnt = Array{Array{Int64, 1}, 1}()
for c in Counter(gridsize)
push!(cnt,c)
push!(cnt, c)
end
@test cnt == index_vec
end
Expand Down
Loading