@@ -530,29 +530,16 @@ end
530530
531531# # TreeSetColoringResult
532532
533- function compute_tree_value (is_star:: Val{false} , B:: AbstractMatrix , i:: Integer , j:: Integer , color:: AbstractVector{<:Integer} , buffer:: AbstractVector{<:Real} )
534- # The tree is not a star
535- val = B[i, color[j]] - buffer[i]
536- buffer[j] = buffer[j] + val
537- return val
538- end
539-
540- function compute_tree_value (is_star:: Val{true} , B:: AbstractMatrix , i:: Integer , j:: Integer , color:: AbstractVector{<:Integer} , buffer:: AbstractVector{<:Real} )
541- # The tree is a star (trivial or non-trivial)
542- val = B[i, color[j]]
543- return val
544- end
545-
546533function decompress! (
547534 A:: AbstractMatrix , B:: AbstractMatrix , result:: TreeSetColoringResult , uplo:: Symbol = :F
548535)
549- (; ag, color, reverse_bfs_orders, is_star, buffer) = result
536+ (; ag, color, reverse_bfs_orders, buffer) = result
550537 (; S) = ag
551538 uplo == :F && check_same_pattern (A, S)
552539 R = eltype (A)
553540 fill! (A, zero (R))
554541
555- if eltype (buffer) == R || isempty (buffer)
542+ if eltype (buffer) == R
556543 buffer_right_type = buffer
557544 else
558545 buffer_right_type = similar (buffer, R)
@@ -569,22 +556,17 @@ function decompress!(
569556
570557 # Recover the off-diagonal coefficients of A
571558 for k in eachindex (reverse_bfs_orders)
572- is_star_k = is_star[k]
573- val_is_star_k = Val (is_star_k)
574-
575- # We need the buffer only when the tree is not a star (trivial or non-trivial)
576- if ! is_star_k
577- # Reset the buffer to zero for all vertices in a tree (except the root)
578- for (vertex, _) in reverse_bfs_orders[k]
579- buffer_right_type[vertex] = zero (R)
580- end
581- # Reset the buffer to zero for the root vertex
582- (_, root) = reverse_bfs_orders[k][end ]
583- buffer_right_type[root] = zero (R)
559+ # Reset the buffer to zero for all vertices in a tree (except the root)
560+ for (vertex, _) in reverse_bfs_orders[k]
561+ buffer_right_type[vertex] = zero (R)
584562 end
563+ # Reset the buffer to zero for the root vertex
564+ (_, root) = reverse_bfs_orders[k][end ]
565+ buffer_right_type[root] = zero (R)
585566
586567 for (i, j) in reverse_bfs_orders[k]
587- val = compute_tree_value (val_is_star_k, B, i, j, color, buffer_right_type)
568+ val = B[i, color[j]] - buffer_right_type[i]
569+ buffer_right_type[j] = buffer_right_type[j] + val
588570
589571 if in_triangle (i, j, uplo)
590572 A[i, j] = val
@@ -607,7 +589,6 @@ function decompress!(
607589 ag,
608590 color,
609591 reverse_bfs_orders,
610- is_star,
611592 diagonal_indices,
612593 diagonal_nzind,
613594 lower_triangle_offsets,
@@ -619,7 +600,7 @@ function decompress!(
619600 nzA = nonzeros (A)
620601 uplo == :F && check_same_pattern (A, S)
621602
622- if eltype (buffer) == R || isempty (buffer)
603+ if eltype (buffer) == R
623604 buffer_right_type = buffer
624605 else
625606 buffer_right_type = similar (buffer, R)
@@ -652,23 +633,18 @@ function decompress!(
652633
653634 # Recover the off-diagonal coefficients of A
654635 for k in eachindex (reverse_bfs_orders)
655- is_star_k = is_star[k]
656- val_is_star_k = Val (is_star_k)
657-
658- # We need the buffer only when the tree is not a star (trivial or non-trivial)
659- if ! is_star_k
660- # Reset the buffer to zero for all vertices in a tree (except the root)
661- for (vertex, _) in reverse_bfs_orders[k]
662- buffer_right_type[vertex] = zero (R)
663- end
664- # Reset the buffer to zero for the root vertex
665- (_, root) = reverse_bfs_orders[k][end ]
666- buffer_right_type[root] = zero (R)
636+ # Reset the buffer to zero for all vertices in a tree (except the root)
637+ for (vertex, _) in reverse_bfs_orders[k]
638+ buffer_right_type[vertex] = zero (R)
667639 end
640+ # Reset the buffer to zero for the root vertex
641+ (_, root) = reverse_bfs_orders[k][end ]
642+ buffer_right_type[root] = zero (R)
668643
669644 for (i, j) in reverse_bfs_orders[k]
670645 counter += 1
671- compute_tree_value (val_is_star_k, B, i, j, color, buffer_right_type)
646+ val = B[i, color[j]] - buffer_right_type[i]
647+ buffer_right_type[j] = buffer_right_type[j] + val
672648
673649 # ! format: off
674650 # A[i,j] is in the lower triangular part of A
0 commit comments