Skip to content

Commit 6c73af9

Browse files
committed
Remember to mark the predecessors as processed as well to avoid cycles
Fix #1751
1 parent d6195ee commit 6c73af9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/systems/alias_elimination.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ function simple_aliases!(ag, graph, var_to_diff, mm_orig, irreducibles = ())
605605
return mm
606606
end
607607

608+
function mark_processed!(processed, var_to_diff, v)
609+
diff_to_var = invview(var_to_diff)
610+
processed[v] = true
611+
while (v = diff_to_var[v]) !== nothing
612+
processed[v] = true
613+
end
614+
return nothing
615+
end
616+
608617
function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
609618
# Step 1: Perform bareiss factorization on the adjacency matrix of the linear
610619
# subsystem of the system we're interested in.
@@ -674,7 +683,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
674683
@assert length(level_to_var) == level
675684
push!(level_to_var, v)
676685
end
677-
processed[v] = true
686+
mark_processed!(processed, var_to_diff, v)
678687
current_coeff_level[] = (coeff, level + 1)
679688
end
680689
end
@@ -684,7 +693,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
684693
max_lv = max(max_lv, lv)
685694
v = nodevalue(t)
686695
iszero(v) && continue
687-
processed[v] = true
696+
mark_processed!(processed, var_to_diff, v)
688697
v == r && continue
689698
if lv < length(level_to_var)
690699
if level_to_var[lv + 1] == v

0 commit comments

Comments
 (0)