Skip to content

Commit 744827d

Browse files
authored
Add triangle to bidirectional visualization (#243)
* Add triangle to bidirectional visualization * Fix * format
1 parent 8eb5d61 commit 744827d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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+
Arc_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: 11 additions & 2 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},
@@ -278,9 +285,11 @@ function show_colors!(
278285
r, c = Tuple(I)
279286
area = matrix_entry_area(I, scale, border, pad)
280287
if column_colors(res)[c] > 0
288+
Arc_img[mytriu(area)] .= A_ccolors[c]
281289
Ac_img[area] .= A_ccolors[c]
282290
end
283291
if row_colors(res)[r] > 0
292+
Arc_img[mytril(area)] .= A_rcolors[r]
284293
Ar_img[area] .= A_rcolors[r]
285294
end
286295
end
@@ -299,7 +308,7 @@ function show_colors!(
299308
Bc_img[area] .= B_ccolors[c]
300309
end
301310
end
302-
return Ar_img, Ac_img, Br_img, Bc_img
311+
return Arc_img, Ar_img, Ac_img, Br_img, Bc_img
303312
end
304313

305314
end # module

test/show_colors.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ algo = GreedyColoringAlgorithm(; decompression=:direct)
5252
Br, Bc = compress(A, result)
5353

5454
scale = 3
55-
Ar_img, Ac_img, Br_img, Bc_img = show_colors(result; scale=scale)
55+
Arc_img, Ar_img, Ac_img, Br_img, Bc_img = show_colors(result; scale=scale)
56+
@test size(Arc_img) == size(A) .* scale
5657
@test size(Ar_img) == size(A) .* scale
5758
@test size(Ac_img) == size(A) .* scale
5859
@test size(Br_img) == size(Br) .* scale
5960
@test size(Bc_img) == size(Bc) .* scale
61+
@test Arc_img isa Matrix{<:Colorant}
6062
@test Ar_img isa Matrix{<:Colorant}
6163
@test Ac_img isa Matrix{<:Colorant}
6264
@test Br_img isa Matrix{<:Colorant}

0 commit comments

Comments
 (0)