Skip to content

Commit fd5c157

Browse files
committed
Update tests and fix infinite loop
1 parent d63043a commit fd5c157

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/systems/alias_elimination.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ function alias_eliminate_graph!(state::TransformationState, mm_orig::SparseMatri
743743
end
744744
if r === nothing
745745
isempty(reach₌) && break
746+
let stem_set = stem_set
747+
any(x -> x[2] in stem_set, reach₌) && break
748+
end
746749
# See example in the box above where D(D(D(z))) doesn't appear
747750
# in the original system and needs to added, so we can alias to it.
748751
# We do that here.
@@ -907,8 +910,9 @@ function alias_eliminate_graph!(state::TransformationState, mm_orig::SparseMatri
907910
merged_ag[v] = c => a
908911
end
909912
ag = merged_ag
910-
echelon_mm = resize_cols(echelon_mm, length(var_to_diff))
911-
mm = reduce!(echelon_mm, mm_orig, ag, size(echelon_mm, 1))
913+
@set! echelon_mm.ncols = length(var_to_diff)
914+
@set! mm_orig.ncols = length(var_to_diff)
915+
mm = reduce!(copy(echelon_mm), mm_orig, ag, size(echelon_mm, 1))
912916

913917
# Step 5: Reflect our update decisions back into the graph, and make sure
914918
# that the RHS of observable variables are defined.

src/systems/sparsematrixclil.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ function SparseMatrixCLIL(mm::AbstractMatrix)
4141
SparseMatrixCLIL(nrows, ncols, Int[1:length(row_cols);], row_cols, row_vals)
4242
end
4343

44-
function resize_cols(mm::SparseMatrixCLIL, nc)
45-
@set! mm.ncols = nc
46-
copy(mm)
47-
end
48-
4944
struct CLILVector{T, Ti} <: AbstractSparseVector{T, Ti}
5045
vec::SparseVector{T, Ti}
5146
end

test/reduction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ eqs = [a ~ D(w)
256256
@named sys = ODESystem(eqs, t, vars, [])
257257
ss = alias_elimination(sys)
258258
@test equations(ss) == [0 ~ D(D(phi)) - a, 0 ~ sin(t) - D(phi)]
259-
@test observed(ss) == [w ~ D(phi)]
259+
@test observed(ss) == [w ~ D(phi), D(w) ~ D(D(phi))]
260260

261261
@variables t x(t) y(t)
262262
D = Differential(t)

0 commit comments

Comments
 (0)