Skip to content

Commit 9be2643

Browse files
committed
Try the compression of B in acyclic decompression
1 parent 763c8a4 commit 9be2643

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/decompression.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ function decompress!(
592592
diagonal_nzind,
593593
lower_triangle_offsets,
594594
upper_triangle_offsets,
595+
compressed_diag,
596+
compressed_indices,
595597
buffer,
596598
) = result
597599
(; S) = ag
@@ -608,21 +610,24 @@ function decompress!(
608610
# Recover the diagonal coefficients of A
609611
if has_diagonal(ag)
610612
if uplo == :L
611-
for i in diagonal_indices
613+
for (k, i) in enumerate(diagonal_indices)
612614
# A[i, i] is the first element in column i
613615
nzind = A_colptr[i]
614-
nzA[nzind] = B[i, color[i]]
616+
pos = compressed_diag[k]
617+
nzA[nzind] = B[pos]
615618
end
616619
elseif uplo == :U
617-
for i in diagonal_indices
620+
for (k, i) in enumerate(diagonal_indices)
618621
# A[i, i] is the last element in column i
619622
nzind = A_colptr[i + 1] - 1
620-
nzA[nzind] = B[i, color[i]]
623+
pos = compressed_diag[k]
624+
nzA[nzind] = B[pos]
621625
end
622626
else # uplo == :F
623627
for (k, i) in enumerate(diagonal_indices)
624628
nzind = diagonal_nzind[k]
625-
nzA[nzind] = B[i, color[i]]
629+
pos = compressed_diag[k]
630+
nzA[nzind] = B[pos]
626631
end
627632
end
628633
end
@@ -642,7 +647,8 @@ function decompress!(
642647

643648
for (i, j) in reverse_bfs_orders[k]
644649
counter += 1
645-
val = B[i, color[j]] - buffer_right_type[i]
650+
pos = compressed_indices[counter]
651+
val = B[pos] - buffer_right_type[i]
646652
buffer_right_type[j] = buffer_right_type[j] + val
647653

648654
#! format: off

src/result.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ struct TreeSetColoringResult{M<:AbstractMatrix,G<:AdjacencyGraph,V,R} <:
283283
diagonal_nzind::Vector{Int}
284284
lower_triangle_offsets::Vector{Int}
285285
upper_triangle_offsets::Vector{Int}
286+
compressed_diag::Vector{Int}
287+
compressed_indices::Vector{Int}
286288
buffer::Vector{R}
287289
end
288290

@@ -302,6 +304,7 @@ function TreeSetColoringResult(
302304
# Vector for the decompression of the diagonal coefficients
303305
diagonal_indices = Int[]
304306
diagonal_nzind = Int[]
307+
compressed_diag = Int[]
305308
ndiag = 0
306309

307310
if has_diagonal(ag)
@@ -311,6 +314,7 @@ function TreeSetColoringResult(
311314
if i == j
312315
push!(diagonal_indices, i)
313316
push!(diagonal_nzind, k)
317+
push!(compressed_diag, (color[i] - 1) * nvertices + i)
314318
ndiag += 1
315319
end
316320
end
@@ -321,8 +325,9 @@ function TreeSetColoringResult(
321325
nedges = (nnz(S) - ndiag) ÷ 2
322326
lower_triangle_offsets = Vector{Int}(undef, nedges)
323327
upper_triangle_offsets = Vector{Int}(undef, nedges)
328+
compressed_indices = Vector{Int}(undef, nedges)
324329

325-
# Index in lower_triangle_offsets and upper_triangle_offsets
330+
# Index in compressed_indices, lower_triangle_offsets and upper_triangle_offsets
326331
index_offsets = 0
327332

328333
for k in eachindex(reverse_bfs_orders)
@@ -334,6 +339,8 @@ function TreeSetColoringResult(
334339
col_j = view(rv, nzrange(S, j))
335340
index_offsets += 1
336341

342+
compressed_indices[index_offsets] = (color[j] - 1) * nvertices + i)
343+
337344
#! format: off
338345
# S[i,j] is in the lower triangular part of S
339346
if in_triangle(i, j, :L)
@@ -373,6 +380,8 @@ function TreeSetColoringResult(
373380
diagonal_nzind,
374381
lower_triangle_offsets,
375382
upper_triangle_offsets,
383+
compressed_diag,
384+
compressed_indices,
376385
buffer,
377386
)
378387
end

0 commit comments

Comments
 (0)