@@ -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,19 +556,13 @@ 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]
587568 val = compute_tree_value (val_is_star_k, B, i, j, color, buffer_right_type)
@@ -607,7 +588,6 @@ function decompress!(
607588 ag,
608589 color,
609590 reverse_bfs_orders,
610- is_star,
611591 diagonal_indices,
612592 diagonal_nzind,
613593 lower_triangle_offsets,
@@ -652,23 +632,18 @@ function decompress!(
652632
653633 # Recover the off-diagonal coefficients of A
654634 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)
635+ # Reset the buffer to zero for all vertices in a tree (except the root)
636+ for (vertex, _) in reverse_bfs_orders[k]
637+ buffer_right_type[vertex] = zero (R)
667638 end
639+ # Reset the buffer to zero for the root vertex
640+ (_, root) = reverse_bfs_orders[k][end ]
641+ buffer_right_type[root] = zero (R)
668642
669643 for (i, j) in reverse_bfs_orders[k]
670644 counter += 1
671- compute_tree_value (val_is_star_k, B, i, j, color, buffer_right_type)
645+ val = B[i, color[j]] - buffer[i]
646+ buffer[j] = buffer[j] + val
672647
673648 # ! format: off
674649 # A[i,j] is in the lower triangular part of A
0 commit comments