Skip to content

Commit aa68a71

Browse files
committed
Fix the propagation algorithm
1 parent 0cbf493 commit aa68a71

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/structural_transformation/partial_state_selection.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ function dummy_derivative_graph!(state::TransformationState, jac = nothing;
179179
else
180180
ag = AliasGraph(mm, ndsts(state.structure.graph))
181181
end
182-
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority, ag, mm, log)
182+
dummy_derivative_graph!(
183+
state.structure, var_eq_matching, jac, state_priority, ag, mm, log)
183184
end
184185

185186
struct DummyDerivativeSummary
@@ -209,7 +210,6 @@ end
209210

210211
function extended_state_priority(state_priority, var_to_diff, ag::AliasGraph)
211212
sp = map(state_priority, 1:length(var_to_diff))
212-
diff_to_var = invview(var_to_diff)
213213
prop_graph = SimpleDiGraph{Int}(ag)
214214
for (v, dv) in enumerate(var_to_diff)
215215
dv isa Int && add_edge!(prop_graph, v, dv)
@@ -228,16 +228,17 @@ function prop_state_priority!(sp, graph)
228228
visited = BitSet()
229229
function visit!(sp, graph, v)
230230
push!(visited, v)
231-
for n in inneighbors(graph, v)
232-
n in visited && continue
233-
visit!(sp, graph, n)
234-
end
235231
for n in outneighbors(graph, v)
232+
n in visited && continue
236233
sp[n] = maxabs(sp[n], sp[v])
234+
visit!(sp, graph, n)
237235
end
238236
end
239237
for v in vertices(graph)
240-
visit!(sp, graph, v)
238+
if all(x -> iszero(sp[v]), inneighbors(graph, v))
239+
visit!(sp, graph, v)
240+
empty!(visited)
241+
end
241242
end
242243
sp
243244
end

src/systems/alias_elimination.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ function AliasGraph(mm::SparseMatrixCLIL, nv::Int)
401401
end
402402
isneg(ag::AliasGraph, a, b) = (a, b) in ag.neg_edge
403403
for f in [:dst, :edges, :edgetype, :has_edge, :has_vertex,
404-
:inneighbors, :is_directed, :ne, :nv, :outneighbors,
405-
:src, :vertices]
404+
:inneighbors, :is_directed, :ne, :nv, :outneighbors,
405+
:src, :vertices]
406406
@eval Graphs.$f(ag::AliasGraph) = Graphs.$f(ag.graph)
407407
end
408408

0 commit comments

Comments
 (0)