Skip to content

Commit 1da176d

Browse files
authored
Format code (#321)
1 parent 3f1e013 commit 1da176d

40 files changed

Lines changed: 809 additions & 557 deletions

benchmark/benchmarks.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ for structure in [:nonsymmetric, :symmetric],
2121

2222
problem = ColoringProblem(; structure, partition)
2323
algo = GreedyColoringAlgorithm(
24-
RandomOrder(StableRNG(0), 0); decompression, postprocessing=true
24+
RandomOrder(StableRNG(0), 0);
25+
decompression,
26+
postprocessing = true,
2527
)
2628

2729
# use several random matrices to reduce variance
2830
nb_samples = 5
29-
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i in 1:nb_samples]
30-
results = [coloring(A, problem, algo; decompression_eltype=Float64) for A in As]
31+
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i = 1:nb_samples]
32+
results = [coloring(A, problem, algo; decompression_eltype = Float64) for A in As]
3133
Bs = [compress(Float64.(A), result) for (A, result) in zip(As, results)]
3234

3335
bench_col = @benchmarkable begin
@@ -57,7 +59,7 @@ for structure in [:nonsymmetric, :symmetric],
5759
p in [2 / n, 5 / n, 10 / n]
5860

5961
nb_samples = 5
60-
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i in 1:nb_samples]
62+
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i = 1:nb_samples]
6163
if structure == :symmetric
6264
gs = [SMC.AdjacencyGraph(A) for A in As]
6365
bench_ord = @benchmarkable begin

docs/make.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@ using SparseMatrixColorings
44

55
links = InterLinks("ADTypes" => "https://sciml.github.io/ADTypes.jl/stable/")
66

7-
cp(joinpath(@__DIR__, "..", "README.md"), joinpath(@__DIR__, "src", "index.md"); force=true)
7+
cp(
8+
joinpath(@__DIR__, "..", "README.md"),
9+
joinpath(@__DIR__, "src", "index.md");
10+
force = true,
11+
)
812

913
makedocs(;
10-
modules=[SparseMatrixColorings],
11-
authors="Guillaume Dalle and Alexis Montoison",
12-
sitename="SparseMatrixColorings.jl",
13-
format=Documenter.HTML(),
14-
pages=[
14+
modules = [SparseMatrixColorings],
15+
authors = "Guillaume Dalle and Alexis Montoison",
16+
sitename = "SparseMatrixColorings.jl",
17+
format = Documenter.HTML(),
18+
pages = [
1519
"Home" => "index.md",
1620
"tutorial.md",
1721
"api.md",
1822
"Developer Documentation" => ["dev.md", "vis.md"],
1923
],
20-
plugins=[links],
24+
plugins = [links],
2125
)
2226

2327
deploydocs(;
24-
repo="github.com/JuliaDiff/SparseMatrixColorings.jl",
25-
push_preview=true,
26-
devbranch="main",
28+
repo = "github.com/JuliaDiff/SparseMatrixColorings.jl",
29+
push_preview = true,
30+
devbranch = "main",
2731
)

ext/SparseMatrixColoringsCUDAExt.jl

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,31 @@ using cuSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR
88
## CSC Result
99

1010
function SMC.ColumnColoringResult(
11-
A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
11+
A::CuSparseMatrixCSC,
12+
bg::SMC.BipartiteGraph{T},
13+
color::Vector{<:Integer},
1214
) where {T<:Integer}
1315
group = SMC.group_by_color(T, color)
1416
compressed_indices = SMC.column_csc_indices(bg, color)
15-
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
17+
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
1618
return SMC.ColumnColoringResult(
17-
A, bg, color, group, compressed_indices, additional_info
19+
A,
20+
bg,
21+
color,
22+
group,
23+
compressed_indices,
24+
additional_info,
1825
)
1926
end
2027

2128
function SMC.RowColoringResult(
22-
A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
29+
A::CuSparseMatrixCSC,
30+
bg::SMC.BipartiteGraph{T},
31+
color::Vector{<:Integer},
2332
) where {T<:Integer}
2433
group = SMC.group_by_color(T, color)
2534
compressed_indices = SMC.row_csc_indices(bg, color)
26-
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
35+
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
2736
return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info)
2837
end
2938

