Skip to content

Commit

Permalink
refactor: move type-pirated function from BoundaryValueDiffEq here
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed May 21, 2024
1 parent e7c5566 commit f296f97
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,26 @@ function solution_new_tslocation(sol::ODESolution{T, N}, tslocation) where {T, N
sol.original)
end

function solution_new_original_retcode(
sol::ODESolution{T, N}, original, retcode, resid) where {T, N}
return ODESolution{T, N}(
sol.u, sol.u_analytic, sol.errors, sol.t, sol.k, sol.discretes, sol.prob, sol.alg,
sol.interp, sol.dense, sol.tslocation, sol.stats, sol.alg_choice, retcode, resid,
original)
end

function solution_slice(sol::ODESolution{T, N}, I) where {T, N}
new_t = sol.t[I]
if sol.discretes === nothing
discretes = nothing
else
mint, maxt = extrema(new_t)
disc_mask = mint .<= sol.discretes.t .<= maxt
discretes = sol.discretes[:, disc_mask]
masked_discs = map(sol.discretes) do disc
mini = searchsortedfirst(disc.t, mint)
maxi = searchsortedlast(disc.t, maxt)
disc[mini:maxi]
end
discretes = ParameterTimeseriesCollection(masked_discs, parameter_values(sol.discretes))
end
ODESolution{T, N}(sol.u[I],
sol.u_analytic === nothing ? nothing : sol.u_analytic[I],
Expand Down

0 comments on commit f296f97

Please sign in to comment.