@@ -2,23 +2,7 @@ using Test
2
2
using LinearMaps
3
3
using SparseArrays
4
4
using LinearAlgebra
5
-
6
- # adopted from: https://discourse.julialang.org/t/way-to-return-the-number-of-allocations/5167/10
7
- macro numalloc (expr)
8
- return quote
9
- let
10
- local f
11
- function f ()
12
- n1 = Base. gc_num ()
13
- $ (expr)
14
- n2 = Base. gc_num ()
15
- diff = Base. GC_Diff (n2, n1)
16
- Base. gc_alloc_count (diff)
17
- end
18
- f ()
19
- end
20
- end
21
- end
5
+ using BenchmarkTools
22
6
23
7
A = 2 * rand (ComplexF64, (20 , 10 )) .- 1
24
8
v = rand (ComplexF64, 10 )
@@ -61,7 +45,8 @@ AV = A * V
61
45
@test M * v == Av
62
46
@test N * v == Av
63
47
@test @inferred mul! (copy (w), M, v) == mul! (copy (w), A, v)
64
- @test ((@allocated mul! (w, M, v)) == 0 )
48
+ b = @benchmarkable mul! (w, M, v)
49
+ @test run (b, samples= 3 ). allocs == 0
65
50
@test @inferred mul! (copy (w), N, v) == Av
66
51
67
52
# mat-vec-mul
@@ -201,12 +186,13 @@ end
201
186
CS! = LinearMap (cumsum!, 10 ; ismutating= true )
202
187
v = rand (10 )
203
188
u = similar (v)
204
- mul! (u, CS!, v)
205
- @test (( @allocated mul! (u, CS!, v)) == 0 )
189
+ b = @benchmarkable mul! (u, CS!, v)
190
+ @test run (b, samples = 3 ) . allocs == 0
206
191
n = 10
207
192
L = sum (fill (CS!, n))
208
193
@test mul! (u, L, v) ≈ n * cumsum (v)
209
- @test ((@numalloc mul! (u, L, v)) <= 1 )
194
+ b = @benchmarkable mul! (u, L, v)
195
+ @test run (b, samples= 5 ). allocs <= 1
210
196
211
197
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
212
198
B = rand (size (A)... )
@@ -215,8 +201,8 @@ N = LinearMap(B)
215
201
LC = M + N
216
202
v = rand (ComplexF64, 10 )
217
203
w = similar (v)
218
- mul! (w, M, v)
219
- @test (( @allocated mul! (w, M, v)) == 0 )
204
+ b = @benchmarkable mul! (w, M, v)
205
+ @test run (b, samples = 3 ) . allocs == 0
220
206
@testset " linear combinations" begin
221
207
# @test_throws ErrorException LinearMaps.LinearCombination{ComplexF64}((M, N), (1, 2, 3))
222
208
@test @inferred size (3 M + 2.0 N) == size (A)
@@ -420,10 +406,19 @@ end
420
406
β = UniformScaling (Quaternion .(rand (4 )... ))
421
407
L = LinearMap (A)
422
408
@test Array (L) == A
409
+ @test Array (L' ) == A'
410
+ @test Array (transpose (L)) == transpose (A)
423
411
@test Array (α * L) == α * A
424
412
@test Array (L * α) == A * α
425
413
@test Array (α * L) == α * A
426
- @test Array (L * α) == A * α
414
+ @test Array (L * α ) == A * α
415
+ @test Array (α * L' ) == α * A'
416
+ @test Array ((α * L' )' ) ≈ (α * A' )' ≈ A * conj (α)
417
+ @test L * x ≈ A * x
418
+ @test L' * x ≈ A' * x
419
+ @test α * (L * x) ≈ α * (A * x)
420
+ @test α * L * x ≈ α * A * x
421
+ @test (α * L' ) * x ≈ (α * A' ) * x
427
422
@test (α * L' )' * x ≈ (α * A' )' * x
428
423
@test (α * L' )' * v ≈ (α * A' )' * v
429
424
@test Array (@inferred adjoint (α * L * β)) ≈ conj (β) * A' * conj (α)
0 commit comments