Skip to content

Commit df4d068

Browse files
Merge pull request #3145 from AayushSabharwal/as/iip-observed
fix: fix in-place observed function generation
2 parents be393fd + 31d8273 commit df4d068

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ 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 .∘
580+
wrap_assignments(isscalar, obsexprs),
581581
expression = Val{true})[2]
582582
if !expression
583583
iip_fn = eval_or_rgf(iip_fn; eval_expression, eval_module)

test/odesystem.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,3 +1447,15 @@ 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(
1457+
sys, [p..., q], return_inplace = true)[2]
1458+
buf = zeros(3)
1459+
obsfn(buf, prob.u0, prob.p, 0.0)
1460+
@test buf [1.0, 1.0, 2.0]
1461+
end

0 commit comments

Comments
 (0)