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
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
ColPack = "ffa27691-3a59-46ab-a8d4-551f45b8d401"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand All @@ -12,3 +13,6 @@ MatrixDepot = "b51810bb-c9f3-55da-ae3c-350fc1fbce05"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
ColPack = "0.4"
60 changes: 60 additions & 0 deletions test/colpack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using ColPack: ColPack, ColPackColoring
using LinearAlgebra
using SparseMatrixColorings
using SparseMatrixColorings: NaturalOrder
using SparseArrays
using StableRNGs
using Test

rng = StableRNG(63)

my_column_coloring(J) = column_coloring(J, GreedyColoringAlgorithm(NaturalOrder()))
my_row_coloring(J) = row_coloring(J, GreedyColoringAlgorithm(NaturalOrder()))
my_symmetric_coloring(H) = symmetric_coloring(H, GreedyColoringAlgorithm(NaturalOrder()))

function colpack_column_coloring(J)
A = ColPack.matrix2adjmatrix(J; partition_by_rows=false)
coloring = ColPackColoring(A, ColPack.d1_coloring(), ColPack.natural_ordering())
return ColPack.get_colors(coloring)
end

function colpack_row_coloring(J)
A = ColPack.matrix2adjmatrix(J; partition_by_rows=true)
coloring = ColPackColoring(A, ColPack.d1_coloring(), ColPack.natural_ordering())
return ColPack.get_colors(coloring)
end

function colpack_symmetric_coloring(H)
coloring = ColPackColoring(H, ColPack.star_coloring(), ColPack.natural_ordering())
return ColPack.get_colors(coloring)
end

n_values = floor.(Int, 10 .^ (1:3))
p_values(n) = (2:4:min(n, 20)) ./ n

@testset verbose = true "Correctness" begin
@testset "Column coloring" begin
@testset "n=$n - p=$p" for n in n_values, p in p_values(n)
J = sprand(rng, n, n + 1, p)
color1 = my_column_coloring(J)
color2 = colpack_column_coloring(J)
@test color1 == color2
end
end
@testset "Row coloring" begin
@testset "n=$n - p=$p" for n in n_values, p in p_values(n)
J = sprand(rng, n, n + 1, p)
color1 = my_row_coloring(J)
color2 = colpack_row_coloring(J)
@test color1 == color2
end
end
@testset "Symmetric coloring" begin
@testset "n=$n - p=$p" for n in n_values, p in p_values(n)
H = sparse(Symmetric(sprand(rng, n, n, p)))
color1 = my_symmetric_coloring(H)
color2 = colpack_symmetric_coloring(H)
@test color1 == color2
end
end
end;
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ include("reference/figures.jl")
end
end
@testset verbose = true "Comparison" begin
@testset "ColPack.jl" begin
include("colpack.jl")
end
@testset "SuiteSparse" begin
include("suitesparse.jl")
end
Expand Down