Skip to content

Commit

Permalink
bugfix for remove_zero_valued_subgraphs!
Browse files Browse the repository at this point in the history
  • Loading branch information
houpc committed Oct 30, 2024
1 parent 79f254b commit 0d3ce5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/computational_graph/transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ function remove_zero_valued_subgraphs!(g::AbstractGraph)
mask_zeros = findall(x -> x != zero(x), subg_fac)
if isempty(mask_zeros)
mask_zeros = [1] # retain eldest(g) if all subfactors are zero
else
if g.operator == Prod
idx = findfirst(x -> x==zero(x), subg_fac)
if !isnothing(idx)
append!(mask_zeros, idx)
end
end
end
set_subgraphs!(g, subg[mask_zeros])
set_subgraph_factors!(g, subg_fac[mask_zeros])
Expand Down
2 changes: 2 additions & 0 deletions src/computational_graph/tree_properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ end
function has_zero_subfactors(g::AbstractGraph)
if isleaf(g)
return false # convention: subgraph_factors = [] ⟹ subfactorless = false
elseif g.operator == Prod && 0 in subgraph_factors(g)
return true
else
return iszero(subgraph_factors(g))
end
Expand Down

0 comments on commit 0d3ce5e

Please sign in to comment.