Skip to content

Commit

Permalink
Make separate function for allocations test
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomercurio committed Oct 15, 2024
1 parent 8280c24 commit 4cafaa0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ end
@test ldiv!(op, u) * D) \ v
end

function apply_op!(H, du, u, p, t)
H(du, u, p, t)
return nothing
end

@testset "AddedOperator" begin
A = rand(N, N) |> MatrixOperator
B = rand(N, N) |> MatrixOperator
Expand Down Expand Up @@ -187,12 +192,9 @@ end

# Allocations Tests

allocs_tot = @allocations mul!(v, op, u) # warmup
allocs_tot = @allocations mul!(v, op, u)
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
allocs_tot = @allocations mul!(v, op, u, α, β) # warmup
allocs_tot = @allocations mul!(v, op, u, α, β)
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0) # warmup
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0)
@test allocs_tot <= 1 # BenchmarkTools.jl returns 0 instead of 1

## Time-Dependent Coefficients

Expand Down Expand Up @@ -222,12 +224,12 @@ end
p == 0.1,)
t = 0.1

allocs_sparse = @allocations H_sparse(du, u, p, t) # warmup
allocs_sparse = @allocations H_sparse(du, u, p, t)
allocs_dense = @allocations H_dense(du, u, p, t) # warmup
allocs_dense = @allocations H_dense(du, u, p, t)
@test allocs_sparse == 1 # BenchmarkTools.jl returns 0 instead of 1
@test allocs_dense == 1 # BenchmarkTools.jl returns 0 instead of 1
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t) # warmup
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t)
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t) # warmup
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t)
@test allocs_sparse <= 1 # BenchmarkTools.jl returns 0 instead of 1
@test allocs_dense <= 1 # BenchmarkTools.jl returns 0 instead of 1
end
end

Expand Down

0 comments on commit 4cafaa0

Please sign in to comment.