Skip to content

Commit adfd0f2

Browse files
authored
Merge pull request #1567 from SciML/myb/union_array
Support array of arrays in `varmap_to_vars `
2 parents 7c7b98d + 38a6f54 commit adfd0f2

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/utils.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,31 @@ function promote_to_concrete(vs; tofloat=true, use_union=false)
481481
vs
482482
else
483483
C = typeof(first(vs))
484-
has_int = false
485484
I = Int8
485+
has_int = false
486+
has_array = false
487+
array_T = nothing
486488
for v in vs
489+
if v isa AbstractArray
490+
has_array = true
491+
array_T = typeof(v)
492+
end
487493
E = eltype(v)
488494
C = promote_type(C, E)
489495
if E <: Integer
490496
has_int = true
491497
I = promote_type(I, E)
492498
end
493499
end
494-
if tofloat
500+
if tofloat && !has_array
495501
C = float(C)
496-
elseif use_union && has_int && C !== I
497-
C = Union{C, I}
502+
elseif has_array || (use_union && has_int && C !== I)
503+
if has_array
504+
C = Union{C, array_T}
505+
end
506+
if has_int
507+
C = Union{C, I}
508+
end
498509
return copyto!(similar(vs, C), vs)
499510
end
500511
convert.(C, vs)

test/odesystem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,12 @@ let
746746
@named sys = ODESystem(eqs, t, vars, pars)
747747
@test_throws ModelingToolkit.ExtraEquationsSystemException structural_simplify(sys)
748748
end
749+
750+
# 1561
751+
let
752+
vars = @variables x y
753+
arr = ModelingToolkit.varmap_to_vars([x => 0.0, y => [0.0, 1.0]], vars) #error
754+
sol = Union{Float64, Vector{Float64}}[0.0, [0.0, 1.0]]
755+
@test arr == sol
756+
@test typeof(arr) == typeof(sol)
757+
end

0 commit comments

Comments
 (0)