Skip to content

Commit 167f98a

Browse files
committed
Use JuliaFormatter on the modified files
1 parent b993df6 commit 167f98a

6 files changed

Lines changed: 238 additions & 70 deletions

File tree

src/graph.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,20 @@ function AdjacencyGraph(
236236
S::SparsityPatternCSC{T},
237237
edge_to_index::Vector{T}=build_edge_to_index(S);
238238
augmented_graph::Bool=false,
239-
original_size::Tuple{Int,Int}=size(S),
239+
original_size::Tuple{Int,Int}=size(S),
240240
) where {T}
241241
return AdjacencyGraph{T,augmented_graph}(S, edge_to_index, original_size)
242242
end
243243

244-
function AdjacencyGraph(A::SparseMatrixCSC; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A))
244+
function AdjacencyGraph(
245+
A::SparseMatrixCSC; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A)
246+
)
245247
return AdjacencyGraph(SparsityPatternCSC(A); augmented_graph)
246248
end
247249

248-
function AdjacencyGraph(A::AbstractMatrix; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A))
250+
function AdjacencyGraph(
251+
A::AbstractMatrix; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A)
252+
)
249253
return AdjacencyGraph(SparseMatrixCSC(A); augmented_graph)
250254
end
251255

src/interface.jl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ struct GreedyColoringAlgorithm{decompression,N,O<:NTuple{N,AbstractOrder}} <:
112112
else
113113
orders = order_or_orders
114114
end
115-
return new{decompression,length(orders),typeof(orders)}(orders, postprocessing, postprocessing_minimizes)
115+
return new{decompression,length(orders),typeof(orders)}(
116+
orders, postprocessing, postprocessing_minimizes
117+
)
116118
end
117119
end
118120

@@ -122,7 +124,9 @@ function GreedyColoringAlgorithm(
122124
decompression::Symbol=:direct,
123125
postprocessing_minimizes::Symbol=:all_colors,
124126
)
125-
return GreedyColoringAlgorithm{decompression}(order_or_orders; postprocessing, postprocessing_minimizes)
127+
return GreedyColoringAlgorithm{decompression}(
128+
order_or_orders; postprocessing, postprocessing_minimizes
129+
)
126130
end
127131

128132
## Coloring
@@ -327,12 +331,18 @@ function _coloring(
327331
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
328332
) where {R}
329333
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
330-
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A))
334+
ag = AdjacencyGraph(
335+
A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A)
336+
)
331337
postprocessing_minimizes = algo.postprocessing_minimizes
332338
outputs_by_order = map(algo.orders) do order
333339
vertices_in_order = vertices(ag, order)
334340
_color, _star_set = star_coloring(
335-
ag, vertices_in_order, algo.postprocessing; postprocessing_minimizes, forced_colors
341+
ag,
342+
vertices_in_order,
343+
algo.postprocessing;
344+
postprocessing_minimizes,
345+
forced_colors,
336346
)
337347
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
338348
eltype(ag), _color, maximum(_color), size(A)...
@@ -375,11 +385,15 @@ function _coloring(
375385
symmetric_pattern::Bool,
376386
) where {R}
377387
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
378-
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A))
388+
ag = AdjacencyGraph(
389+
A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A)
390+
)
379391
postprocessing_minimizes = algo.postprocessing_minimizes
380392
outputs_by_order = map(algo.orders) do order
381393
vertices_in_order = vertices(ag, order)
382-
_color, _tree_set = acyclic_coloring(ag, vertices_in_order, algo.postprocessing; postprocessing_minimizes)
394+
_color, _tree_set = acyclic_coloring(
395+
ag, vertices_in_order, algo.postprocessing; postprocessing_minimizes
396+
)
383397
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
384398
eltype(ag), _color, maximum(_color), size(A)...
385399
)

