SciML/OrdinaryDiffEq.jl

Avoid allocations for interpolator evaluation

开放

#1,270 创建于 2020年9月15日

 (6 条评论) (0 个反应) (0 位负责人)Julia (262 个派生)batch import
help wantedperformance

仓库指标

星标
 (656 个星标)
PR 合并指标
 (平均合并 3天 12小时) (30 天内合并 74 个 PR)

描述

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!

贡献者指南