Skip to content

Commit d5b7873

Browse files
authored
More robust tests (#12)
1 parent 759ed65 commit d5b7873

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Coloring algorithms for sparse Jacobian and Hessian matrices.
1313
To install this package, run the following in a Julia Pkg REPL:
1414

1515
```julia
16-
pkg> add https://github.com/gdalle/SparseMatrixColorings.jl
16+
pkg> add SparseMatrixColorings
1717
```
1818

1919
## Background

src/coloring.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function star_coloring(g::Graph, order::AbstractOrder)
7575
# Initialize data structures
7676
color = zeros(Int, length(g))
7777
forbidden_colors = zeros(Int, length(g))
78-
first_neighbor = Vector{Tuple{Int,Int}}(undef, length(g))
78+
first_neighbor = fill((0, 0), length(g)) # at first no neighbors have been encountered
7979
treated = zeros(Int, length(g))
8080
star = Dict{Tuple{Int,Int},Int}()
8181
hub = Int[]
@@ -137,13 +137,13 @@ end
137137

138138
function _update_stars!(
139139
# modified
140-
star,
140+
star::Dict{<:Tuple,<:Integer},
141141
hub::AbstractVector{<:Integer},
142142
# not modified
143143
g::Graph,
144144
v::Integer,
145145
color::AbstractVector{<:Integer},
146-
first_neighbor::AbstractVector{<:Tuple{<:Integer,<:Integer}},
146+
first_neighbor::AbstractVector{<:Tuple},
147147
)
148148
for w in neighbors(g, v)
149149
iszero(color[w]) && continue

src/matrices.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ Used for internal testing.
1212
"""
1313
function matrix_versions(A)
1414
A_dense = Matrix(A)
15-
A_sparse = SparseMatrixCSC(A)
15+
A_sparse = sparse(A)
1616
versions = [
1717
A_dense,
1818
transpose(Matrix(transpose(A_dense))),
1919
adjoint(Matrix(adjoint(A_dense))),
2020
A_sparse,
21-
transpose(SparseMatrixCSC(transpose(A_sparse))),
22-
adjoint(SparseMatrixCSC(adjoint(A_sparse))),
21+
transpose(sparse(transpose(A_sparse))),
22+
adjoint(sparse(adjoint(A_sparse))),
2323
]
2424
if issymmetric(A)
25-
append!(versions, [Symmetric(A_dense), Symmetric(A_sparse)])
25+
append!(versions, Symmetric.(versions))
2626
end
2727
return versions
2828
end

test/coloring_correctness.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,42 @@ algo = GreedyColoringAlgorithm()
1515

1616
@test startswith(string(algo), "GreedyColoringAlgorithm(")
1717

18+
asymmetric_params = vcat(
19+
[(10, 20, p) for p in (0.1:0.1:0.5)],
20+
[(20, 10, p) for p in (0.1:0.1:0.5)],
21+
[(100, 200, p) for p in (0.01:0.01:0.05)],
22+
[(200, 100, p) for p in (0.01:0.01:0.05)],
23+
)
24+
25+
symmetric_params = vcat(
26+
[(10, p) for p in (0.1:0.05:0.5)], #
27+
[(100, p) for p in (0.01:0.005:0.05)],
28+
)
29+
1830
@testset "Column coloring" begin
19-
@testset "Size ($m, $n) - sparsity $p" for (m, n, p) in [
20-
(10, 20, 0.05), (20, 10, 0.05), (100, 200, 0.05), (200, 100, 0.05)
21-
]
31+
@testset "Size ($m, $n) - sparsity $p" for (m, n, p) in asymmetric_params
2232
@testset "$(typeof(A))" for A in matrix_versions(sprand(rng, Bool, m, n, p))
2333
column_color = column_coloring(A, algo)
2434
@test check_structurally_orthogonal_columns(A, column_color)
25-
@test minimum(column_color) == 1
26-
@test maximum(column_color) < size(A, 2) ÷ 2
2735
end
2836
end
2937
end;
3038

3139
@testset "Row coloring" begin
32-
@testset "Size ($m, $n) - sparsity $p" for (m, n, p) in [
33-
(10, 20, 0.05), (20, 10, 0.05), (100, 200, 0.05), (200, 100, 0.05)
34-
]
35-
@testset "$(typeof(A))" for A in matrix_versions(sprand(rng, Bool, m, n, 0.05))
40+
@testset "Size ($m, $n) - sparsity $p" for (m, n, p) in asymmetric_params
41+
@testset "$(typeof(A))" for A in matrix_versions(sprand(rng, Bool, m, n, p))
3642
row_color = row_coloring(A, algo)
3743
@test check_structurally_orthogonal_columns(transpose(A), row_color)
38-
@test minimum(row_color) == 1
39-
@test maximum(row_color) < size(A, 1) ÷ 2
4044
end
4145
end
4246
end;
4347

4448
@testset "Symmetric coloring" begin
45-
@testset "Size ($n, $n) - sparsity $p" for (n, p) in [(10, 0.05), (100, 0.05)]
49+
@testset "Size ($n, $n) - sparsity $p" for (n, p) in symmetric_params
4650
@testset "$(typeof(A))" for A in
4751
matrix_versions(Symmetric(sprand(rng, Bool, n, n, p)))
4852
symmetric_color = symmetric_coloring(A, algo)
4953
@test check_symmetrically_orthogonal_columns(A, symmetric_color)
50-
@test minimum(symmetric_color) == 1
51-
@test maximum(symmetric_color) < size(A, 2) ÷ 2
5254
end
5355
end
5456
end;

0 commit comments

Comments
 (0)