Skip to content

Commit bb2c1d3

Browse files
Fix extra allocation in tests
1 parent 4cafaa0 commit bb2c1d3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

test/basic.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ function apply_op!(H, du, u, p, t)
143143
return nothing
144144
end
145145

146+
test_apply_noalloc(H, du, u, p, t) = @test (@allocations apply_op!(H, du, u, p, t)) == 0
147+
146148
@testset "AddedOperator" begin
147149
A = rand(N, N) |> MatrixOperator
148150
B = rand(N, N) |> MatrixOperator
@@ -192,9 +194,8 @@ end
192194

193195
# Allocations Tests
194196

195-
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0) # warmup
196-
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0)
197-
@test allocs_tot <= 1 # BenchmarkTools.jl returns 0 instead of 1
197+
@allocations apply_op!(op, v, u, (), 1.0) # warmup
198+
test_apply_noalloc(op, v, u, (), 1.0)
198199

199200
## Time-Dependent Coefficients
200201

@@ -224,12 +225,10 @@ end
224225
p == 0.1,)
225226
t = 0.1
226227

227-
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t) # warmup
228-
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t)
229-
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t) # warmup
230-
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t)
231-
@test allocs_sparse <= 1 # BenchmarkTools.jl returns 0 instead of 1
232-
@test allocs_dense <= 1 # BenchmarkTools.jl returns 0 instead of 1
228+
@allocations apply_op!(H_sparse, du, u, p, t) # warmup
229+
@allocations apply_op!(H_dense, du, u, p, t) # warmup
230+
test_apply_noalloc(H_sparse, du, u, p, t)
231+
test_apply_noalloc(H_dense, du, u, p, t)
233232
end
234233
end
235234

0 commit comments

Comments
 (0)