|
1 | | -using SciMLOperators, LinearAlgebra |
| 1 | +using SciMLOperators, LinearAlgebra, SparseArrays |
2 | 2 | using Random |
3 | 3 |
|
4 | 4 | using SciMLOperators: IdentityOperator, |
|
184 | 184 | for op in L.ops |
185 | 185 | @test !isa(op, AddedOperator) |
186 | 186 | 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 |
187 | 232 | end |
188 | 233 |
|
189 | 234 | @testset "ComposedOperator" begin |
|
0 commit comments