|
| 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 |
0 commit comments