@@ -309,6 +309,7 @@ struct StarSetColoringResult{
309309 color:: CT
310310 group:: GT
311311 compressed_indices:: VT
312+ decompression_uplo:: Symbol
312313 additional_info:: A
313314end
314315
@@ -317,43 +318,58 @@ function StarSetColoringResult(
317318 ag:: AdjacencyGraph{T} ,
318319 color:: Vector{<:Integer} ,
319320 star_set:: StarSet{<:Integer} ,
321+ decompression_uplo:: Symbol ,
320322) where {T<: Integer }
321323 group = group_by_color (T, color)
322- compressed_indices = star_csc_indices (ag, color, star_set)
323- return StarSetColoringResult (A, ag, color, group, compressed_indices, nothing )
324+ compressed_indices = star_csc_indices (ag, color, star_set, decompression_uplo)
325+ return StarSetColoringResult (
326+ A, ag, color, group, compressed_indices, decompression_uplo, nothing
327+ )
324328end
325329
326330function star_csc_indices (
327- ag:: AdjacencyGraph{T} , color:: Vector{<:Integer} , star_set
331+ ag:: AdjacencyGraph{T} ,
332+ color:: Vector{<:Integer} ,
333+ star_set:: StarSet{<:Integer} ,
334+ decompression_uplo:: Symbol ,
328335) where {T}
329336 (; star, hub) = star_set
330337 S = pattern (ag)
331338 edge_to_index = edge_indices (ag)
332339 n = S. n
333340 rvS = rowvals (S)
334- compressed_indices = zeros (T, nnz (S)) # needs to be independent from the storage in the graph, in case the graph gets reused
341+ nb_indices = nnz (S)
342+ if decompression_uplo != :F
343+ nb_indices = nb_edges (ag) + ag. nb_self_loops
344+ end
345+ compressed_indices = zeros (T, nb_indices) # needs to be independent from the storage in the graph, in case the graph gets reused
346+ l = 0
335347 for j in axes (S, 2 )
336348 for k in nzrange (S, j)
337349 i = rvS[k]
338350 if i == j
339351 # diagonal coefficients
352+ l += 1
340353 c = color[i]
341- compressed_indices[k ] = (c - 1 ) * n + i
354+ compressed_indices[l ] = (c - 1 ) * n + i
342355 else
343- # off-diagonal coefficients
344- index_ij = edge_to_index[k]
345- s = star[index_ij]
346- h = abs (hub[s])
347-
348- # Assign the non-hub vertex (spoke) to the correct position in spokes
349- if i == h
350- # i is the hub and j is the spoke
351- c = color[i]
352- compressed_indices[k] = (c - 1 ) * n + j
353- else # j == h
354- # j is the hub and i is the spoke
355- c = color[j]
356- compressed_indices[k] = (c - 1 ) * n + i
356+ if in_triangle (i, j, decompression_uplo)
357+ # off-diagonal coefficients
358+ l += 1
359+ index_ij = edge_to_index[k]
360+ s = star[index_ij]
361+ h = abs (hub[s])
362+
363+ # Assign the non-hub vertex (spoke) to the correct position in spokes
364+ if i == h
365+ # i is the hub and j is the spoke
366+ c = color[i]
367+ compressed_indices[l] = (c - 1 ) * n + j
368+ else # j == h
369+ # j is the hub and i is the spoke
370+ c = color[j]
371+ compressed_indices[l] = (c - 1 ) * n + i
372+ end
357373 end
358374 end
359375 end
@@ -391,6 +407,7 @@ struct TreeSetColoringResult{
391407 lower_triangle_offsets:: Vector{T}
392408 upper_triangle_offsets:: Vector{T}
393409 buffer:: Vector{R}
410+ decompression_uplo:: Symbol
394411end
395412
396413function TreeSetColoringResult (
@@ -399,6 +416,7 @@ function TreeSetColoringResult(
399416 color:: Vector{<:Integer} ,
400417 tree_set:: TreeSet{<:Integer} ,
401418 decompression_eltype:: Type{R} ,
419+ decompression_uplo:: Symbol ,
402420) where {T<: Integer ,R}
403421 (; reverse_bfs_orders, tree_edge_indices, nt) = tree_set
404422 (; S, nb_self_loops) = ag
@@ -408,7 +426,7 @@ function TreeSetColoringResult(
408426
409427 # Vector for the decompression of the diagonal coefficients
410428 diagonal_indices = Vector {T} (undef, nb_self_loops)
411- diagonal_nzind = Vector {T} (undef, nb_self_loops)
429+ diagonal_nzind = (decompression_uplo == :F ) ? Vector {T} (undef, nb_self_loops) : T[]
412430
413431 if ! augmented_graph (ag)
414432 l = 0
@@ -418,16 +436,18 @@ function TreeSetColoringResult(
418436 if i == j
419437 l += 1
420438 diagonal_indices[l] = i
421- diagonal_nzind[l] = k
439+ if decompression_uplo == :F
440+ diagonal_nzind[l] = k
441+ end
422442 end
423443 end
424444 end
425445 end
426446
427447 # Vectors for the decompression of the off-diagonal coefficients
428448 nedges = nb_edges (ag)
429- lower_triangle_offsets = Vector {T} (undef, nedges)
430- upper_triangle_offsets = Vector {T} (undef, nedges)
449+ lower_triangle_offsets = decompression_uplo == :U ? T[] : Vector {T} (undef, nedges)
450+ upper_triangle_offsets = decompression_uplo == :L ? T[] : Vector {T} (undef, nedges)
431451
432452 # Index in lower_triangle_offsets and upper_triangle_offsets
433453 index_offsets = 0
@@ -451,21 +471,29 @@ function TreeSetColoringResult(
451471 if in_triangle (i, j, :L )
452472 # uplo = :L or uplo = :F
453473 # S[i,j] is stored at index_ij = (S.colptr[j+1] - offset_L) in S.nzval
454- lower_triangle_offsets[index_offsets] = length (col_j) - searchsortedfirst (col_j, i) + 1
474+ if decompression_uplo != :U
475+ lower_triangle_offsets[index_offsets] = length (col_j) - searchsortedfirst (col_j, i) + 1
476+ end
455477
456478 # uplo = :U or uplo = :F
457479 # S[j,i] is stored at index_ji = (S.colptr[i] + offset_U) in S.nzval
458- upper_triangle_offsets[index_offsets] = searchsortedfirst (col_i, j):: Int - 1
480+ if decompression_uplo != :L
481+ upper_triangle_offsets[index_offsets] = searchsortedfirst (col_i, j):: Int - 1
482+ end
459483
460484 # S[i,j] is in the upper triangular part of S
461485 else
462486 # uplo = :U or uplo = :F
463487 # S[i,j] is stored at index_ij = (S.colptr[j] + offset_U) in S.nzval
464- upper_triangle_offsets[index_offsets] = searchsortedfirst (col_j, i):: Int - 1
488+ if decompression_uplo != :L
489+ upper_triangle_offsets[index_offsets] = searchsortedfirst (col_j, i):: Int - 1
490+ end
465491
466492 # uplo = :L or uplo = :F
467493 # S[j,i] is stored at index_ji = (S.colptr[i+1] - offset_L) in S.nzval
468- lower_triangle_offsets[index_offsets] = length (col_i) - searchsortedfirst (col_i, j) + 1
494+ if decompression_uplo != :U
495+ lower_triangle_offsets[index_offsets] = length (col_i) - searchsortedfirst (col_i, j) + 1
496+ end
469497 end
470498 # ! format: on
471499 end
@@ -488,6 +516,7 @@ function TreeSetColoringResult(
488516 lower_triangle_offsets,
489517 upper_triangle_offsets,
490518 buffer,
519+ decompression_uplo,
491520 )
492521end
493522
0 commit comments