Skip to content

Commit bfe0923

Browse files
authored
Format code again (#326)
* Update pre-commit hook * Apply formatting again
1 parent c6ffdcf commit bfe0923

42 files changed

Lines changed: 567 additions & 818 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
22
- repo: https://github.com/JuliaEditorSupport/JuliaFormatter.jl
3-
rev: 0935890389c9fbc45f4ee150064c0abe5340b6a9 # v2.4.0
3+
rev: 2864ae303b091a1a310d8baaf608a5deadf221b6 # v2.8.4
44
hooks:
55
- id: "jlfmt"

benchmark/benchmarks.jl

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

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

2927
# use several random matrices to reduce variance
3028
nb_samples = 5
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]
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]
3331
Bs = [compress(Float64.(A), result) for (A, result) in zip(As, results)]
3432

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

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

docs/make.jl

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

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

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

139
makedocs(;
14-
modules = [SparseMatrixColorings],
15-
authors = "Guillaume Dalle and Alexis Montoison",
16-
sitename = "SparseMatrixColorings.jl",
17-
format = Documenter.HTML(),
18-
pages = [
10+
modules=[SparseMatrixColorings],
11+
authors="Guillaume Dalle and Alexis Montoison",
12+
sitename="SparseMatrixColorings.jl",
13+
format=Documenter.HTML(),
14+
pages=[
1915
"Home" => "index.md",
2016
"tutorial.md",
2117
"api.md",
2218
"Developer Documentation" => ["dev.md", "vis.md"],
2319
],
24-
plugins = [links],
20+
plugins=[links],
2521
)
2622

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

ext/SparseMatrixColoringsCUDAExt.jl

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

1010
function SMC.ColumnColoringResult(
11-
A::CuSparseMatrixCSC,
12-
bg::SMC.BipartiteGraph{T},
13-
color::Vector{<:Integer},
11+
A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
1412
) where {T<:Integer}
1513
group = SMC.group_by_color(T, color)
1614
compressed_indices = SMC.column_csc_indices(bg, color)
17-
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
15+
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
1816
return SMC.ColumnColoringResult(
19-
A,
20-
bg,
21-
color,
22-
group,
23-
compressed_indices,
24-
additional_info,
17+
A, bg, color, group, compressed_indices, additional_info
2518
)
2619
end
2720

2821
function SMC.RowColoringResult(
29-
A::CuSparseMatrixCSC,
30-
bg::SMC.BipartiteGraph{T},
31-
color::Vector{<:Integer},
22+
A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
3223
) where {T<:Integer}
3324
group = SMC.group_by_color(T, color)
3425
compressed_indices = SMC.row_csc_indices(bg, color)
35-
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
26+
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
3627
return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info)
3728
end
3829

@@ -44,47 +35,33 @@ function SMC.StarSetColoringResult(
4435
) where {T<:Integer}
4536
group = SMC.group_by_color(T, color)
4637
compressed_indices = SMC.star_csc_indices(ag, color, star_set)
47-
additional_info = (; compressed_indices_gpu_csc = CuVector(compressed_indices))
38+
additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices))
4839
return SMC.StarSetColoringResult(
49-
A,
50-
ag,
51-
color,
52-
group,
53-
compressed_indices,
54-
additional_info,
40+
A, ag, color, group, compressed_indices, additional_info
5541
)
5642
end
5743

5844
## CSR Result
5945

6046
function SMC.ColumnColoringResult(
61-
A::CuSparseMatrixCSR,
62-
bg::SMC.BipartiteGraph{T},
63-
color::Vector{<:Integer},
47+
A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
6448
) where {T<:Integer}
6549
group = SMC.group_by_color(T, color)
6650
compressed_indices = SMC.column_csc_indices(bg, color)
6751
compressed_indices_csr = SMC.column_csr_indices(bg, color)
68-
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices_csr))
52+
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr))
6953
return SMC.ColumnColoringResult(
70-
A,
71-
bg,
72-
color,
73-
group,
74-
compressed_indices,
75-
additional_info,
54+
A, bg, color, group, compressed_indices, additional_info
7655
)
7756
end
7857

