Skip to content

Commit 8280c24

Browse files
Add tests
1 parent 934ae5d commit 8280c24

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/basic.jl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SciMLOperators, LinearAlgebra
1+
using SciMLOperators, LinearAlgebra, SparseArrays
22
using Random
33

44
using SciMLOperators: IdentityOperator,
@@ -184,6 +184,51 @@ end
184184
for op in L.ops
185185
@test !isa(op, AddedOperator)
186186
end
187+
188+
# Allocations Tests
189+
190+
allocs_tot = @allocations mul!(v, op, u) # warmup
191+
allocs_tot = @allocations mul!(v, op, u)
192+
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
193+
allocs_tot = @allocations mul!(v, op, u, α, β) # warmup
194+
allocs_tot = @allocations mul!(v, op, u, α, β)
195+
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
196+
197+
## Time-Dependent Coefficients
198+
199+
for T in (Float32, Float64, ComplexF32, ComplexF64)
200+
N = 100
201+
A1_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
202+
A2_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
203+
A3_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
204+
205+
A1_dense = MatrixOperator(rand(T, N, N))
206+
A2_dense = MatrixOperator(rand(T, N, N))
207+
A3_dense = MatrixOperator(rand(T, N, N))
208+
209+
coeff1(a, u, p, t) = sin(p.ω * t)
210+
coeff2(a, u, p, t) = cos(p.ω * t)
211+
coeff3(a, u, p, t) = sin(p.ω * t) * cos(p.ω * t)
212+
213+
c1 = ScalarOperator(rand(T), coeff1)
214+
c2 = ScalarOperator(rand(T), coeff2)
215+
c3 = ScalarOperator(rand(T), coeff3)
216+
217+
H_sparse = c1 * A1_sparse + c2 * A2_sparse + c3 * A3_sparse
218+
H_dense = c1 * A1_dense + c2 * A2_dense + c3 * A3_dense
219+
220+
u = rand(T, N)
221+
du = similar(u)
222+
p == 0.1,)
223+
t = 0.1
224+
225+
allocs_sparse = @allocations H_sparse(du, u, p, t) # warmup
226+
allocs_sparse = @allocations H_sparse(du, u, p, t)
227+
allocs_dense = @allocations H_dense(du, u, p, t) # warmup
228+
allocs_dense = @allocations H_dense(du, u, p, t)
229+
@test allocs_sparse == 1 # BenchmarkTools.jl returns 0 instead of 1
230+
@test allocs_dense == 1 # BenchmarkTools.jl returns 0 instead of 1
231+
end
187232
end
188233

189234
@testset "ComposedOperator" begin

0 commit comments

Comments
 (0)