SciML/OrdinaryDiffEq.jl

Avoid allocations for interpolator evaluation

Offen

#1.270 geöffnet am 15.09.2020

 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Julia (262 Forks)batch import
help wantedperformance

Repository-Metriken

Stars
 (656 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 3T 12h) (74 gemergte PRs in 30 T)

Beschreibung

Hi,

I have noticed that the interpolation of a solution allocates. This is a MWE:

using OrdinaryDiffEq
using BenchmarkTools

function f1(du, u, p, t)
  du[1] = u[1]
end
prob1 = ODEProblem{true}(f1, ones(1), (0.0, 1.0), nothing)
sol1 = solve(prob1, Tsit5())

f2(u, p, t) = u
prob2 = ODEProblem{false}(f2, 1.0, (0.0, 1.0), nothing)
sol2 = solve(prob2, Tsit5())

out = zeros(1)

Then:

julia> @btime $sol1(0.1)
  1.181 μs (18 allocations: 416 bytes)
1-element Array{Float64,1}:
 1.1051709180988993

julia> @btime $sol1($out, 0.1)
  1.143 μs (17 allocations: 320 bytes)
1-element Array{Float64,1}:
 1.1051709180988993

julia> @btime $sol2(0.1)
  1.267 μs (25 allocations: 1.33 KiB)
1.1051709180988993

julia> @btime $sol2($out, 0.1)
  1.185 μs (24 allocations: 1.31 KiB)
1-element Array{Float64,1}:
 1.1051709180988993

Thanks!

Contributor Guide