Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions test/alloc_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using SimpleDiffEq
using DiffEqBase
using StaticArrays
using Test

@testset "Allocation Tests - Zero Allocation Verification" begin
# Define test problems (Lorenz system)
function loop_oop(u, p, t)
@inbounds begin
σ = p[1]
ρ = p[2]
β = p[3]
du1 = σ * (u[2] - u[1])
du2 = u[1] * (ρ - u[3]) - u[2]
du3 = u[1] * u[2] - β * u[3]
return SVector{3}(du1, du2, du3)
end
end

function loop_iip!(du, u, p, t)
σ = p[1]
ρ = p[2]
β = p[3]
du[1] = σ * (u[2] - u[1])
du[2] = u[1] * (ρ - u[3]) - u[2]
du[3] = u[1] * u[2] - β * u[3]
return nothing
end

u0_vec = [10.0, 10.0, 10.0]
u0_svec = SVector{3}(10.0, 10.0, 10.0)
dt = 0.01
p = [10.0, 28.0, 8 / 3]

@testset "SimpleTsit5 step! - zero allocations" begin
# OOP (out-of-place) with SVector
integ_oop = SimpleDiffEq.simpletsit5_init(loop_oop, false, u0_svec, 0.0, dt, p)
step!(integ_oop) # warmup
allocs = @allocated step!(integ_oop)
@test allocs == 0

# IIP (in-place) with Vector
integ_iip = SimpleDiffEq.simpletsit5_init(loop_iip!, true, copy(u0_vec), 0.0, dt, p)
step!(integ_iip) # warmup
allocs = @allocated step!(integ_iip)
@test allocs == 0
end

@testset "SimpleRK4 step! - zero allocations" begin
# OOP (out-of-place) with SVector
integ_oop = SimpleDiffEq.simplerk4_init(loop_oop, false, u0_svec, 0.0, dt, p)
step!(integ_oop) # warmup
allocs = @allocated step!(integ_oop)
@test allocs == 0

# IIP (in-place) with Vector
integ_iip = SimpleDiffEq.simplerk4_init(loop_iip!, true, copy(u0_vec), 0.0, dt, p)
step!(integ_iip) # warmup
allocs = @allocated step!(integ_iip)
@test allocs == 0
end

@testset "SimpleEuler step! - zero allocations" begin
# OOP (out-of-place) with SVector
integ_oop = SimpleDiffEq.simpleeuler_init(loop_oop, false, u0_svec, 0.0, dt, p)
step!(integ_oop) # warmup
allocs = @allocated step!(integ_oop)
@test allocs == 0

# IIP (in-place) with Vector
integ_iip = SimpleDiffEq.simpleeuler_init(loop_iip!, true, copy(u0_vec), 0.0, dt, p)
step!(integ_iip) # warmup
allocs = @allocated step!(integ_iip)
@test allocs == 0
end

@testset "SimpleATsit5 step! - zero allocations" begin
# OOP (out-of-place) with SVector
prob_oop = ODEProblem{false}(loop_oop, u0_svec, (0.0, 100.0), p)
integ_oop = DiffEqBase.__init(prob_oop, SimpleATsit5(), dt = dt)
step!(integ_oop) # warmup
allocs = @allocated step!(integ_oop)
@test allocs == 0

# IIP (in-place) with Vector
prob_iip = ODEProblem{true}(loop_iip!, copy(u0_vec), (0.0, 100.0), p)
integ_iip = DiffEqBase.__init(prob_iip, SimpleATsit5(), dt = dt)
step!(integ_iip) # warmup
allocs = @allocated step!(integ_iip)
@test allocs == 0
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ const GROUP = get(ENV, "GROUP", "Core")
import Pkg
Pkg.add("JET")
@time @safetestset "JET Static Analysis Tests" include("jet_tests.jl")
@time @safetestset "Allocation Tests" include("alloc_tests.jl")
end
end
Loading