src/postprocessing.jl

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@ function postprocess!(
2828

2929
if star_or_tree_set isa StarSet
3030
# star_or_tree_set is a StarSet
31-
postprocess_with_star_set!(bicoloring, g, row_color_used, column_color_used, color, star_or_tree_set, postprocessing_minimizes)
31+
postprocess_with_star_set!(
32+
bicoloring,
33+
g,
34+
row_color_used,
35+
column_color_used,
36+
color,
37+
star_or_tree_set,
38+
postprocessing_minimizes,
39+
)
3240
else
3341
# star_or_tree_set is a TreeSet
34-
postprocess_with_tree_set!(bicoloring, row_color_used, column_color_used, color, star_or_tree_set, postprocessing_minimizes)
42+
postprocess_with_tree_set!(
43+
bicoloring,
44+
row_color_used,
45+
column_color_used,
46+
color,
47+
star_or_tree_set,
48+
postprocessing_minimizes,
49+
)
3550
end
3651

3752
if bicoloring
@@ -175,7 +190,8 @@ function postprocess_with_star_set!(
175190
#
176191
# Note that this heuristic also depends on the order in which
177192
# the trivial stars are processed, especially when there are ties in `color_counts`.
178-
if row_color_counts[color[i]] > column_color_counts[color[j]]
193+
if row_color_counts[color[i]] >
194+
column_color_counts[color[j]]
179195
row_color_used[color[i]] = true
180196
hub[s] = i
181197
else
@@ -191,7 +207,9 @@ function postprocess_with_star_set!(
191207
hub[s] = i
192208
row_color_used[color[i]] = true
193209
else
194-
error("The value postprocessing_minimizes = :$postprocessing_minimizes is not supported.")
210+
error(
211+
"The value postprocessing_minimizes = :$postprocessing_minimizes is not supported.",
212+
)
195213
end
196214
else
197215
# Previously processed trivial stars determined the hub vertex for this star
@@ -244,8 +262,8 @@ function postprocess_with_tree_set!(
244262
else
245263
# It is not a star and both colors are needed during the decompression
246264
(i, j) = reverse_bfs_orders[first]
247-
v_col = min(i,j)
248-
v_row = max(i,j)
265+
v_col = min(i, j)
266+
v_row = max(i, j)
249267
row_color_used[color[v_row]] = true
250268
column_color_used[color[v_col]] = true
251269
end
@@ -274,8 +292,8 @@ function postprocess_with_tree_set!(
274292
# Check if we have exactly one edge in the tree
275293
if ne_tree == 1
276294
(i, j) = reverse_bfs_orders[first]
277-
v_col = min(i,j)
278-
v_row = max(i,j)
295+
v_col = min(i, j)
296+
v_row = max(i, j)
279297
if column_color_used[color[v_col]]
280298
# The vertex v_col is already an internal node in a non-trivial tree
281299
reverse_bfs_orders[first] = (v_row, v_col)
@@ -307,7 +325,7 @@ function postprocess_with_tree_set!(
307325
# This is optimal because we never increase the number of colors in the target partition during this phase,
308326
# and all preceding steps of the post-processing are deterministic.
309327
if !all_trivial_trees_treated
310-
for k in 1:nt
328+
for k in 1:nt
311329
# Position of the first edge in the tree
312330
first = tree_edge_indices[k]
313331

@@ -317,8 +335,8 @@ function postprocess_with_tree_set!(
317335
# Check if we have exactly one edge in the tree
318336
if ne_tree == 1
319337
(i, j) = reverse_bfs_orders[first]
320-
v_col = min(i,j)
321-
v_row = max(i,j)
338+
v_col = min(i, j)
339+
v_row = max(i, j)
322340
if !column_color_used[color[v_col]] && !row_color_used[color[v_row]]
323341
if !bicoloring || postprocessing_minimizes == :all_colors
324342
# Choose as root the vertex whose color is most frequent among the trivial trees.
@@ -330,7 +348,8 @@ function postprocess_with_tree_set!(
330348
#
331349
# Note that this heuristic also depends on the order in which
332350
# the trivial trees are processed, especially when there are ties in `color_counts`.
333-
if row_color_counts[color[v_row]] > column_color_counts[color[v_col]]
351+
if row_color_counts[color[v_row]] >
352+
column_color_counts[color[v_col]]
334353
row_color_used[color[v_row]] = true
335354
reverse_bfs_orders[first] = (v_col, v_row)
336355
else
@@ -346,7 +365,9 @@ function postprocess_with_tree_set!(
346365
row_color_used[color[v_row]] = true
347366
reverse_bfs_orders[first] = (v_col, v_row)
348367
else
349-
error("The value postprocessing_minimizes = :$postprocessing_minimizes is not supported.")
368+
error(
369+
"The value postprocessing_minimizes = :$postprocessing_minimizes is not supported.",
370+
)
350371
end
351372
else
352373
# Previously processed trivial trees determined the root vertex for this tree

test/random.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,22 @@ end;
8484
RandomOrder(StableRNG(0), 0); postprocessing=false, decompression=:direct
8585
),
8686
GreedyColoringAlgorithm(
87-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:all_colors, decompression=:direct
87+
RandomOrder(StableRNG(0), 0);
88+
postprocessing=true,
89+
postprocessing_minimizes=:all_colors,
90+
decompression=:direct,
8891
),
8992
GreedyColoringAlgorithm(
90-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:row_colors, decompression=:direct
93+
RandomOrder(StableRNG(0), 0);
94+
postprocessing=true,
95+
postprocessing_minimizes=:row_colors,
96+
decompression=:direct,
9197
),
9298
GreedyColoringAlgorithm(
93-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:column_colors, decompression=:direct
99+
RandomOrder(StableRNG(0), 0);
100+
postprocessing=true,
101+
postprocessing_minimizes=:column_colors,
102+
decompression=:direct,
94103
),
95104
)
96105
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params
@@ -111,13 +120,22 @@ end;
111120
RandomOrder(StableRNG(0), 0); postprocessing=false, decompression=:substitution
112121
),
113122
GreedyColoringAlgorithm(
114-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:all_colors, decompression=:substitution
123+
RandomOrder(StableRNG(0), 0);
124+
postprocessing=true,
125+
postprocessing_minimizes=:all_colors,
126+
decompression=:substitution,
115127
),
116128
GreedyColoringAlgorithm(
117-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:row_colors, decompression=:substitution
129+
RandomOrder(StableRNG(0), 0);
130+
postprocessing=true,
131+
postprocessing_minimizes=:row_colors,
132+
decompression=:substitution,
118133
),
119134
GreedyColoringAlgorithm(
120-
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:column_colors, decompression=:substitution
135+
RandomOrder(StableRNG(0), 0);
136+
postprocessing=true,
137+
postprocessing_minimizes=:column_colors,
138+
decompression=:substitution,
121139
),
122140
)
123141
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params

0 commit comments

Comments
 (0)