Skip to content

Commit f75c944

Browse files
committed
Batch observed function eval if possible
1 parent 9e92fc6 commit f75c944

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/solutions/ode_solutions.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function (sol::AbstractODESolution)(t::Number, ::Type{deriv}, idxs::AbstractVect
203203
all(!isequal(NotSymbolic()), symbolic_type.(idxs)) ||
204204
error("Incorrect specification of `idxs`")
205205
interp_sol = augment(sol.interp([t], nothing, deriv, sol.prob.p, continuity), sol)
206-
[is_parameter(sol, idx) ? getp(sol, idx)(sol) : first(interp_sol[idx]) for idx in idxs]
206+
first(interp_sol[idxs])
207207
end
208208

209209
function (sol::AbstractODESolution)(t::AbstractVector{<:Number}, ::Type{deriv}, idxs,
@@ -224,8 +224,9 @@ function (sol::AbstractODESolution)(t::AbstractVector{<:Number}, ::Type{deriv},
224224
error("Incorrect specification of `idxs`")
225225
interp_sol = augment(sol.interp(t, nothing, deriv, sol.prob.p, continuity), sol)
226226
p = hasproperty(sol.prob, :p) ? sol.prob.p : nothing
227+
indexed_sol = interp_sol[idxs]
227228
return DiffEqArray(
228-
[[interp_sol[idx][i] for idx in idxs] for i in 1:length(t)], t, p, sol)
229+
[indexed_sol[i] for i in 1:length(t)], t, p, sol)
229230
end
230231

231232
function build_solution(prob::Union{AbstractODEProblem, AbstractDDEProblem},

src/solutions/solution_interface.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,18 @@ function solplot_vecs_and_labels(dims, vars, plott, sol, plot_analytic,
436436
plot_vecs = []
437437
labels = String[]
438438
varsyms = variable_symbols(sol)
439+
batch_symbolic_vars = []
440+
for x in vars
441+
for j in 2:length(x)
442+
if (x[j] isa Integer && x[j] == 0) || isequal(x[j], getindepsym_defaultt(sol))
443+
else
444+
push!(batch_symbolic_vars, x[j])
445+
end
446+
end
447+
end
448+
batch_symbolic_vars = identity.(batch_symbolic_vars)
449+
indexed_solution = sol(plott; idxs = batch_symbolic_vars)
450+
idxx = 0
439451
for x in vars
440452
tmp = []
441453
strs = String[]
@@ -444,7 +456,8 @@ function solplot_vecs_and_labels(dims, vars, plott, sol, plot_analytic,
444456
push!(tmp, plott)
445457
push!(strs, "t")
446458
else
447-
push!(tmp, sol(plott; idxs = x[j]))
459+
idxx += 1
460+
push!(tmp, indexed_solution[idxx, :])
448461
if !isempty(varsyms) && x[j] isa Integer
449462
push!(strs, String(getname(varsyms[x[j]])))
450463
elseif hasname(x[j])

0 commit comments

Comments
 (0)