Skip to content

Commit 8635b3d

Browse files
committed
Decompression of acyclic coloring with SparseMatrixCSC
1 parent ec19388 commit 8635b3d

2 files changed

Lines changed: 43 additions & 29 deletions

File tree

src/decompression.jl

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -571,27 +571,40 @@ function decompress!(
571571
val = B[i, color[j]] - buffer_right_type[i]
572572
buffer_right_type[j] = buffer_right_type[j] + val
573573

574-
# A[i,j] = val
575-
if in_triangle(i, j, uplo)
576-
if uplo == :L
574+
#! format: off
575+
# A[i,j] is in the lower triangular part of A
576+
if in_triangle(i, j, :L)
577+
# uplo = :L or uplo = :F
578+
# A[i,j] is stored at index_ij = (A.colptr[j+1] - offset_L) in A.nzval
579+
if uplo != :U
577580
nzind = A.colptr[j + 1] - lower_triangle_offsets[counter]
578-
else
581+
nzA[nzind] = val
582+
end
583+
584+
# uplo = :U or uplo = :F
585+
# A[j,i] is stored at index_ji = (A.colptr[i] + offset_U) in A.nzval
586+
if uplo != :L
587+
nzind = A.colptr[i] + upper_triangle_offsets[counter]
588+
nzA[nzind] = val
589+
end
590+
591+
# A[i,j] is in the upper triangular part of A
592+
else
593+
# uplo = :U or uplo = :F
594+
# A[i,j] is stored at index_ij = (A.colptr[j] + offset_U) in A.nzval
595+
if uplo != :L
579596
nzind = A.colptr[j] + upper_triangle_offsets[counter]
597+
nzA[nzind] = val
580598
end
581-
# Both values of `nzind` can be used if uplo = :F
582-
nzA[nzind] = val
583-
end
584599

585-
# A[j,i] = val
586-
if in_triangle(j, i, uplo)
587-
if uplo == :L
600+
# uplo = :L or uplo = :F
601+
# A[j,i] is stored at index_ji = (A.colptr[i+1] - offset_L) in A.nzval
602+
if uplo != :U
588603
nzind = A.colptr[i + 1] - lower_triangle_offsets[counter]
589-
else
590-
nzind = A.colptr[i] + upper_triangle_offsets[counter]
604+
nzA[nzind] = val
591605
end
592-
# Both values of `nzind` can be used if uplo = :F
593-
nzA[nzind] = val
594606
end
607+
#! format: on
595608
end
596609
end
597610
return A

src/result.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function TreeSetColoringResult(
347347
end
348348

349349
# continue until all leaves are treated
350-
while queue_start queue_end
350+
while queue_start <= queue_end
351351
leaf = queue[queue_start]
352352
queue_start += 1
353353

@@ -373,29 +373,30 @@ function TreeSetColoringResult(
373373
j = neighbor
374374
col_i = view(rv, nzrange(S, i))
375375
col_j = view(rv, nzrange(S, j))
376-
index_ij = S.colptr[j] - 1 + searchsortedfirst(col_j, i) # S.nzval[index_ij] = S[i,j]
377-
@assert S.nzval[index_ij] == S[i,j]
378-
index_ji = S.colptr[i] - 1 + searchsortedfirst(col_i, j) # S.nzval[index_ji] = S[j,i]
379-
@assert S.nzval[index_ji] == S[j,i]
380376
index_offsets += 1
381377

378+
#! format: off
379+
# S[i,j] is in the lower triangular part of S
382380
if in_triangle(i, j, :L)
383381
# uplo = :L or uplo = :F
384-
# A[i,j] is stored at index_ij = (A.colptr[j+1] - offset_L) in A.nzval
385-
lower_triangle_offsets[index_offsets] = S.colptr[j + 1] - index_ij
382+
# S[i,j] is stored at index_ij = (S.colptr[j+1] - offset_L) in S.nzval
383+
lower_triangle_offsets[index_offsets] = length(col_j) - searchsortedfirst(col_j, i) + 1
386384

387385
# uplo = :U or uplo = :F
388-
# A[j,i] is stored at index_ji = (A.colptr[i] + offset_U) in A.nzval
389-
upper_triangle_offsets[index_offsets] = index_ji - S.colptr[i]
390-
else
391-
# uplo = :L or uplo = :F
392-
# A[j,i] is stored at index_ji = (A.colptr[i+1] - offset_L) in A.nzval
393-
lower_triangle_offsets[index_offsets] = S.colptr[i + 1] - index_ji
386+
# S[j,i] is stored at index_ji = (S.colptr[i] + offset_U) in S.nzval
387+
upper_triangle_offsets[index_offsets] = searchsortedfirst(col_i, j)::Int - 1
394388

389+
# S[i,j] is in the upper triangular part of S
390+
else
395391
# uplo = :U or uplo = :F
396-
# A[i,j] is stored at index_ij = (A.colptr[j] + offset_U) in A.nzval
397-
upper_triangle_offsets[index_offsets] = index_ij - S.colptr[j]
392+
# S[i,j] is stored at index_ij = (S.colptr[j] + offset_U) in S.nzval
393+
upper_triangle_offsets[index_offsets] = searchsortedfirst(col_j, i)::Int - 1
394+
395+
# uplo = :L or uplo = :F
396+
# S[j,i] is stored at index_ji = (S.colptr[i+1] - offset_L) in S.nzval
397+
lower_triangle_offsets[index_offsets] = length(col_i) - searchsortedfirst(col_i, j) + 1
398398
end
399+
#! format: on
399400
end
400401
end
401402
end

0 commit comments

Comments
 (0)