@@ -2,23 +2,7 @@ using Test
22using LinearMaps
33using SparseArrays
44using 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
226
237A = 2 * rand (ComplexF64, (20 , 10 )) .- 1
248v = rand (ComplexF64, 10 )
@@ -61,7 +45,8 @@ AV = A * V
6145 @test M * v == Av
6246 @test N * v == Av
6347 @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
6550 @test @inferred mul! (copy (w), N, v) == Av
6651
6752 # mat-vec-mul
@@ -201,12 +186,13 @@ end
201186CS! = LinearMap (cumsum!, 10 ; ismutating= true )
202187v = rand (10 )
203188u = 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
206191n = 10
207192L = sum (fill (CS!, n))
208193@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
210196
211197A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
212198B = rand (size (A)... )
@@ -215,8 +201,8 @@ N = LinearMap(B)
215201LC = M + N
216202v = rand (ComplexF64, 10 )
217203w = 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
220206@testset " linear combinations" begin
221207 # @test_throws ErrorException LinearMaps.LinearCombination{ComplexF64}((M, N), (1, 2, 3))
222208 @test @inferred size (3 M + 2.0 N) == size (A)
@@ -420,10 +406,19 @@ end
420406 β = UniformScaling (Quaternion .(rand (4 )... ))
421407 L = LinearMap (A)
422408 @test Array (L) == A
409+ @test Array (L' ) == A'
410+ @test Array (transpose (L)) == transpose (A)
423411 @test Array (α * L) == α * A
424412 @test Array (L * α) == A * α
425413 @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
427422 @test (α * L' )' * x ≈ (α * A' )' * x
428423 @test (α * L' )' * v ≈ (α * A' )' * v
429424 @test Array (@inferred adjoint (α * L * β)) ≈ conj (β) * A' * conj (α)
0 commit comments