Skip to content
Open
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
10 changes: 2 additions & 8 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function _coloring(
vertices_in_order = vertices(ag, order)
return star_coloring(ag, vertices_in_order, algo.postprocessing; forced_colors)
end
color, star_set = argmin(maximum ∘ first, color_and_star_set_by_order)
color, star_set = argmin(t -> maximum(first(t); init=0), color_and_star_set_by_order)
if speed_setting isa WithResult
return StarSetColoringResult(A, ag, color, star_set)
else
Expand All @@ -334,13 +334,7 @@ function _coloring(
vertices_in_order = vertices(ag, order)
return acyclic_coloring(ag, vertices_in_order, algo.postprocessing)
end
# if `color` is empty, `maximum` will fail but `color_and_tree_set_by_order`
# is also one so we can just add a special case for this
if length(color_and_tree_set_by_order) == 1
color, tree_set = only(color_and_tree_set_by_order)
else
color, tree_set = argmin(maximum ∘ first, color_and_tree_set_by_order)
end
color, tree_set = argmin(t -> maximum(first(t); init=0), color_and_tree_set_by_order)
if speed_setting isa WithResult
return TreeSetColoringResult(A, ag, color, tree_set, R)
else
Expand Down
2 changes: 1 addition & 1 deletion src/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function postprocess!(
postprocessing_minimizes::Symbol,
)
# flag which colors are actually used during decompression
nb_colors = maximum(color)
nb_colors = maximum(color; init=0)
color_used = zeros(Bool, nb_colors)

# nonzero diagonal coefficients force the use of their respective color (there can be no neutral colors if the diagonal is fully nonzero)
Expand Down
34 changes: 34 additions & 0 deletions test/empty.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using LinearAlgebra
using SparseArrays
using SparseMatrixColorings
using Test

@testset "Empty symmetric coloring" begin
problem = ColoringProblem(; structure=:symmetric, partition=:column)
orders = (NaturalOrder(), LargestFirst(), (NaturalOrder(), LargestFirst()))
matrices = (
zeros(0, 0),
spzeros(0, 0),
Symmetric(spzeros(0, 0)),
SparseMatrixColorings.SparsityPatternCSC(spzeros(0, 0)),
)
@testset "$decompression, $postprocessing, $order, $(typeof(A))" for decompression in (
:direct, :substitution
),
postprocessing in (false, true), order in orders,
A in matrices

algo = GreedyColoringAlgorithm(order; decompression, postprocessing)
result = coloring(A, problem, algo)
@test ncolors(result) == 0
@test isempty(column_colors(result))
@test isempty(column_groups(result))
@test fast_coloring(A, problem, algo) == Int[]
B = compress(A, result)
@test size(B) == (0, 0)
@test decompress(B, result) == A
target = spzeros(0, 0)
@test decompress!(target, B, result) === target
@test size(target) == (0, 0)
end
end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ using Colors: Colors
end
end
@testset verbose = true "Correctness" begin
@testset "Empty matrices" begin
include("empty.jl")
end
@testset "Small instances" begin
include("small.jl")
end
Expand Down
Loading