Skip to content

Commit 1275c9d

Browse files
committed
Compute Jacobian sparsity when u0 is not provided
1 parent 9ae858e commit 1275c9d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,22 @@ function DiffEqBase.ODEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
217217
end
218218
end
219219

220-
uElType = eltype(u0)
220+
jac_prototype = if sparse
221+
uElType = u0 === nothing ? Float64 : eltype(u0)
222+
if jac
223+
similar(calculate_jacobian(sys, sparse=sparse), uElType)
224+
else
225+
similar(jacobian_sparsity(sys), uElType)
226+
end
227+
else
228+
nothing
229+
end
221230
ODEFunction{iip}(
222231
f,
223232
jac = _jac === nothing ? nothing : _jac,
224233
tgrad = _tgrad === nothing ? nothing : _tgrad,
225234
mass_matrix = _M,
226-
jac_prototype = (!isnothing(u0) && sparse) ? (!jac ? similar(jacobian_sparsity(sys),uElType) : SparseArrays.sparse(similar(get_jac(sys)[],uElType))) : nothing,
235+
jac_prototype = jac_prototype,
227236
syms = Symbol.(states(sys)),
228237
indepsym = Symbol(independent_variable(sys)),
229238
observed = observedfun,

0 commit comments

Comments
 (0)