@@ -35,33 +44,47 @@ function SMC.StarSetColoringResult(
3544
) where {T<:Integer}
3645
group = SMC.group_by_color(T, color)
3746
compressed_indices = SMC.star_csc_indices(ag, color, star_set)
38-
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
47+
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
3948
return SMC.StarSetColoringResult(
40-
A, ag, color, group, compressed_indices, additional_info
49+
A,
50+
ag,
51+
color,
52+
group,
53+
compressed_indices,
54+
additional_info,
4155
)
4256
end
4357

4458
## CSR Result
4559

4660
function SMC.ColumnColoringResult(
47-
A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
61+
A::CuSparseMatrixCSR,
62+
bg::SMC.BipartiteGraph{T},
63+
color::Vector{<:Integer},
4864
) where {T<:Integer}
4965
group = SMC.group_by_color(T, color)
5066
compressed_indices = SMC.column_csc_indices(bg, color)
5167
compressed_indices_csr = SMC.column_csr_indices(bg, color)
52-
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr))
68+
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices_csr))
5369
return SMC.ColumnColoringResult(
54-
A, bg, color, group, compressed_indices, additional_info
70+
A,
71+
bg,
72+
color,
73+
group,
74+
compressed_indices,
75+
additional_info,
5576
)
5677
end
5778

5879
function SMC.RowColoringResult(
59-
A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
80+
A::CuSparseMatrixCSR,
81+
bg::SMC.BipartiteGraph{T},
82+
color::Vector{<:Integer},
6083
) where {T<:Integer}
6184
group = SMC.group_by_color(T, color)
6285
compressed_indices = SMC.row_csc_indices(bg, color)
6386
compressed_indices_csr = SMC.row_csr_indices(bg, color)
64-
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr))
87+
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices_csr))
6588
return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info)
6689
end
6790

@@ -73,9 +96,14 @@ function SMC.StarSetColoringResult(
7396
) where {T<:Integer}
7497
group = SMC.group_by_color(T, color)
7598
compressed_indices = SMC.star_csc_indices(ag, color, star_set)
76-
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices))
99+
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices))
77100
return SMC.StarSetColoringResult(
78-
A, ag, color, group, compressed_indices, additional_info
101+
A,
102+
ag,
103+
color,
104+
group,
105+
compressed_indices,
106+
additional_info,
79107
)
80108
end
81109

@@ -84,15 +112,19 @@ end
84112
for R in (:ColumnColoringResult, :RowColoringResult)
85113
# loop to avoid method ambiguity
86114
@eval function SMC.decompress!(
87-
A::CuSparseMatrixCSC, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSC}
115+
A::CuSparseMatrixCSC,
116+
B::CuMatrix,
117+
result::SMC.$R{<:CuSparseMatrixCSC},
88118
)
89119
compressed_indices = result.additional_info.compressed_indices_gpu_csc
90120
copyto!(A.nzVal, view(B, compressed_indices))
91121
return A
92122
end
93123

