Skip to content

Commit 6834cd9

Browse files
committed
Fix coloring with empty matrix as input
1 parent 3b9fe4b commit 6834cd9

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/interface.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@ function _coloring(
305305
vertices_in_order = vertices(ag, order)
306306
return acyclic_coloring(ag, vertices_in_order, algo.postprocessing)
307307
end
308-
color, tree_set = argmin(maximum first, color_and_tree_set_by_order)
308+
# if `color` is empty, `maximum` will fail but `color_and_tree_set_by_order`
309+
# is also one so we can just add a special case for this
310+
if length(color_and_tree_set_by_order) == 1
311+
color, tree_set = only(color_and_tree_set_by_order)
312+
else
313+
color, tree_set = argmin(maximum first, color_and_tree_set_by_order)
314+
end
309315
if speed_setting isa WithResult
310316
return TreeSetColoringResult(A, ag, color, tree_set, R)
311317
else

src/result.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Create a color-indexed vector `group` such that `i ∈ group[c]` iff `color[i] =
8282
Assumes the colors are contiguously numbered from `0` to some `cmax`.
8383
"""
8484
function group_by_color(::Type{T}, color::AbstractVector) where {T<:Integer}
85+
if isempty(color)
86+
return SubArray{Int,1,Vector{Int},Tuple{UnitRange{Int}},true}[]
87+
end
8588
cmin, cmax = extrema(color)
8689
@assert cmin >= 0
8790
# Compute group sizes and offsets for a joint storage

0 commit comments

Comments
 (0)