Skip to content
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
8 changes: 7 additions & 1 deletion docs/src/vis.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ problem_bi = ColoringProblem(; structure=:nonsymmetric, partition=:bidirectional
algo_bi = GreedyColoringAlgorithm(RandomOrder(StableRNG(0)); postprocessing=true, decompression=:direct)
result_bi = coloring(S, problem_bi, algo_bi)

Ar_img, Ac_img, Br_img, Bc_img = show_colors(
Arc_img, Ar_img, Ac_img, Br_img, Bc_img = show_colors(
result_bi;
colorscheme=ColorSchemes.progress,
background_color=RGB(1, 1, 1), # white
Expand All @@ -94,6 +94,12 @@ Ar_img
Ac_img
```

Together, this yields:

```@example img
Arc_img
```

And there are two associated compression results, one by row and one by column:

```@example img
Expand Down
13 changes: 11 additions & 2 deletions ext/SparseMatrixColoringsColorsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function allocate_outputs(
hA, wA = size(A) .* (scale + 2border + pad) .+ (pad)
hBr, wBr = size(Br) .* (scale + 2border + pad) .+ (pad)
hBc, wBc = size(Bc) .* (scale + 2border + pad) .+ (pad)
Arc_img = fill(background_color, hA, wA)
Ar_img = fill(background_color, hA, wA)
Ac_img = fill(background_color, hA, wA)
Br_img = fill(background_color, hBr, wBr)
Expand All @@ -150,8 +151,10 @@ function allocate_outputs(
if !iszero(A[I])
area = matrix_entry_area(I, scale, border, pad)
barea = matrix_entry_plus_border_area(I, scale, border, pad)
Arc_img[barea] .= border_color
Ar_img[barea] .= border_color
Ac_img[barea] .= border_color
Arc_img[area] .= background_color
Ar_img[area] .= background_color
Ac_img[area] .= background_color
end
Expand All @@ -172,7 +175,7 @@ function allocate_outputs(
Bc_img[area] .= background_color
end
end
return Ar_img, Ac_img, Br_img, Bc_img
return Arc_img, Ar_img, Ac_img, Br_img, Bc_img
end

## Implementations for different AbstractColoringResult types start here
Expand Down Expand Up @@ -247,7 +250,11 @@ function show_colors!(
return A_img, B_img
end

mytriu(area) = [area[i, j] for i in axes(area, 1) for j in axes(area, 2) if i < j]
mytril(area) = [area[i, j] for i in axes(area, 1) for j in axes(area, 2) if i > j]

function show_colors!(
Arc_img::AbstractMatrix{<:Colorant},
Ar_img::AbstractMatrix{<:Colorant},
Ac_img::AbstractMatrix{<:Colorant},
Br_img::AbstractMatrix{<:Colorant},
Expand Down Expand Up @@ -278,9 +285,11 @@ function show_colors!(
r, c = Tuple(I)
area = matrix_entry_area(I, scale, border, pad)
if column_colors(res)[c] > 0
Arc_img[mytriu(area)] .= A_ccolors[c]
Ac_img[area] .= A_ccolors[c]
end
if row_colors(res)[r] > 0
Arc_img[mytril(area)] .= A_rcolors[r]
Ar_img[area] .= A_rcolors[r]
end
end
Expand All @@ -299,7 +308,7 @@ function show_colors!(
Bc_img[area] .= B_ccolors[c]
end
end
return Ar_img, Ac_img, Br_img, Bc_img
return Arc_img, Ar_img, Ac_img, Br_img, Bc_img
end

end # module
4 changes: 3 additions & 1 deletion test/show_colors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ algo = GreedyColoringAlgorithm(; decompression=:direct)
Br, Bc = compress(A, result)

scale = 3
Ar_img, Ac_img, Br_img, Bc_img = show_colors(result; scale=scale)
Arc_img, Ar_img, Ac_img, Br_img, Bc_img = show_colors(result; scale=scale)
@test size(Arc_img) == size(A) .* scale
@test size(Ar_img) == size(A) .* scale
@test size(Ac_img) == size(A) .* scale
@test size(Br_img) == size(Br) .* scale
@test size(Bc_img) == size(Bc) .* scale
@test Arc_img isa Matrix{<:Colorant}
@test Ar_img isa Matrix{<:Colorant}
@test Ac_img isa Matrix{<:Colorant}
@test Br_img isa Matrix{<:Colorant}
Expand Down