94124
@eval function SMC.decompress!(
95-
A::CuSparseMatrixCSR, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSR}
125+
A::CuSparseMatrixCSR,
126+
B::CuMatrix,
127+
result::SMC.$R{<:CuSparseMatrixCSR},
96128
)
97129
compressed_indices = result.additional_info.compressed_indices_gpu_csr
98130
copyto!(A.nzVal, view(B, compressed_indices))
@@ -104,12 +136,12 @@ function SMC.decompress!(
104136
A::CuSparseMatrixCSC,
105137
B::CuMatrix,
106138
result::SMC.StarSetColoringResult{<:CuSparseMatrixCSC},
107-
uplo::Symbol=:F,
139+
uplo::Symbol = :F,
108140
)
109141
if uplo != :F
110142
throw(
111143
SMC.UnsupportedDecompressionError(
112-
"Single-triangle decompression is not supported on GPU matrices"
144+
"Single-triangle decompression is not supported on GPU matrices",
113145
),
114146
)
115147
end
@@ -122,12 +154,12 @@ function SMC.decompress!(
122154
A::CuSparseMatrixCSR,
123155
B::CuMatrix,
124156
result::SMC.StarSetColoringResult{<:CuSparseMatrixCSR},
125-
uplo::Symbol=:F,
157+
uplo::Symbol = :F,
126158
)
127159
if uplo != :F
128160
throw(
129161
SMC.UnsupportedDecompressionError(
130-
"Single-triangle decompression is not supported on GPU matrices"
162+
"Single-triangle decompression is not supported on GPU matrices",
131163
),
132164
)
133165
end

