Skip to content

Commit db715ee

Browse files
Merge pull request SciML#2288 from oscardssmith/os/fix-is_constant_cache
fix `is_constant_cache(::DefaultCache)
2 parents a8beedb + fd1dc5a commit db715ee

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/cache_utils.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
is_constant_cache(cache::OrdinaryDiffEqConstantCache) = true
2-
is_constant_cache(cache::OrdinaryDiffEqCache) = false
1+
is_constant_cache(::OrdinaryDiffEqConstantCache) = true
2+
is_constant_cache(::OrdinaryDiffEqCache) = false
33
is_constant_cache(cache::CompositeCache) = is_constant_cache(cache.caches[1])
4+
is_constant_cache(::DefaultCache{Cache1}) where {Cache1} = Cache1 <: OrdinaryDiffEqConstantCache
45

56
function DiffEqBase.unwrap_cache(integrator::ODEIntegrator, is_stiff)
67
alg = integrator.alg
@@ -22,6 +23,8 @@ function DiffEqBase.unwrap_cache(integrator::ODEIntegrator, is_stiff)
2223
return cache.cache5
2324
elseif current == 6
2425
return cache.cache6
26+
else
27+
error("This should not occur (please report a bug)")
2528
end
2629
elseif alg.choice_function isa AutoSwitch
2730
num = is_stiff ? 2 : 1

test/interface/default_solver_tests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ prob_rober_mm = ODEProblem(f, [1.0, 0.0, 1.0], (0.0, 1e5), (0.04, 3e7, 1e4))
104104
sol = solve(prob_rober_mm)
105105
@test all(isequal(3), sol.alg_choice)
106106
@test sol(0.5) isa Vector{Float64} # test dense output
107+
108+
109+
# test callback on ConstantCache (https://github.com/SciML/OrdinaryDiffEq.jl/issues/2287)
110+
using StaticArrays
111+
cb = ContinuousCallback((u, t, integrator) -> t - 1, (integrator) -> nothing)
112+
SA_ode_problem = ODEProblem((u, p, t) -> zero(u), SA[0], 2)
113+
@test solve(SA_ode_problem; callback=cb).retcode == ReturnCode.Success

0 commit comments

Comments
 (0)