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
8 changes: 7 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ function _coloring(
vertices_in_order = vertices(ag, order)
return acyclic_coloring(ag, vertices_in_order, algo.postprocessing)
end
color, tree_set = argmin(maximum ∘ first, color_and_tree_set_by_order)
# 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
if speed_setting isa WithResult
return TreeSetColoringResult(A, ag, color, tree_set, R)
else
Expand Down
3 changes: 3 additions & 0 deletions src/result.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Create a color-indexed vector `group` such that `i ∈ group[c]` iff `color[i] =
Assumes the colors are contiguously numbered from `0` to some `cmax`.
"""
function group_by_color(::Type{T}, color::AbstractVector) where {T<:Integer}
if isempty(color)
return typeof(view(T[], 1:0))[]
end
cmin, cmax = extrema(color)
@assert cmin >= 0
# Compute group sizes and offsets for a joint storage
Expand Down
11 changes: 11 additions & 0 deletions test/check.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LinearAlgebra
using SparseArrays
using SparseMatrixColorings:
structurally_orthogonal_columns,
symmetrically_orthogonal_columns,
Expand Down Expand Up @@ -308,3 +309,13 @@ end
log = (:warn, "4 colors provided for 3 rows.")
@test_logs log !substitutable_bidirectional(A, B, [1, 0, 0, 1], [0, 1, 1]; verbose=true)
end

# See https://github.com/gdalle/SparseMatrixColorings.jl/pull/300
@testset "Empty matrix" begin
problem = ColoringProblem(; structure=:symmetric, partition=:column)
algo = GreedyColoringAlgorithm(; decompression=:substitution)
S = spzeros(Int, 0, 0)
result = coloring(S, problem, algo)
@test isempty(result.color)
@test isempty(result.group)
end
Loading