Skip to content

Commit 44fd6d3

Browse files
fix: fix flatten_equations
1 parent f37fc87 commit 44fd6d3

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,19 +1513,7 @@ function isisomorphic(sys1::AbstractODESystem, sys2::AbstractODESystem)
15131513
end
15141514

15151515
function flatten_equations(eqs)
1516-
mapreduce(vcat, eqs; init = Equation[]) do eq
1517-
islhsarr = eq.lhs isa AbstractArray || Symbolics.isarraysymbolic(eq.lhs)
1518-
isrhsarr = eq.rhs isa AbstractArray || Symbolics.isarraysymbolic(eq.rhs)
1519-
if islhsarr || isrhsarr
1520-
islhsarr && isrhsarr ||
1521-
error("LHS ($(eq.lhs)) and RHS ($(eq.rhs)) must either both be array expressions or both scalar")
1522-
size(eq.lhs) == size(eq.rhs) ||
1523-
error("Size of LHS ($(eq.lhs)) and RHS ($(eq.rhs)) must match: got $(size(eq.lhs)) and $(size(eq.rhs))")
1524-
return collect(eq.lhs) .~ collect(eq.rhs)
1525-
else
1526-
eq
1527-
end
1528-
end
1516+
mapreduce(Symbolics.scalarize, vcat, eqs; init = Equation[])
15291517
end
15301518

15311519
struct InitializationProblem{iip, specialization} end

test/odesystem.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,3 +1022,10 @@ prob2 = @test_nowarn ODEProblem(sys, [x => ones(3)], (0.0, 10.0), [p => ones(3,
10221022
sol2 = @test_nowarn solve(prob, Tsit5())
10231023

10241024
@test sol1 sol2
1025+
1026+
# Flatten equations properly
1027+
# Issue#1502
1028+
@variables x(t)[1:3] y(t)
1029+
@parameters p[1:3, 1:3]
1030+
@test_nowarn @mtkbuild sys = ODESystem([D(x) ~ p * x, D(y) ~ x' * p * x], t)
1031+
@test_nowarn ODEProblem(sys, [x => ones(3), y => 2], (0.0, 10.0), [p => ones(3, 3)])

0 commit comments

Comments
 (0)