@@ -570,7 +570,9 @@ function simple_aliases!(ag, graph, var_to_diff, mm_orig, irreducibles = ())
570
570
irreducibles)
571
571
572
572
# Step 2: Simplify the system using the Bareiss factorization
573
- for v in setdiff (solvable_variables, @view pivots[1 : rank1])
573
+ rk1vars = BitSet (@view pivots[1 : rank1])
574
+ for v in solvable_variables
575
+ v in rk1vars && continue
574
576
ag[v] = 0
575
577
end
576
578
@@ -699,6 +701,16 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
699
701
end
700
702
for (i, v) in enumerate (level_to_var)
701
703
_alias = get (ag, v, nothing )
704
+ v_eqs = 𝑑neighbors (graph, v)
705
+ # if an irreducible appears in only one equation, we need to make
706
+ # sure that the other variables don't get eliminated
707
+ if length (v_eqs) == 1
708
+ eq = v_eqs[1 ]
709
+ for av in 𝑠neighbors (graph, eq)
710
+ push! (irreducibles, av)
711
+ end
712
+ ag[v] = nothing
713
+ end
702
714
push! (irreducibles, v)
703
715
if _alias != = nothing && iszero (_alias[1 ]) && i < length (level_to_var)
704
716
# we have `x = 0`
@@ -709,7 +721,8 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
709
721
end
710
722
if nlevels < (new_nlevels = length (level_to_var))
711
723
for i in (nlevels + 1 ): new_nlevels
712
- var_to_diff[level_to_var[i - 1 ]] = level_to_var[i]
724
+ li = level_to_var[i]
725
+ var_to_diff[level_to_var[i - 1 ]] = li
713
726
push! (updated_diff_vars, level_to_var[i - 1 ])
714
727
end
715
728
end
0 commit comments