Skip to content

Commit 28a8bcf

Browse files
committed
add PreallocationTools.LazyBufferCache as cache for SplitODEProblem
1 parent 5edf434 commit 28a8bcf

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1919
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2020
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
2121
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
22+
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
2223
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
2324
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
2425
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -75,6 +76,7 @@ Makie = "0.20, 0.21, 0.22, 0.23, 0.24"
7576
Markdown = "1.10"
7677
Moshi = "0.3"
7778
PartialFunctions = "1.1"
79+
PreallocationTools = "0.4.29"
7880
PrecompileTools = "1.2"
7981
Preferences = "1.3"
8082
Printf = "1.10"

src/SciMLBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using Distributed
1414
using Markdown
1515
using Printf
1616
import Preferences
17+
using PreallocationTools
1718

1819
import Logging, ArrayInterface
1920
import IteratorInterfaceExtensions

src/problems/ode_problems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ end
474474
function SplitODEProblem{iip}(f::SplitFunction, u0, tspan, p = NullParameters();
475475
kwargs...) where {iip}
476476
if f._func_cache === nothing && iip
477-
_func_cache = similar(u0)
477+
_func_cache = PreallocationTools.LazyBufferCache()
478478
f = remake(f; _func_cache)
479479
end
480480
ODEProblem(f, u0, tspan, p, SplitODEProblem{iip}(); kwargs...)

src/scimlfunctions.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,9 +2618,10 @@ end
26182618

26192619
(f::SplitFunction)(u, p, t) = f.f1(u, p, t) + f.f2(u, p, t)
26202620
function (f::SplitFunction)(du, u, p, t)
2621-
f.f1(f._func_cache, u, p, t)
2621+
tmp = PreallocationTools.get_tmp(f._func_cache, u)
2622+
f.f1(tmp, u, p, t)
26222623
f.f2(du, u, p, t)
2623-
du .+= f._func_cache
2624+
du .+= tmp
26242625
end
26252626

26262627
(f::DiscreteFunction)(args...) = f.f(args...)
@@ -2666,11 +2667,11 @@ end
26662667

26672668
(f::SDDEFunction)(args...) = f.f(args...)
26682669
(f::SplitSDEFunction)(u, p, t) = f.f1(u, p, t) + f.f2(u, p, t)
2669-
26702670
function (f::SplitSDEFunction)(du, u, p, t)
2671-
f.f1(f._func_cache, u, p, t)
2671+
tmp = PreallocationTools.get_tmp(f._func_cache)
2672+
f.f1(tmp, u, p, t)
26722673
f.f2(du, u, p, t)
2673-
du .+= f._func_cache
2674+
du .+= tmp
26742675
end
26752676

26762677
(f::RODEFunction)(args...) = f.f(args...)

0 commit comments

Comments
 (0)