Skip to content

Commit 8430561

Browse files
authored
Support ADTypes.NoColoringAlgorithm (#142)
* Support `ADTypes.NoColoringAlgorithm` * Bump version
1 parent 0ceb174 commit 8430561

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseMatrixColorings"
22
uuid = "0a514795-09f3-496d-8182-132a7b665d35"
33
authors = ["Guillaume Dalle", "Alexis Montoison"]
4-
version = "0.4.5"
4+
version = "0.4.6"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/SparseMatrixColorings.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ include("result.jl")
5050
include("matrices.jl")
5151
include("interface.jl")
5252
include("constant.jl")
53+
include("adtypes.jl")
5354
include("decompression.jl")
5455
include("check.jl")
5556
include("examples.jl")

src/adtypes.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function coloring(
2+
A::AbstractMatrix,
3+
::ColoringProblem{:nonsymmetric,:column},
4+
algo::ADTypes.NoColoringAlgorithm;
5+
kwargs...,
6+
)
7+
bg = BipartiteGraph(A)
8+
color = convert(Vector{Int}, ADTypes.column_coloring(A, algo))
9+
return ColumnColoringResult(A, bg, color)
10+
end
11+
12+
function coloring(
13+
A::AbstractMatrix,
14+
::ColoringProblem{:nonsymmetric,:row},
15+
algo::ADTypes.NoColoringAlgorithm;
16+
kwargs...,
17+
)
18+
bg = BipartiteGraph(A)
19+
color = convert(Vector{Int}, ADTypes.row_coloring(A, algo))
20+
return RowColoringResult(A, bg, color)
21+
end

test/adtypes.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using ADTypes: ADTypes
2+
using SparseArrays
3+
using SparseMatrixColorings
4+
using Test
5+
6+
@testset "Column coloring" begin
7+
problem = ColoringProblem(; structure=:nonsymmetric, partition=:column)
8+
algo = ADTypes.NoColoringAlgorithm()
9+
A = sprand(10, 20, 0.1)
10+
result = coloring(A, problem, algo)
11+
B = compress(A, result)
12+
@test size(B) == size(A)
13+
@test column_colors(result) == ADTypes.column_coloring(A, algo)
14+
@test decompress(B, result) == A
15+
end
16+
17+
@testset "Row coloring" begin
18+
problem = ColoringProblem(; structure=:nonsymmetric, partition=:row)
19+
algo = ADTypes.NoColoringAlgorithm()
20+
A = sprand(10, 20, 0.1)
21+
result = coloring(A, problem, algo)
22+
B = compress(A, result)
23+
@test size(B) == size(A)
24+
@test row_colors(result) == ADTypes.row_coloring(A, algo)
25+
@test decompress(B, result) == A
26+
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ include("utils.jl")
4545
@testset "Constant coloring" begin
4646
include("constant.jl")
4747
end
48+
@testset "ADTypes coloring algorithms" begin
49+
include("adtypes.jl")
50+
end
4851
end
4952
@testset verbose = true "Correctness" begin
5053
@testset "Small instances" begin

0 commit comments

Comments
 (0)