SciML/OrdinaryDiffEq.jl

Avoid allocations for interpolator evaluation

Ouverte

#1 270 ouverte le 15 sept. 2020

 (6 commentaires) (0 réaction) (0 personne assignée)Julia (262 forks)batch import
help wantedperformance

Métriques du dépôt

Stars
 (656 étoiles)
Métriques de merge PR
 (Merge moyen 3j 12h) (74 PRs mergées en 30 j)

Description

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!

Guide contributeur