Skip to content

Commit deb821c

Browse files
Merge pull request #747 from SciML/myb/u0map
Handle u0 with UnionAll eltype
2 parents 1aa2399 + 910db88 commit deb821c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function DiffEqBase.ODEProblem{iip}(sys::AbstractODESystem,u0map,tspan,
266266
ps = parameters(sys)
267267
u0map′ = lower_mapnames(u0map,sys.iv)
268268
u0 = varmap_to_vars(u0map′,dvs)
269-
269+
270270
if !(parammap isa DiffEqBase.NullParameters)
271271
parammap′ = lower_mapnames(parammap)
272272
p = varmap_to_vars(parammap′,ps)

src/variables.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ function TreeViews.treelabel(io::IO,x::Variable,
206206
end
207207

208208
"""
209-
varmap_to_vars(varmap,varlist)
209+
varmap_to_vars(varmap,varlist)
210210
211211
Takes a list of pairs of variables=>values and an ordered list of variables and
212212
creates the array of values in the correct order
213213
"""
214-
function varmap_to_vars(varmap::AbstractArray{Pair{T,S}},varlist) where {T,S}
215-
out = similar(varmap,S)
214+
function varmap_to_vars(varmap::AbstractArray{<:Pair},varlist)
215+
out = map(zero last, varmap)
216216
for (ivar, ival) in varmap
217217
j = findfirst(isequal(ivar),varlist)
218218
if isnothing(j)
@@ -228,7 +228,8 @@ function varmap_to_vars(varmap::AbstractArray{Pair{T,S}},varlist) where {T,S}
228228
ArrayInterface.restructure(varmap,out)
229229
end
230230

231-
function varmap_to_vars(varmap::NTuple{N,Pair{T,S}},varlist) where {N,T,S}
231+
function varmap_to_vars(varmap::NTuple{N,<:Pair},varlist) where {N}
232+
S = Base.promote_typeof(map(zero last, varmap)...)
232233
out = MArray{Tuple{N},S}(undef)
233234
for (ivar, ival) in varmap
234235
j = findfirst(isequal(ivar),varlist)

test/odesystem.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ eqs = [D(y₁) ~ -k₁*y₁+k₃*y₂*y₃,
186186
0 ~ y₁ + y₂ + y₃ - 1,
187187
D(y₂) ~ k₁*y₁-k₂*y₂^2-k₃*y₂*y₃]
188188
sys = ODESystem(eqs)
189-
u0 = [y₁ => 1.0,
190-
y₂ => 0.0,
191-
y₃ => 0.0]
189+
u0 = Pair[]
190+
push!(u0, y₁ => 1.0)
191+
push!(u0, y₂ => 0.0)
192+
push!(u0, y₃ => 0.0)
192193
p = [k₁ => 0.04,
193194
k₂ => 3e7,
194195
k₃ => 1e4]

0 commit comments

Comments
 (0)