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

Support ADTypes.NoColoringAlgorithm #142

Merged
merged 2 commits into from
Oct 4, 2024
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseMatrixColorings"
uuid = "0a514795-09f3-496d-8182-132a7b665d35"
authors = ["Guillaume Dalle", "Alexis Montoison"]
version = "0.4.5"
version = "0.4.6"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
1 change: 1 addition & 0 deletions src/SparseMatrixColorings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ include("result.jl")
include("matrices.jl")
include("interface.jl")
include("constant.jl")
include("adtypes.jl")
include("decompression.jl")
include("check.jl")
include("examples.jl")
Expand Down
21 changes: 21 additions & 0 deletions src/adtypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function coloring(
A::AbstractMatrix,
::ColoringProblem{:nonsymmetric,:column},
algo::ADTypes.NoColoringAlgorithm;
kwargs...,
)
bg = BipartiteGraph(A)
color = convert(Vector{Int}, ADTypes.column_coloring(A, algo))
return ColumnColoringResult(A, bg, color)
end

function coloring(
A::AbstractMatrix,
::ColoringProblem{:nonsymmetric,:row},
algo::ADTypes.NoColoringAlgorithm;
kwargs...,
)
bg = BipartiteGraph(A)
color = convert(Vector{Int}, ADTypes.row_coloring(A, algo))
return RowColoringResult(A, bg, color)
end
26 changes: 26 additions & 0 deletions test/adtypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ADTypes: ADTypes
using SparseArrays
using SparseMatrixColorings
using Test

@testset "Column coloring" begin
problem = ColoringProblem(; structure=:nonsymmetric, partition=:column)
algo = ADTypes.NoColoringAlgorithm()
A = sprand(10, 20, 0.1)
result = coloring(A, problem, algo)
B = compress(A, result)
@test size(B) == size(A)
@test column_colors(result) == ADTypes.column_coloring(A, algo)
@test decompress(B, result) == A
end

@testset "Row coloring" begin
problem = ColoringProblem(; structure=:nonsymmetric, partition=:row)
algo = ADTypes.NoColoringAlgorithm()
A = sprand(10, 20, 0.1)
result = coloring(A, problem, algo)
B = compress(A, result)
@test size(B) == size(A)
@test row_colors(result) == ADTypes.row_coloring(A, algo)
@test decompress(B, result) == A
end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ include("utils.jl")
@testset "Constant coloring" begin
include("constant.jl")
end
@testset "ADTypes coloring algorithms" begin
include("adtypes.jl")
end
end
@testset verbose = true "Correctness" begin
@testset "Small instances" begin
Expand Down