Skip to content

Commit 93d13fb

Browse files
committed
Disable early return optimization in promote_to_concrete()
1 parent 910f7de commit 93d13fb

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/utils.jl

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -663,42 +663,43 @@ function promote_to_concrete(vs; tofloat = true, use_union = true)
663663
vs = Any[vs...]
664664
end
665665
T = eltype(vs)
666-
if Base.isconcretetype(T) && (!tofloat || T === float(T)) # nothing to do
667-
return vs
668-
else
669-
sym_vs = filter(x -> SymbolicUtils.issym(x) || SymbolicUtils.iscall(x), vs)
670-
isempty(sym_vs) || throw_missingvars_in_sys(sym_vs)
671-
672-
C = nothing
673-
for v in vs
674-
E = typeof(v)
675-
if E <: Number
676-
if tofloat
677-
E = float(E)
678-
end
679-
end
680-
if C === nothing
681-
C = E
682-
end
683-
if use_union
684-
C = Union{C, E}
685-
else
686-
@assert C==E "`promote_to_concrete` can't make type $E uniform with $C"
687-
C = E
688-
end
689-
end
690666

691-
y = similar(vs, C)
692-
for i in eachindex(vs)
693-
if (vs[i] isa Number) & tofloat
694-
y[i] = float(vs[i]) #needed because copyto! can't convert Int to Float automatically
695-
else
696-
y[i] = vs[i]
667+
# return early if there is nothing to do
668+
# TODO: reenable after it was disabled to fix missing errors in https://github.com/SciML/ModelingToolkit.jl/issues/2873
669+
#Base.isconcretetype(T) && (!tofloat || T === float(T)) && return vs
670+
671+
sym_vs = filter(x -> SymbolicUtils.issym(x) || SymbolicUtils.iscall(x), vs)
672+
isempty(sym_vs) || throw_missingvars_in_sys(sym_vs)
673+
674+
C = nothing
675+
for v in vs
676+
E = typeof(v)
677+
if E <: Number
678+
if tofloat
679+
E = float(E)
697680
end
698681
end
682+
if C === nothing
683+
C = E
684+
end
685+
if use_union
686+
C = Union{C, E}
687+
else
688+
@assert C==E "`promote_to_concrete` can't make type $E uniform with $C"
689+
C = E
690+
end
691+
end
699692

700-
return y
693+
y = similar(vs, C)
694+
for i in eachindex(vs)
695+
if (vs[i] isa Number) & tofloat
696+
y[i] = float(vs[i]) #needed because copyto! can't convert Int to Float automatically
697+
else
698+
y[i] = vs[i]
699+
end
701700
end
701+
702+
return y
702703
end
703704

704705
struct BitDict <: AbstractDict{Int, Int}

0 commit comments

Comments
 (0)