@@ -528,6 +528,41 @@ function decompress!(
528528 return A
529529end
530530
531+ function decompress! (
532+ A:: SparseMatrixCSC ,
533+ Br:: AbstractMatrix ,
534+ Bc:: AbstractMatrix ,
535+ symmetric_to_row:: Vector{Int} ,
536+ symmetric_to_column:: Vector{Int} ,
537+ result:: StarSetColoringResult ,
538+ )
539+ (; ag, color, compressed_indices) = result
540+ (; S) = ag
541+ n = size (Br, 2 )
542+ m = size (Bc, 1 )
543+ dim = m + n
544+ nzA = nonzeros (A)
545+ rvS = rowvals (S)
546+ l = 0 # assume A has the same pattern as the triangle
547+ for j in axes (S, 2 )
548+ for k in nzrange (S, j)
549+ i = rvS[k]
550+ if in_triangle (i, j, :L )
551+ l += 1
552+ j2, i2 = divrem (compressed_indices[k] - 1 , dim)
553+ j2 += 1
554+ i2 += 1
555+ if i2 ≤ n
556+ nzA[l] = Br[symmetric_to_row[j2], i2]
557+ else
558+ nzA[l] = Bc[i2 - n, symmetric_to_column[j2]]
559+ end
560+ end
561+ end
562+ end
563+ return A
564+ end
565+
531566# # TreeSetColoringResult
532567
533568function decompress! (
@@ -684,6 +719,74 @@ function decompress!(
684719 return A
685720end
686721
722+ function decompress! (
723+ A:: SparseMatrixCSC{R} ,
724+ Br:: AbstractMatrix{R} ,
725+ Bc:: AbstractMatrix{R} ,
726+ symmetric_to_row:: Vector{Int} ,
727+ symmetric_to_column:: Vector{Int} ,
728+ result:: TreeSetColoringResult ,
729+ ) where {R<: Real }
730+ (;
731+ ag,
732+ color,
733+ reverse_bfs_orders,
734+ diagonal_indices,
735+ diagonal_nzind,
736+ lower_triangle_offsets,
737+ upper_triangle_offsets,
738+ buffer,
739+ ) = result
740+ (; S) = ag
741+ A_colptr = A. colptr
742+ nzA = nonzeros (A)
743+ m = size (Bc, 1 )
744+ n = size (Br, 2 )
745+
746+ if eltype (buffer) == R
747+ buffer_right_type = buffer
748+ else
749+ buffer_right_type = similar (buffer, R)
750+ end
751+
752+ # Index of offsets in lower_triangle_offsets and upper_triangle_offsets
753+ counter = 0
754+
755+ # Recover the off-diagonal coefficients of A
756+ for k in eachindex (reverse_bfs_orders)
757+ # Reset the buffer to zero for all vertices in a tree (except the root)
758+ for (vertex, _) in reverse_bfs_orders[k]
759+ buffer_right_type[vertex] = zero (R)
760+ end
761+ # Reset the buffer to zero for the root vertex
762+ (_, root) = reverse_bfs_orders[k][end ]
763+ buffer_right_type[root] = zero (R)
764+
765+ for (i, j) in reverse_bfs_orders[k]
766+ counter += 1
767+ if i ≤ n
768+ val = Br[symmetric_to_row[color[j]], i] - buffer_right_type[i]
769+ else
770+ val = Bc[i - n, symmetric_to_column[color[j]]] - buffer_right_type[i]
771+ end
772+ buffer_right_type[j] = buffer_right_type[j] + val
773+
774+ # ! format: off
775+ # A[i,j] is in the lower triangular part of A
776+ if in_triangle (i, j, :L )
777+ nzind = A_colptr[j + 1 ] - lower_triangle_offsets[counter]
778+ nzA[nzind] = val
779+ # A[i,j] is in the upper triangular part of A
780+ else
781+ nzind = A_colptr[i + 1 ] - lower_triangle_offsets[counter]
782+ nzA[nzind] = val
783+ end
784+ # ! format: on
785+ end
786+ end
787+ return A
788+ end
789+
687790# # MatrixInverseColoringResult
688791
689792function decompress! (
@@ -782,10 +885,9 @@ function decompress!(
782885 symmetric_to_row, symmetric_to_column, symmetric_result, large_colptr, large_rowval
783886 ) = result
784887 m, n = size (A)
785- Br_and_Bc = JoinCompressed (m, n, Br, Bc, symmetric_to_row, symmetric_to_column)
786888 # pretend A is larger
787889 A_and_noAᵀ = SparseMatrixCSC (m + n, m + n, large_colptr, large_rowval, A. nzval)
788890 # decompress lower triangle only
789- decompress! (A_and_noAᵀ, Br_and_Bc, symmetric_result, :L )
891+ decompress! (A_and_noAᵀ, Br, Bc, symmetric_to_row, symmetric_to_column, symmetric_result )
790892 return A
791893end
0 commit comments