Skip to content

Commit f9c7083

Browse files
committed
fix params
1 parent 6b1e01d commit f9c7083

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
4949
ParallelForm, SerialForm, MultithreadedForm, build_function,
5050
unflatten_long_ops, rhss, lhss, prettify_expr, gradient,
5151
jacobian, hessian, derivative, sparsejacobian, sparsehessian,
52-
substituter
52+
substituter, scalarize
5353

5454
import DiffEqBase: @add_kwonly
5555

src/parameters.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ Maps the variable to a state.
2121
tovar(s::Symbolic) = setmetadata(s, MTKParameterCtx, false)
2222
tovar(s::Num) = Num(tovar(value(s)))
2323

24+
function recurse_and_apply(f, x)
25+
if symtype(x) <: AbstractArray
26+
getindex_posthook(x) do r,x,i...
27+
recurse_and_apply(f, r)
28+
end
29+
else
30+
f(x)
31+
end
32+
end
33+
2434
"""
2535
$(SIGNATURES)
2636
@@ -31,6 +41,6 @@ macro parameters(xs...)
3141
Real,
3242
xs,
3343
x -> x isa AbstractArray ?
34-
Symbolics.getindex_posthook((a, b...)->toparam(a), x) : toparam(x)
44+
Symbolics.recurse_and_apply(toparam, x) : toparam(x),
3545
) |> esc
3646
end

src/systems/diffeqs/odesystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ function ODESystem(
8585
defaults=_merge(Dict(default_u0), Dict(default_p)),
8686
connection_type=nothing,
8787
)
88-
iv′ = value(iv)
89-
dvs′ = value.(collect(dvs))
90-
ps′ = value.(collect(ps))
88+
iv′ = value(scalarize(iv))
89+
dvs′ = value.(scalarize(dvs))
90+
ps′ = value.(scalarize(ps))
9191

9292
if !(isempty(default_u0) && isempty(default_p))
9393
Base.depwarn("`default_u0` and `default_p` are deprecated. Use `defaults` instead.", :ODESystem, force=true)

0 commit comments

Comments
 (0)