7958
function SMC.RowColoringResult(
80-
A::CuSparseMatrixCSR,
81-
bg::SMC.BipartiteGraph{T},
82-
color::Vector{<:Integer},
59+
A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer}
8360
) where {T<:Integer}
8461
group = SMC.group_by_color(T, color)
8562
compressed_indices = SMC.row_csc_indices(bg, color)
8663
compressed_indices_csr = SMC.row_csr_indices(bg, color)
87-
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices_csr))
64+
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr))
8865
return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info)
8966
end
9067

@@ -96,14 +73,9 @@ function SMC.StarSetColoringResult(
9673
) where {T<:Integer}
9774
group = SMC.group_by_color(T, color)
9875
compressed_indices = SMC.star_csc_indices(ag, color, star_set)
99-
additional_info = (; compressed_indices_gpu_csr = CuVector(compressed_indices))
76+
additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices))
10077
return SMC.StarSetColoringResult(
101-
A,
102-
ag,
103-
color,
104-
group,
105-
compressed_indices,
106-
additional_info,
78+
A, ag, color, group, compressed_indices, additional_info
10779
)
10880
end
10981

@@ -112,19 +84,15 @@ end
11284
for R in (:ColumnColoringResult, :RowColoringResult)
11385
# loop to avoid method ambiguity
11486
@eval function SMC.decompress!(
115-
A::CuSparseMatrixCSC,
116-
B::CuMatrix,
117-
result::SMC.$R{<:CuSparseMatrixCSC},
87+
A::CuSparseMatrixCSC, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSC}
11888
)
11989
compressed_indices = result.additional_info.compressed_indices_gpu_csc
12090
copyto!(A.nzVal, view(B, compressed_indices))
12191
return A
12292
end
12393

12494
@eval function SMC.decompress!(
125-
A::CuSparseMatrixCSR,
126-
B::CuMatrix,
127-
result::SMC.$R{<:CuSparseMatrixCSR},
95+
A::CuSparseMatrixCSR, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSR}
12896
)
12997
compressed_indices = result.additional_info.compressed_indices_gpu_csr
13098
copyto!(A.nzVal, view(B, compressed_indices))
@@ -136,12 +104,12 @@ function SMC.decompress!(
136104
A::CuSparseMatrixCSC,
137105
B::CuMatrix,
138106
result::SMC.StarSetColoringResult{<:CuSparseMatrixCSC},
139-
uplo::Symbol = :F,
107+
uplo::Symbol=:F,
140108
)
141109
if uplo != :F
142110
throw(
143111
SMC.UnsupportedDecompressionError(
144-
"Single-triangle decompression is not supported on GPU matrices",
112+
"Single-triangle decompression is not supported on GPU matrices"
145113
),
146114
)
147115
end
@@ -154,12 +122,12 @@ function SMC.decompress!(
154122
A::CuSparseMatrixCSR,
155123
B::CuMatrix,
156124
result::SMC.StarSetColoringResult{<:CuSparseMatrixCSR},
157-
uplo::Symbol = :F,
125+
uplo::Symbol=:F,
158126
)
159127
if uplo != :F
160128
throw(
161129
SMC.UnsupportedDecompressionError(
162-
"Single-triangle decompression is not supported on GPU matrices",
130+
"Single-triangle decompression is not supported on GPU matrices"
163131
),
164132
)
165133
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: 15 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,14 +53,15 @@ 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 =
57-
promote_colors(colorscheme, background_color, border_color)
56+
colorscheme, background_color, border_color = promote_colors(
57+
colorscheme, background_color, border_color
58+
)
5859
else
5960
# Sample n distinguishable colors, excluding the background and border color
6061
colorscheme = distinguishable_colors(
6162
ncolors(res),
6263
[convert(RGB, background_color), convert(RGB, border_color)];
63-
dropseed = true,
64+
dropseed=true,
6465
)
6566
end
6667
outs = allocate_outputs(res, background_color, border_color, scale, border, pad)
@@ -85,7 +86,7 @@ function matrix_entry_area(I::CartesianIndex, scale, border, pad)
8586
end
8687

