Skip to content

Commit 20e6796

Browse files
fix: fix in-place observed function generation
1 parent 9b439b7 commit 20e6796

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,7 @@ function build_explicit_observed_function(sys, ts;
576576
iip_fn = build_function(ts,
577577
args...;
578578
postprocess_fbody = pre,
579-
wrap_code = array_wrapper .∘ wrap_assignments(isscalar, obsexprs) .∘
580-
mtkparams_wrapper,
579+
wrap_code = mtkparams_wrapper .∘ array_wrapper .∘ wrap_assignments(isscalar, obsexprs),
581580
expression = Val{true})[2]
582581
if !expression
583582
iip_fn = eval_or_rgf(iip_fn; eval_expression, eval_module)

test/odesystem.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,3 +1447,14 @@ end
14471447
@parameters p
14481448
@test_nowarn ODESystem(Equation[], t; parameter_dependencies = [p ~ 1.0], name = :a)
14491449
end
1450+
1451+
@testset "Inplace observed" begin
1452+
@variables x(t)
1453+
@parameters p[1:2] q
1454+
@mtkbuild sys = ODESystem(D(x) ~ sum(p) * x + q * t, t)
1455+
prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [p => ones(2), q => 2])
1456+
obsfn = ModelingToolkit.build_explicit_observed_function(sys, [p..., q], return_inplace = true)[2]
1457+
buf = zeros(3)
1458+
obsfn(buf, prob.u0, prob.p, 0.0)
1459+
@test buf [1.0, 1.0, 2.0]
1460+
end

0 commit comments

Comments
 (0)