@@ -227,6 +227,10 @@ struct TreeSetColoringResult{M,R} <:
227227 group:: Vector{Vector{Int}}
228228 vertices_by_tree:: Vector{Vector{Int}}
229229 reverse_bfs_orders:: Vector{Vector{Tuple{Int,Int}}}
230+ diagonal_indices:: Vector{Int}
231+ diagonal_nzind:: Vector{Int}
232+ lower_triangle_offsets:: Vector{Int}
233+ upper_triangle_offsets:: Vector{Int}
230234 buffer:: Vector{R}
231235end
232236
@@ -236,6 +240,29 @@ function TreeSetColoringResult(
236240 nvertices = length (color)
237241 group = group_by_color (color)
238242
243+ # Vector for the decompression of the diagonal coefficients
244+ diagonal_indices = Int[]
245+ diagonal_nzind = Int[]
246+ ndiag = 0
247+
248+ n = size (S, 1 )
249+ rv = rowvals (S)
250+ for j in axes (S, 2 )
251+ for k in nzrange (S, j)
252+ i = rv[k]
253+ if i == j
254+ push! (diagonal_indices, i)
255+ push! (diagonal_nzind, k)
256+ ndiag += 1
257+ end
258+ end
259+ end
260+
261+ # Vectors for the decompression of the off-diagonal coefficients
262+ nedges = (nnz (S) - ndiag) ÷ 2
263+ lower_triangle_offsets = Vector {Int} (undef, nedges)
264+ upper_triangle_offsets = Vector {Int} (undef, nedges)
265+
239266 # forest is a structure DisjointSets from DataStructures.jl
240267 # - forest.intmap: a dictionary that maps an edge (i, j) to an integer k
241268 # - forest.revmap: a dictionary that does the reverse of intmap, mapping an integer k to an edge (i, j)
@@ -297,6 +324,9 @@ function TreeSetColoringResult(
297324 # Create a queue with a fixed size nvmax
298325 queue = Vector {Int} (undef, nvmax)
299326
327+ # Index in lower_triangle_offsets and upper_triangle_offsets
328+ index_offsets = 0
329+
300330 for k in 1 : ntrees
301331 tree = trees[k]
302332
@@ -317,7 +347,7 @@ function TreeSetColoringResult(
317347 end
318348
319349 # continue until all leaves are treated
320- while queue_start <= queue_end
350+ while queue_start ≤ queue_end
321351 leaf = queue[queue_start]
322352 queue_start += 1
323353
@@ -337,6 +367,35 @@ function TreeSetColoringResult(
337367 queue_end += 1
338368 queue[queue_end] = neighbor
339369 end
370+
371+ # Update lower_triangle_offsets and upper_triangle_offsets
372+ i = leaf
373+ j = neighbor
374+ col_i = view (rv, nzrange (S, i))
375+ 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]
380+ index_offsets += 1
381+
382+ if in_triangle (i, j, :L )
383+ # 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
386+
387+ # 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
394+
395+ # 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]
398+ end
340399 end
341400 end
342401 end
@@ -347,7 +406,16 @@ function TreeSetColoringResult(
347406 buffer = Vector {R} (undef, nvertices)
348407
349408 return TreeSetColoringResult (
350- S, color, group, vertices_by_tree, reverse_bfs_orders, buffer
409+ S,
410+ color,
411+ group,
412+ vertices_by_tree,
413+ reverse_bfs_orders,
414+ diagonal_indices,
415+ diagonal_nzind,
416+ lower_triangle_offsets,
417+ upper_triangle_offsets,
418+ buffer,
351419 )
352420end
353421
0 commit comments