Skip to content

Commit 2037afe

Browse files
committed
More modifications
1 parent 08a29bf commit 2037afe

4 files changed

Lines changed: 57 additions & 20 deletions

File tree

src/decompression.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,44 @@ function decompress!(
537537
return A
538538
end
539539

540+
function decompress_single_color!(
541+
A::SparseMatrixCSC,
542+
b::AbstractVector,
543+
c::Integer,
544+
result::StarSetColoringResult,
545+
uplo::Symbol=:F,
546+
)
547+
(; ag, compressed_indices) = result
548+
(; S) = ag
549+
lower_index = (c - 1) * S.n + 1
550+
upper_index = c * S.n
551+
nzA = nonzeros(A)
552+
if result.decompression_uplo == uplo
553+
uplo == :F && check_same_pattern(A, S)
554+
for k in eachindex(nzA, compressed_indices)
555+
if lower_index <= compressed_indices[k] <= upper_index
556+
nzA[k] = b[compressed_indices[k] - lower_index + 1]
557+
end
558+
end
559+
else
560+
@assert result.decompression_uplo == :F
561+
rvS = rowvals(S)
562+
l = 0 # assume A has the same pattern as the triangle
563+
for j in axes(S, 2)
564+
for k in nzrange(S, j)
565+
i = rvS[k]
566+
if in_triangle(i, j, uplo)
567+
l += 1
568+
if lower_index <= compressed_indices[k] <= upper_index
569+
nzA[l] = b[i]
570+
end
571+
end
572+
end
573+
end
574+
end
575+
return A
576+
end
577+
540578
## TreeSetColoringResult
541579

542580
function decompress!(

src/graph.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,7 @@ function degree(g::AdjacencyGraph{T,false}, v::Integer) where {T}
284284
return g.S.colptr[v + 1] - g.S.colptr[v] - has_selfloop
285285
end
286286

287-
nb_edges(g::AdjacencyGraph{T,true}) where {T} = nnz(g.S) ÷ 2
288-
289-
function nb_edges(g::AdjacencyGraph{T,false}) where {T}
290-
ne = 0
291-
for v in vertices(g)
292-
ne += degree(g, v)
293-
end
294-
return ne ÷ 2
295-
end
287+
nb_edges(g::AdjacencyGraph) = (nnz(g.S) - g.nb_self_loops) ÷ 2
296288

297289
maximum_degree(g::AdjacencyGraph) = maximum(Base.Fix1(degree, g), vertices(g))
298290
minimum_degree(g::AdjacencyGraph) = minimum(Base.Fix1(degree, g), vertices(g))

src/interface.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ function coloring(
190190
A::AbstractMatrix,
191191
problem::ColoringProblem,
192192
algo::GreedyColoringAlgorithm;
193-
decompression_eltype::Type{R}=Float64,
194193
symmetric_pattern::Bool=false,
194+
decompression_eltype::Type{R}=Float64,
195+
decompression_uplo::Symbol=:F,
195196
) where {R}
196-
return _coloring(WithResult(), A, problem, algo, R, symmetric_pattern)
197+
return _coloring(WithResult(), A, problem, algo, symmetric_pattern, R, decompression_uplo)
197198
end
198199

199200
"""
@@ -229,8 +230,9 @@ function _coloring(
229230
A::AbstractMatrix,
230231
::ColoringProblem{:nonsymmetric,:column},
231232
algo::GreedyColoringAlgorithm,
233+
symmetric_pattern::Bool,
232234
decompression_eltype::Type,
233-
symmetric_pattern::Bool;
235+
decompression_uplo::Symbol;
234236
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
235237
)
236238
symmetric_pattern = symmetric_pattern || A isa Union{Symmetric,Hermitian}
@@ -252,8 +254,9 @@ function _coloring(
252254
A::AbstractMatrix,
253255
::ColoringProblem{:nonsymmetric,:row},
254256
algo::GreedyColoringAlgorithm,
257+
symmetric_pattern::Bool,
255258
decompression_eltype::Type,
256-
symmetric_pattern::Bool;
259+
decompression_uplo::Symbol;
257260
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
258261
)
259262
symmetric_pattern = symmetric_pattern || A isa Union{Symmetric,Hermitian}
@@ -275,8 +278,9 @@ function _coloring(
275278
A::AbstractMatrix,
276279
::ColoringProblem{:symmetric,:column},
277280
algo::GreedyColoringAlgorithm{:direct},
281+
symmetric_pattern::Bool,
278282
decompression_eltype::Type,
279-
symmetric_pattern::Bool;
283+
decompression_uplo::Symbol;
280284
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
281285
)
282286
ag = AdjacencyGraph(A; augmented_graph=false)
@@ -286,7 +290,7 @@ function _coloring(
286290
end
287291
color, star_set = argmin(maximum first, color_and_star_set_by_order)
288292
if speed_setting isa WithResult
289-
return StarSetColoringResult(A, ag, color, star_set)
293+
return StarSetColoringResult(A, ag, color, star_set; decompression_uplo)
290294
else
291295
return color
292296
end
@@ -297,8 +301,9 @@ function _coloring(
297301
A::AbstractMatrix,
298302
::ColoringProblem{:symmetric,:column},
299303
algo::GreedyColoringAlgorithm{:substitution},
300-
decompression_eltype::Type{R},
301304
symmetric_pattern::Bool,
305+
decompression_eltype::Type{R},
306+
decompression_uplo::Symbol,
302307
) where {R}
303308
ag = AdjacencyGraph(A; augmented_graph=false)
304309
color_and_tree_set_by_order = map(algo.orders) do order
@@ -307,7 +312,7 @@ function _coloring(
307312
end
308313
color, tree_set = argmin(maximum first, color_and_tree_set_by_order)
309314
if speed_setting isa WithResult
310-
return TreeSetColoringResult(A, ag, color, tree_set, R)
315+
return TreeSetColoringResult(A, ag, color, tree_set, R; decompression_uplo)
311316
else
312317
return color
313318
end
@@ -318,8 +323,9 @@ function _coloring(
318323
A::AbstractMatrix,
319324
::ColoringProblem{:nonsymmetric,:bidirectional},
320325
algo::GreedyColoringAlgorithm{:direct},
326+
symmetric_pattern::Bool,
321327
decompression_eltype::Type{R},
322-
symmetric_pattern::Bool;
328+
decompression_uplo::Symbol;
323329
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
324330
) where {R}
325331
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
@@ -368,8 +374,9 @@ function _coloring(
368374
A::AbstractMatrix,
369375
::ColoringProblem{:nonsymmetric,:bidirectional},
370376
algo::GreedyColoringAlgorithm{:substitution},
371-
decompression_eltype::Type{R},
372377
symmetric_pattern::Bool,
378+
decompression_eltype::Type{R},
379+
decompression_uplo::Symbol,
373380
) where {R}
374381
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
375382
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index, 0; augmented_graph=true)

src/result.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function star_csc_indices(
339339
rvS = rowvals(S)
340340
nb_indices = nnz(S)
341341
if decompression_uplo != :F
342-
nb_indices = (nb_indices - nb_self_loops) ÷ 2 + nb_self_loops
342+
nb_indices = nb_edges(ag) + nb_self_loops
343343
end
344344
compressed_indices = zeros(T, nb_indices) # needs to be independent from the storage in the graph, in case the graph gets reused
345345
l = 0

0 commit comments

Comments
 (0)