Skip to content

Commit 87282ee

Browse files
committed
Check is_star only once during decompression
1 parent a2df751 commit 87282ee

1 file changed

Lines changed: 93 additions & 51 deletions

File tree

src/decompression.jl

Lines changed: 93 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -565,22 +565,28 @@ function decompress!(
565565
# Reset the buffer to zero for the root vertex
566566
(_, root) = reverse_bfs_orders[k][end]
567567
buffer_right_type[root] = zero(R)
568-
end
569568

570-
for (i, j) in reverse_bfs_orders[k]
571-
if !is_star[k]
572-
# the tree is not a star
569+
# The tree is not a star
570+
for (i, j) in reverse_bfs_orders[k]
573571
val = B[i, color[j]] - buffer_right_type[i]
574572
buffer_right_type[j] = buffer_right_type[j] + val
575-
else
576-
# the tree is a trivial or non-trivial star
577-
val = B[i, color[j]]
578-
end
579-
if in_triangle(i, j, uplo)
580-
A[i, j] = val
573+
if in_triangle(i, j, uplo)
574+
A[i, j] = val
575+
end
576+
if in_triangle(j, i, uplo)
577+
A[j, i] = val
578+
end
581579
end
582-
if in_triangle(j, i, uplo)
583-
A[j, i] = val
580+
else
581+
# The tree is a star (trivial or non-trivial)
582+
for (i, j) in reverse_bfs_orders[k]
583+
val = B[i, color[j]]
584+
if in_triangle(i, j, uplo)
585+
A[i, j] = val
586+
end
587+
if in_triangle(j, i, uplo)
588+
A[j, i] = val
589+
end
584590
end
585591
end
586592
end
@@ -651,53 +657,89 @@ function decompress!(
651657
# Reset the buffer to zero for the root vertex
652658
(_, root) = reverse_bfs_orders[k][end]
653659
buffer_right_type[root] = zero(R)
654-
end
655660

656-
for (i, j) in reverse_bfs_orders[k]
657-
counter += 1
658-
if !is_star[k]
659-
# the tree is not a star
661+
# The tree is not a star
662+
for (i, j) in reverse_bfs_orders[k]
663+
counter += 1
660664
val = B[i, color[j]] - buffer_right_type[i]
661665
buffer_right_type[j] = buffer_right_type[j] + val
662-
else
663-
# the tree is a trivial or non-trivial star
664-
val = B[i, color[j]]
665-
end
666666

667-
#! format: off
668-
# A[i,j] is in the lower triangular part of A
669-
if in_triangle(i, j, :L)
670-
# uplo = :L or uplo = :F
671-
# A[i,j] is stored at index_ij = (A.colptr[j+1] - offset_L) in A.nzval
672-
if uplo != :U
673-
nzind = A_colptr[j + 1] - lower_triangle_offsets[counter]
674-
nzA[nzind] = val
675-
end
676-
677-
# uplo = :U or uplo = :F
678-
# A[j,i] is stored at index_ji = (A.colptr[i] + offset_U) in A.nzval
679-
if uplo != :L
680-
nzind = A_colptr[i] + upper_triangle_offsets[counter]
681-
nzA[nzind] = val
682-
end
683-
684-
# A[i,j] is in the upper triangular part of A
685-
else
686-
# uplo = :U or uplo = :F
687-
# A[i,j] is stored at index_ij = (A.colptr[j] + offset_U) in A.nzval
688-
if uplo != :L
689-
nzind = A_colptr[j] + upper_triangle_offsets[counter]
690-
nzA[nzind] = val
667+
#! format: off
668+
# A[i,j] is in the lower triangular part of A
669+
if in_triangle(i, j, :L)
670+
# uplo = :L or uplo = :F
671+
# A[i,j] is stored at index_ij = (A.colptr[j+1] - offset_L) in A.nzval
672+
if uplo != :U
673+
nzind = A_colptr[j + 1] - lower_triangle_offsets[counter]
674+
nzA[nzind] = val
675+
end
676+
677+
# uplo = :U or uplo = :F
678+
# A[j,i] is stored at index_ji = (A.colptr[i] + offset_U) in A.nzval
679+
if uplo != :L
680+
nzind = A_colptr[i] + upper_triangle_offsets[counter]
681+
nzA[nzind] = val
682+
end
683+
684+
# A[i,j] is in the upper triangular part of A
685+
else
686+
# uplo = :U or uplo = :F
687+
# A[i,j] is stored at index_ij = (A.colptr[j] + offset_U) in A.nzval
688+
if uplo != :L
689+
nzind = A_colptr[j] + upper_triangle_offsets[counter]
690+
nzA[nzind] = val
691+
end
692+
693+
# uplo = :L or uplo = :F
694+
# A[j,i] is stored at index_ji = (A.colptr[i+1] - offset_L) in A.nzval
695+
if uplo != :U
696+
nzind = A_colptr[i + 1] - lower_triangle_offsets[counter]
697+
nzA[nzind] = val
698+
end
691699
end
700+
#! format: on
701+
end
702+
else
703+
# The tree is a star (trivial or non-trivial)
704+
for (i, j) in reverse_bfs_orders[k]
705+
counter += 1
706+
val = B[i, color[j]]
692707

693-
# uplo = :L or uplo = :F
694-
# A[j,i] is stored at index_ji = (A.colptr[i+1] - offset_L) in A.nzval
695-
if uplo != :U
696-
nzind = A_colptr[i + 1] - lower_triangle_offsets[counter]
697-
nzA[nzind] = val
708+
#! format: off
709+
# A[i,j] is in the lower triangular part of A
710+
if in_triangle(i, j, :L)
711+
# uplo = :L or uplo = :F
712+
# A[i,j] is stored at index_ij = (A.colptr[j+1] - offset_L) in A.nzval
713+
if uplo != :U
714+
nzind = A_colptr[j + 1] - lower_triangle_offsets[counter]
715+
nzA[nzind] = val
716+
end
717+
718+
# uplo = :U or uplo = :F
719+
# A[j,i] is stored at index_ji = (A.colptr[i] + offset_U) in A.nzval
720+
if uplo != :L
721+
nzind = A_colptr[i] + upper_triangle_offsets[counter]
722+
nzA[nzind] = val
723+
end
724+
725+
# A[i,j] is in the upper triangular part of A
726+
else
727+
# uplo = :U or uplo = :F
728+
# A[i,j] is stored at index_ij = (A.colptr[j] + offset_U) in A.nzval
729+
if uplo != :L
730+
nzind = A_colptr[j] + upper_triangle_offsets[counter]
731+
nzA[nzind] = val
732+
end
733+
734+
# uplo = :L or uplo = :F
735+
# A[j,i] is stored at index_ji = (A.colptr[i+1] - offset_L) in A.nzval
736+
if uplo != :U
737+
nzind = A_colptr[i + 1] - lower_triangle_offsets[counter]
738+
nzA[nzind] = val
739+
end
698740
end
741+
#! format: on
699742
end
700-
#! format: on
701743
end
702744
end
703745
return A

0 commit comments

Comments
 (0)