@@ -528,41 +528,6 @@ 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-
566531# # TreeSetColoringResult
567532
568533function decompress! (
@@ -719,74 +684,6 @@ function decompress!(
719684 return A
720685end
721686
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-
790687# # MatrixInverseColoringResult
791688
792689function decompress! (
@@ -861,14 +758,59 @@ function Base.getindex(B::JoinCompressed, i::Int, j::Int)
861758 end
862759end
863760
864- function Base. getindex (B:: JoinCompressed , k:: Int )
865- dim = B. m + B. n
866- j, i = divrem (k - 1 , dim)
867- return getindex (B, i + 1 , j + 1 )
761+ # # StarSetBicoloringResult
762+
763+ function decompress! (
764+ A:: AbstractMatrix ,
765+ Br:: AbstractMatrix ,
766+ Bc:: AbstractMatrix ,
767+ result:: StarSetBicoloringResult ,
768+ )
769+ (; ag, symmetric_color, symmetric_to_row, symmetric_to_column, star_set) = result
770+ (; star, hub, spokes) = star_set
771+ (; S) = ag
772+ fill! (A, zero (eltype (A)))
773+
774+ m, n = size (A)
775+ for s in eachindex (hub, spokes)
776+ j = abs (hub[s])
777+ cj = symmetric_color[j]
778+ for i in spokes[s]
779+ if in_triangle (i, j, :L )
780+ A[i - n, j] = Bc[i - n, symmetric_to_column[cj]]
781+ else
782+ A[j - n, i] = Br[symmetric_to_row[cj], i]
783+ end
784+ end
785+ end
786+ return A
787+ end
788+
789+ function decompress! (
790+ A:: SparseMatrixCSC ,
791+ Br:: AbstractMatrix ,
792+ Bc:: AbstractMatrix ,
793+ result:: StarSetBicoloringResult ,
794+ )
795+ (; ag, A_indices, compressed_indices, pos_Br) = result
796+ (; S) = ag
797+ nzA = nonzeros (A)
798+ for k in 1 : pos_Br
799+ nzA[A_indices[k]] = Br[compressed_indices[k]]
800+ end
801+ for k in (pos_Br + 1 ): length (nzA)
802+ nzA[A_indices[k]] = Bc[compressed_indices[k]]
803+ end
804+ return A
868805end
869806
807+ # # TreeSetBicoloringResult
808+
870809function decompress! (
871- A:: AbstractMatrix , Br:: AbstractMatrix , Bc:: AbstractMatrix , result:: BicoloringResult
810+ A:: AbstractMatrix ,
811+ Br:: AbstractMatrix ,
812+ Bc:: AbstractMatrix ,
813+ result:: TreeSetBicoloringResult ,
872814)
873815 (; symmetric_to_row, symmetric_to_column, symmetric_result) = result
874816 m, n = size (A)
@@ -879,15 +821,19 @@ function decompress!(
879821end
880822
881823function decompress! (
882- A:: SparseMatrixCSC , Br:: AbstractMatrix , Bc:: AbstractMatrix , result:: BicoloringResult
824+ A:: SparseMatrixCSC ,
825+ Br:: AbstractMatrix ,
826+ Bc:: AbstractMatrix ,
827+ result:: TreeSetBicoloringResult ,
883828)
884829 (;
885830 symmetric_to_row, symmetric_to_column, symmetric_result, large_colptr, large_rowval
886831 ) = result
887832 m, n = size (A)
833+ Br_and_Bc = JoinCompressed (m, n, Br, Bc, symmetric_to_row, symmetric_to_column)
888834 # pretend A is larger
889835 A_and_noAᵀ = SparseMatrixCSC (m + n, m + n, large_colptr, large_rowval, A. nzval)
890836 # decompress lower triangle only
891- decompress! (A_and_noAᵀ, Br, Bc, symmetric_to_row, symmetric_to_column, symmetric_result )
837+ decompress! (A_and_noAᵀ, Br_and_Bc, symmetric_result, :L )
892838 return A
893839end
0 commit comments