ext/SparseMatrixColoringsCliqueTreesExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function vertices(g::AdjacencyGraph{T}, order::PerfectEliminationOrder) where {T
1515

1616
# construct a perfect elimination order
1717
# self-loops are ignored
18-
order, _ = permutation(M; alg=order.elimination_algorithm)
18+
order, _ = permutation(M; alg = order.elimination_algorithm)
1919

2020
return reverse!(order)
2121
end

ext/SparseMatrixColoringsColorsExt.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ const DEFAULT_PAD = 0
3737

3838
function SparseMatrixColorings.show_colors(
3939
res::AbstractColoringResult;
40-
colorscheme=nothing,
41-
background_color::Colorant=DEFAULT_BACKGROUND_COLOR, # color used for zero matrix entries and pad
42-
border_color::Colorant=DEFAULT_BORDER_COLOR, # color used for zero matrix entries and pad
43-
scale::Int=DEFAULT_SCALE, # scale size of matrix entries to `scale × scale` pixels
44-
border::Int=DEFAULT_BORDER, # border around matrix entries
45-
pad::Int=DEFAULT_PAD, # pad between matrix entries
46-
warn::Bool=true,
40+
colorscheme = nothing,
41+
background_color::Colorant = DEFAULT_BACKGROUND_COLOR, # color used for zero matrix entries and pad
42+
border_color::Colorant = DEFAULT_BORDER_COLOR, # color used for zero matrix entries and pad
43+
scale::Int = DEFAULT_SCALE, # scale size of matrix entries to `scale × scale` pixels
44+
border::Int = DEFAULT_BORDER, # border around matrix entries
45+
pad::Int = DEFAULT_PAD, # pad between matrix entries
46+
warn::Bool = true,
4747
)
4848
scale < 1 && throw(ArgumentError("`scale` has to be ≥ 1."))
4949
border < 0 && throw(ArgumentError("`border` has to be ≥ 0."))
@@ -53,15 +53,14 @@ function SparseMatrixColorings.show_colors(
5353
if warn && ncolors(res) > length(colorscheme)
5454
@warn "`show_colors` will reuse colors since the provided `colorscheme` has $(length(colorscheme)) colors and the matrix needs $(ncolors(res)). You can turn off this warning via the keyword argument `warn = false`, or choose a larger `colorscheme` from ColorSchemes.jl."
5555
end
56-
colorscheme, background_color, border_color = promote_colors(
57-
colorscheme, background_color, border_color
58-
)
56+
colorscheme, background_color, border_color =
57+
promote_colors(colorscheme, background_color, border_color)
5958
else
6059
# Sample n distinguishable colors, excluding the background and border color
6160
colorscheme = distinguishable_colors(
6261
ncolors(res),
6362
[convert(RGB, background_color), convert(RGB, border_color)];
64-
dropseed=true,
63+
dropseed = true,
6564
)
6665
end
6766
outs = allocate_outputs(res, background_color, border_color, scale, border, pad)
@@ -86,7 +85,7 @@ function matrix_entry_area(I::CartesianIndex, scale, border, pad)
8685
end
8786

8887
function matrix_entry_plus_border_area(I::CartesianIndex, scale, border, pad)
89-
stencil = CartesianIndices((1:(scale + 2border), 1:(scale + 2border)))
88+
stencil = CartesianIndices((1:(scale+2border), 1:(scale+2border)))
9089
return CartesianIndex(1, 1) * pad +
9190
(I - CartesianIndex(1, 1)) * (scale + 2border + pad) .+ stencil
9291
end
@@ -272,7 +271,7 @@ function show_colors!(
272271
A_rcolor_indices = mod1.(row_shift .+ row_colors(res), length(colorscheme))
273272
B_ccolor_indices = mod1.(1:maximum(column_colors(res)), length(colorscheme))
274273
B_rcolor_indices =
275-
mod1.((row_shift + 1):(row_shift + maximum(row_colors(res))), length(colorscheme))
274+
mod1.((row_shift+1):(row_shift+maximum(row_colors(res))), length(colorscheme))
276275
A_ccolors = colorscheme[A_ccolor_indices]
277276
A_rcolors = colorscheme[A_rcolor_indices]
278277
B_ccolors = colorscheme[B_ccolor_indices]

ext/SparseMatrixColoringsGPUArraysExt.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ SMC.matrix_versions(A::AbstractGPUSparseMatrix) = (A,)
99
## Compression (slow, through CPU)
1010

1111
function SMC.compress(
12-
A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:column}
12+
A::AbstractGPUSparseMatrix,
13+
result::SMC.AbstractColoringResult{structure,:column},
1314
) where {structure}
1415
A_cpu = SparseMatrixCSC(A)
1516
B_cpu = SMC.compress(A_cpu, result)
@@ -18,7 +19,8 @@ function SMC.compress(
1819
end
1920

2021
function SMC.compress(
21-
A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:row}
22+
A::AbstractGPUSparseMatrix,
23+
result::SMC.AbstractColoringResult{structure,:row},
2224
) where {structure}
2325
A_cpu = SparseMatrixCSC(A)
2426
B_cpu = SMC.compress(A_cpu, result)

ext/SparseMatrixColoringsJuMPExt.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function optimal_distance2_coloring(
2121
bg::BipartiteGraph,
2222
::Val{side},
2323
optimizer::O;
24-
silent::Bool=true,
25-
assert_solved::Bool=true,
24+
silent::Bool = true,
25+
assert_solved::Bool = true,
2626
) where {side,O}
2727
other_side = 3 - side
2828
n = nb_vertices(bg, Val(side))
@@ -66,14 +66,22 @@ end
6666
function ADTypes.column_coloring(A::AbstractMatrix, algo::OptimalColoringAlgorithm)
6767
bg = BipartiteGraph(A)
6868
return optimal_distance2_coloring(
69-
bg, Val(2), algo.optimizer; algo.silent, algo.assert_solved
69+
bg,
70+
Val(2),
71+
algo.optimizer;
72+
algo.silent,
73+
algo.assert_solved,
7074
)
7175
end
7276

7377
function ADTypes.row_coloring(A::AbstractMatrix, algo::OptimalColoringAlgorithm)
7478
bg = BipartiteGraph(A)
7579
return optimal_distance2_coloring(
76-
bg, Val(1), algo.optimizer; algo.silent, algo.assert_solved
80+
bg,
81+
Val(1),
82+
algo.optimizer;
83+
algo.silent,
84+
algo.assert_solved,
7785
)
7886
end
7987

src/adtypes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function coloring(
44
A::AbstractMatrix,
55
problem::ColoringProblem{structure,partition},
66
algo::ADTypes.AbstractColoringAlgorithm;
7-
decompression_eltype::Type{R}=Float64,
8-
symmetric_pattern::Bool=false,
7+
decompression_eltype::Type{R} = Float64,
8+
symmetric_pattern::Bool = false,
99
) where {structure,partition,R}
1010
symmetric_pattern = symmetric_pattern || A isa Union{Symmetric,Hermitian}
1111
if structure == :nonsymmetric

0 commit comments

Comments
 (0)