8788
function matrix_entry_plus_border_area(I::CartesianIndex, scale, border, pad)
88-
stencil = CartesianIndices((1:(scale+2border), 1:(scale+2border)))
89+
stencil = CartesianIndices((1:(scale + 2border), 1:(scale + 2border)))
8990
return CartesianIndex(1, 1) * pad +
9091
(I - CartesianIndex(1, 1)) * (scale + 2border + pad) .+ stencil
9192
end
@@ -270,8 +271,9 @@ function show_colors!(
270271
A_ccolor_indices = mod1.(column_colors(res), length(colorscheme))
271272
A_rcolor_indices = mod1.(row_shift .+ row_colors(res), length(colorscheme))
272273
B_ccolor_indices = mod1.(1:maximum(column_colors(res)), length(colorscheme))
273-
B_rcolor_indices =
274-
mod1.((row_shift+1):(row_shift+maximum(row_colors(res))), length(colorscheme))
274+
B_rcolor_indices = mod1.(
275+
(row_shift + 1):(row_shift + maximum(row_colors(res))), length(colorscheme)
276+
)
275277
A_ccolors = colorscheme[A_ccolor_indices]
276278
A_rcolors = colorscheme[A_rcolor_indices]
277279
B_ccolors = colorscheme[B_ccolor_indices]

ext/SparseMatrixColoringsGPUArraysExt.jl

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

1111
function SMC.compress(
12-
A::AbstractGPUSparseMatrix,
13-
result::SMC.AbstractColoringResult{structure,:column},
12+
A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:column}
1413
) where {structure}
1514
A_cpu = SparseMatrixCSC(A)
1615
B_cpu = SMC.compress(A_cpu, result)
@@ -19,8 +18,7 @@ function SMC.compress(
1918
end
2019

2120
function SMC.compress(
22-
A::AbstractGPUSparseMatrix,
23-
result::SMC.AbstractColoringResult{structure,:row},
21+
A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:row}
2422
) where {structure}
2523
A_cpu = SparseMatrixCSC(A)
2624
B_cpu = SMC.compress(A_cpu, result)

ext/SparseMatrixColoringsJuMPExt.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ 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))
2929
model = Model(optimizer)
3030
silent && set_silent(model)
3131
# one variable per vertex to color, removing some renumbering symmetries
32-
@variable(model, 1 <= color[i=1:n] <= i, Int)
32+
@variable(model, 1 <= color[i = 1:n] <= i, Int)
3333
# one variable to count the number of distinct colors
3434
@variable(model, ncolors, Int)
3535
@constraint(model, [ncolors; color] in MOI.CountDistinct(n + 1))
@@ -66,22 +66,14 @@ end
6666
function ADTypes.column_coloring(A::AbstractMatrix, algo::OptimalColoringAlgorithm)
6767
bg = BipartiteGraph(A)
6868
return optimal_distance2_coloring(
69-
bg,
70-
Val(2),
71-
algo.optimizer;
72-
algo.silent,
73-
algo.assert_solved,
69+
bg, Val(2), algo.optimizer; algo.silent, algo.assert_solved
7470
)
7571
end
7672

7773
function ADTypes.row_coloring(A::AbstractMatrix, algo::OptimalColoringAlgorithm)
7874
bg = BipartiteGraph(A)
7975
return optimal_distance2_coloring(
80-
bg,
81-
Val(1),
82-
algo.optimizer;
83-
algo.silent,
84-
algo.assert_solved,
76+
bg, Val(1), algo.optimizer; algo.silent, algo.assert_solved
8577
)
8678
end
8779

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)