Skip to content

Commit 1f61746

Browse files
committed
Add triangle to bidirectional visualization
1 parent 8eb5d61 commit 1f61746

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

docs/src/vis.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ problem_bi = ColoringProblem(; structure=:nonsymmetric, partition=:bidirectional
7474
algo_bi = GreedyColoringAlgorithm(RandomOrder(StableRNG(0)); postprocessing=true, decompression=:direct)
7575
result_bi = coloring(S, problem_bi, algo_bi)
7676
77-
Ar_img, Ac_img, Br_img, Bc_img = show_colors(
77+
A_rc_img, Ar_img, Ac_img, Br_img, Bc_img = show_colors(
7878
result_bi;
7979
colorscheme=ColorSchemes.progress,
8080
background_color=RGB(1, 1, 1), # white
@@ -94,6 +94,12 @@ Ar_img
9494
Ac_img
9595
```
9696

97+
Together, this yields:
98+
99+
```@example img
100+
Arc_img
101+
```
102+
97103
And there are two associated compression results, one by row and one by column:
98104

99105
```@example img

ext/SparseMatrixColoringsColorsExt.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function allocate_outputs(
142142
hA, wA = size(A) .* (scale + 2border + pad) .+ (pad)
143143
hBr, wBr = size(Br) .* (scale + 2border + pad) .+ (pad)
144144
hBc, wBc = size(Bc) .* (scale + 2border + pad) .+ (pad)
145+
Arc_img = fill(background_color, hA, wA)
145146
Ar_img = fill(background_color, hA, wA)
146147
Ac_img = fill(background_color, hA, wA)
147148
Br_img = fill(background_color, hBr, wBr)
@@ -150,8 +151,10 @@ function allocate_outputs(
150151
if !iszero(A[I])
151152
area = matrix_entry_area(I, scale, border, pad)
152153
barea = matrix_entry_plus_border_area(I, scale, border, pad)
154+
Arc_img[barea] .= border_color
153155
Ar_img[barea] .= border_color
154156
Ac_img[barea] .= border_color
157+
Arc_img[area] .= background_color
155158
Ar_img[area] .= background_color
156159
Ac_img[area] .= background_color
157160
end
@@ -172,7 +175,7 @@ function allocate_outputs(
172175
Bc_img[area] .= background_color
173176
end
174177
end
175-
return Ar_img, Ac_img, Br_img, Bc_img
178+
return Arc_img, Ar_img, Ac_img, Br_img, Bc_img
176179
end
177180

178181
## Implementations for different AbstractColoringResult types start here
@@ -247,7 +250,11 @@ function show_colors!(
247250
return A_img, B_img
248251
end
249252

253+
mytriu(area) = [area[i, j] for i in axes(area, 1) for j in axes(area, 2) if i < j]
254+
mytril(area) = [area[i, j] for i in axes(area, 1) for j in axes(area, 2) if i > j]
255+
250256
function show_colors!(
257+
Arc_img::AbstractMatrix{<:Colorant},
251258
Ar_img::AbstractMatrix{<:Colorant},
252259
Ac_img::AbstractMatrix{<:Colorant},
253260
Br_img::AbstractMatrix{<:Colorant},
@@ -264,9 +271,8 @@ function show_colors!(
264271
A_ccolor_indices = mod1.(column_colors(res), length(colorscheme))
265272
A_rcolor_indices = mod1.(row_shift .+ row_colors(res), length(colorscheme))
266273
B_ccolor_indices = mod1.(1:maximum(column_colors(res)), length(colorscheme))
267-
B_rcolor_indices = mod1.(
268-
(row_shift + 1):(row_shift + maximum(row_colors(res))), length(colorscheme)
269-
)
274+
B_rcolor_indices =
275+
mod1.((row_shift + 1):(row_shift + maximum(row_colors(res))), length(colorscheme))
270276
A_ccolors = colorscheme[A_ccolor_indices]
271277
A_rcolors = colorscheme[A_rcolor_indices]
272278
B_ccolors = colorscheme[B_ccolor_indices]
@@ -278,9 +284,11 @@ function show_colors!(
278284
r, c = Tuple(I)
279285
area = matrix_entry_area(I, scale, border, pad)
280286
if column_colors(res)[c] > 0
287+
Arc_img[mytriu(area)] .= A_ccolors[c]
281288
Ac_img[area] .= A_ccolors[c]
282289
end
283290
if row_colors(res)[r] > 0
291+
Arc_img[mytril(area)] .= A_rcolors[r]
284292
Ar_img[area] .= A_rcolors[r]
285293
end
286294
end
@@ -299,7 +307,7 @@ function show_colors!(
299307
Bc_img[area] .= B_ccolors[c]
300308
end
301309
end
302-
return Ar_img, Ac_img, Br_img, Bc_img
310+
return Arc_img, Ar_img, Ac_img, Br_img, Bc_img
303311
end
304312

305313
end # module

0 commit comments

Comments
 (0)