Skip to content

Commit 047dcfd

Browse files
authored
Make sure that the alias candidate is an integer (#1364)
1 parent 09d6e86 commit 047dcfd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/systems/alias_elimination.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,12 @@ function locally_structure_simplify!(adj_row, pivot_col, ag, may_eliminate)
372372
# Note that when `nirreducible <= 1`, `alias_candidate` is uniquely
373373
# determined.
374374
if alias_candidate !== 0
375-
alias_candidate = -exactdiv(alias_candidate[1], pivot_val) => alias_candidate[2]
375+
d, r = divrem(alias_candidate[1], pivot_val)
376+
if r == 0 && (d == 1 || d == -1)
377+
alias_candidate = -d => alias_candidate[2]
378+
else
379+
return false
380+
end
376381
end
377382
ag[pivot_col] = alias_candidate
378383
zero!(adj_row)

test/nonlinearsystem.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,21 @@ end
159159

160160
# observed variable handling
161161
@variables t x(t) RHS(t)
162-
@parameters τ
162+
@parameters τ
163163
@named fol = NonlinearSystem([0 ~ (1 - x)/τ], [x], [τ]; observed=[RHS ~ (1 - x)/τ])
164164
@test isequal(RHS, @nonamespace fol.RHS)
165165
RHS2 = RHS
166166
@unpack RHS = fol
167167
@test isequal(RHS, RHS2)
168+
169+
# issue #1358
170+
@variables t
171+
@variables v1(t) v2(t) i1(t) i2(t)
172+
eq = [
173+
v1 ~ sin(2pi*t)
174+
v1 - v2 ~ i1
175+
v2 ~ i2
176+
i1 ~ i2
177+
]
178+
@named sys = ODESystem(eq)
179+
@test length(equations(structural_simplify(sys))) == 0

0 commit comments

Comments
 (0)