SciML/OrdinaryDiffEq.jl

Avoid allocations for interpolator evaluation

オープン

#1,270 opened on 2020/09/15

 (6 件のコメント) (0 件のリアクション) (0 人の担当者)Julia (262 件のフォーク)batch import
help wantedperformance

Repository metrics

Stars
 (656 個のスター)
PR merge metrics
 (平均マージ 3d 12h) (30d で 74 merged PRs)

説明

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!

コントリビューターガイド