Skip to content

Commit a03a455

Browse files
authored
Merge two decompress! for star coloring (#129)
1 parent 96830d4 commit a03a455

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

src/decompression.jl

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function in_triangle(i::Integer, j::Integer, uplo::Symbol)
257257
return true
258258
elseif uplo == :U
259259
return i <= j
260-
else
260+
else # uplo == :L
261261
return i >= j
262262
end
263263
end
@@ -434,35 +434,32 @@ function decompress_single_color!(
434434
end
435435

436436
function decompress!(
437-
A::SparseMatrixCSC{R}, B::AbstractMatrix{R}, result::StarSetColoringResult
438-
) where {R<:Real}
439-
@compat (; S, compressed_indices) = result
440-
check_same_pattern(A, S)
441-
nzA = nonzeros(A)
442-
for k in eachindex(nzA, compressed_indices)
443-
nzA[k] = B[compressed_indices[k]]
444-
end
445-
return A
446-
end
447-
448-
function decompress!(
449-
A::SparseMatrixCSC{R}, B::AbstractMatrix{R}, result::StarSetColoringResult, uplo::Symbol
437+
A::SparseMatrixCSC{R},
438+
B::AbstractMatrix{R},
439+
result::StarSetColoringResult,
440+
uplo::Symbol=:F,
450441
) where {R<:Real}
451442
@compat (; S, compressed_indices) = result
452-
uplo == :F && check_same_pattern(A, S)
453-
rvS = rowvals(S)
454443
nzA = nonzeros(A)
455-
l = 0 # assume A has the same pattern as the triangle
456-
for j in axes(S, 2)
457-
for k in nzrange(S, j)
458-
i = rvS[k]
459-
if in_triangle(i, j, uplo)
460-
l += 1
461-
nzA[l] = B[compressed_indices[k]]
444+
if uplo == :F
445+
check_same_pattern(A, S)
446+
for k in eachindex(nzA, compressed_indices)
447+
nzA[k] = B[compressed_indices[k]]
448+
end
449+
else
450+
rvS = rowvals(S)
451+
l = 0 # assume A has the same pattern as the triangle
452+
for j in axes(S, 2)
453+
for k in nzrange(S, j)
454+
i = rvS[k]
455+
if in_triangle(i, j, uplo)
456+
l += 1
457+
nzA[l] = B[compressed_indices[k]]
458+
end
462459
end
463460
end
461+
@assert l == length(nonzeros(A))
464462
end
465-
@assert l == length(nonzeros(A))
466463
return A
467464
end
468465

0 commit comments

Comments
 (0)