Skip to content

Commit 88e5ade

Browse files
fix: properly construct caches with non-concrete u0
1 parent 4873d37 commit 88e5ade

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/problems/sccnonlinearproblem.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,29 +234,30 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, op; eval_expression = f
234234
push!(nlfuns, f)
235235
end
236236

237+
u0_eltype = Union{}
238+
for x in u0
239+
symbolic_type(x) == NotSymbolic() || continue
240+
u0_eltype = typeof(x)
241+
break
242+
end
243+
if u0_eltype == Union{}
244+
u0_eltype = Float64
245+
end
246+
u0_eltype = float(u0_eltype)
247+
237248
if !isempty(cachetypes)
238249
templates = map(cachetypes, cachesizes) do T, n
239250
# Real refers to `eltype(u0)`
240251
if T == Real
241-
T = eltype(u0)
252+
T = u0_eltype
242253
elseif T <: Array && eltype(T) == Real
243-
T = Array{eltype(u0), ndims(T)}
254+
T = Array{u0_eltype, ndims(T)}
244255
end
245256
BufferTemplate(T, n)
246257
end
247258
p = rebuild_with_caches(p, templates...)
248259
end
249260

250-
u0_eltype = Union{}
251-
for x in u0
252-
symbolic_type(x) == NotSymbolic() || continue
253-
u0_eltype = typeof(x)
254-
break
255-
end
256-
if u0_eltype == Union{}
257-
u0_eltype = Float64
258-
end
259-
u0_eltype = float(u0_eltype)
260261
subprobs = []
261262
for (i, (f, vscc)) in enumerate(zip(nlfuns, var_sccs))
262263
_u0 = SymbolicUtils.Code.create_array(

0 commit comments

Comments
 (0)