Skip to content

Commit 4927ad9

Browse files
Merge pull request #539 from brainsMAKER/master
Fixing `RODESolution` inplace interpolation
2 parents 4fca547 + 60bde1b commit 4927ad9

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/dense.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function sde_interpolation!(vals,tvals,id,idxs,deriv,p,continuity::Symbol=:left)
223223
dt = ts[i₊] - ts[i₋]
224224
Θ = iszero(dt) ? oneunit(t) / oneunit(dt) : (t-ts[i₋]) / dt
225225

226-
if eltype(timeseries) <: AbstractArray
226+
if eltype(vals) <: AbstractArray
227227
sde_interpolant!(vals[j],Θ,dt,timeseries[i₋],timeseries[i₊],idxs,deriv)
228228
else
229229
vals[j] = sde_interpolant(Θ,dt,timeseries[i₋],timeseries[i₊],idxs,deriv)

test/inplace_interpolation.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using StochasticDiffEq, Test, Random
2+
import SDEProblemLibrary: prob_sde_linear, prob_sde_2Dlinear
3+
Random.seed!(100)
4+
5+
vecarrzero(m::Integer, n) = map(t->zeros(n), 1:m)
6+
7+
tt = 0:0.05:1
8+
ntt = length(tt)
9+
out_VF = zeros(ntt) # Vector{Float64}
10+
out_VVF_1 = vecarrzero(ntt,1) # Vector{Vector{Float64}}
11+
out_VVF_2 = vecarrzero(ntt,2) # Vector{Vector{Float64}}
12+
out_VMF = vecarrzero(ntt, size(prob_sde_2Dlinear.u0)) # Vector{Matrix{Float64}}
13+
14+
15+
@testset verbose=true "SDESolution interpolation" begin
16+
sol_SDE = solve(prob_sde_linear, SRIW1(); dt=1//2^4)
17+
sol_SDE_2D = solve(prob_sde_2Dlinear, SRIW1(); dt=1//2^4)
18+
19+
sol_SDE_interp = sol_SDE(tt)
20+
sol_SDE_2D_interp = sol_SDE_2D(tt)
21+
22+
@testset "1D" begin
23+
@test_throws MethodError sol_SDE(out_VF, tt; idxs=1:1)
24+
@test sol_SDE(out_VF, tt) isa Vector{Float64}
25+
@test sol_SDE(out_VVF_1,tt) isa Vector{Vector{Float64}}
26+
@test sol_SDE_interp.u == out_VF
27+
end
28+
29+
@testset "2D" begin
30+
@test_throws MethodError sol_SDE_2D(out_VF, tt; idxs=3:3)
31+
@test sol_SDE_2D(out_VF, tt; idxs=3) isa Vector{Float64}
32+
@test sol_SDE_2D(out_VVF_1, tt; idxs=3) isa Vector{Vector{Float64}}
33+
@test sol_SDE_2D(out_VVF_1, tt; idxs=3:3) isa Vector{Vector{Float64}}
34+
@test sol_SDE_2D(out_VVF_2, tt; idxs=2:3) isa Vector{Vector{Float64}}
35+
@test sol_SDE_2D(out_VMF, tt) isa Vector{Matrix{Float64}}
36+
@test sol_SDE_2D_interp.u == out_VMF
37+
end
38+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const is_APPVEYOR = Sys.iswindows() && haskey(ENV,"APPVEYOR")
4040
@time @safetestset "Scalar Tests" begin include("scalar_noise.jl") end
4141
@time @safetestset "Stiffness Detection Test" begin include("stiffness_detection_test.jl") end
4242
@time @safetestset "Adaptive SDE Linear Tests" begin include("adaptive/sde_linearadaptive_tests.jl") end
43+
@time @safetestset "Inplace RODESolution Interpolation Tests" begin include("inplace_interpolation.jl") end
4344
end
4445

4546
if GROUP == "All" || GROUP == "Interface3"

0 commit comments

Comments
 (0)