@@ -11,8 +11,8 @@ V = rand(ComplexF64, 10, 3)
11
11
W = rand (ComplexF64, 20 , 3 )
12
12
α = rand ()
13
13
β = rand ()
14
- M = LinearMap (A)
15
- N = LinearMap (M)
14
+ M = @inferred LinearMap (A)
15
+ N = @inferred LinearMap (M)
16
16
17
17
@testset " LinearMaps.jl" begin
18
18
@test eltype (M) == eltype (A)
74
74
@test @inferred LinearMap (M' )' * v == A * v
75
75
@test @inferred transpose (transpose (M)) == M
76
76
@test (M' )' == M
77
- Mherm = LinearMap (A' A)
77
+ Mherm = @inferred LinearMap (A' A)
78
78
@test @inferred ishermitian (Mherm)
79
79
@test @inferred ! issymmetric (Mherm)
80
80
@test @inferred ! issymmetric (transpose (Mherm))
98
98
@test @inferred mul! (copy (V), transpose (M), W) ≈ transpose (A) * W
99
99
@test @inferred mul! (copy (V), adjoint (M), W) ≈ A' * W
100
100
101
- B = LinearMap (Symmetric (rand (10 , 10 )))
101
+ B = @inferred LinearMap (Symmetric (rand (10 , 10 )))
102
102
@test transpose (B) == B
103
103
@test B == transpose (B)
104
104
105
- B = LinearMap (Hermitian (rand (ComplexF64, 10 , 10 )))
105
+ B = @inferred LinearMap (Hermitian (rand (ComplexF64, 10 , 10 )))
106
106
@test adjoint (B) == B
107
107
@test B == B'
108
108
end
@@ -121,40 +121,40 @@ end
121
121
end
122
122
return w
123
123
end
124
- MyFT = LinearMap {ComplexF64} (myft, N) / sqrt (N)
124
+ MyFT = @inferred LinearMap {ComplexF64} (myft, N) / sqrt (N)
125
125
U = Matrix (MyFT) # will be a unitary matrix
126
126
@test @inferred U' U ≈ Matrix {eltype(U)} (I, N, N)
127
127
128
- CS = LinearMap (cumsum, 2 )
128
+ CS = @inferred LinearMap (cumsum, 2 )
129
129
@test size (CS) == (2 , 2 )
130
130
@test @inferred ! issymmetric (CS)
131
131
@test @inferred ! ishermitian (CS)
132
132
@test @inferred ! isposdef (CS)
133
133
@test @inferred ! (LinearMaps. ismutating (CS))
134
134
@test @inferred Matrix (CS) == [1. 0. ; 1. 1. ]
135
135
@test @inferred Array (CS) == [1. 0. ; 1. 1. ]
136
- CS = LinearMap (cumsum, 10 ; ismutating= false )
136
+ CS = @inferred LinearMap (cumsum, 10 ; ismutating= false )
137
137
v = rand (10 )
138
138
cv = cumsum (v)
139
139
@test CS * v == cv
140
140
@test * (CS, v) == cv
141
141
@test_throws ErrorException CS' * v
142
- CS = LinearMap (cumsum, x -> cumsum (reverse (x)), 10 ; ismutating= false )
142
+ CS = @inferred LinearMap (cumsum, x -> cumsum (reverse (x)), 10 ; ismutating= false )
143
143
cv = cumsum (v)
144
144
@test @inferred CS * v == cv
145
145
@test @inferred * (CS, v) == cv
146
146
@test @inferred CS' * v == cumsum (reverse (v))
147
147
@test @inferred mul! (similar (v), transpose (CS), v) == cumsum (reverse (v))
148
148
149
- CS! = LinearMap (cumsum!, 10 ; ismutating= true )
149
+ CS! = @inferred LinearMap (cumsum!, 10 ; ismutating= true )
150
150
@test @inferred LinearMaps. ismutating (CS!)
151
151
@test @inferred CS! * v == cv
152
152
@test @inferred * (CS!, v) == cv
153
153
@test @inferred mul! (similar (v), CS!, v) == cv
154
154
@test_throws ErrorException CS!' v
155
155
@test_throws ErrorException transpose (CS!) * v
156
156
157
- CS! = LinearMap {ComplexF64} (cumsum!, 10 ; ismutating= true )
157
+ CS! = @inferred LinearMap {ComplexF64} (cumsum!, 10 ; ismutating= true )
158
158
v = rand (ComplexF64, 10 )
159
159
cv = cumsum (v)
160
160
@test @inferred LinearMaps. ismutating (CS!)
@@ -173,17 +173,17 @@ end
173
173
@test @inferred mul! (similar (v), adjoint (CS), v) == cumsum (reverse (v))
174
174
175
175
# Test fallback methods:
176
- L = LinearMap (x -> x, x -> x, 10 )
176
+ L = @inferred LinearMap (x -> x, x -> x, 10 )
177
177
v = randn (10 )
178
178
@test @inferred (2 * L)' * v ≈ 2 * v
179
179
@test @inferred transpose (2 * L) * v ≈ 2 * v
180
- L = LinearMap {ComplexF64} (x -> x, x -> x, 10 )
180
+ L = @inferred LinearMap {ComplexF64} (x -> x, x -> x, 10 )
181
181
v = rand (ComplexF64, 10 )
182
182
@test @inferred (2 * L)' * v ≈ 2 * v
183
183
@test @inferred transpose (2 * L) * v ≈ 2 * v
184
184
end
185
185
186
- CS! = LinearMap (cumsum!, 10 ; ismutating= true )
186
+ CS! = @inferred LinearMap (cumsum!, 10 ; ismutating= true )
187
187
v = rand (10 )
188
188
u = similar (v)
189
189
b = @benchmarkable mul! (u, CS!, v)
@@ -196,9 +196,9 @@ b = @benchmarkable mul!(u, L, v)
196
196
197
197
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
198
198
B = rand (size (A)... )
199
- M = LinearMap (A)
200
- N = LinearMap (B)
201
- LC = M + N
199
+ M = @inferred LinearMap (A)
200
+ N = @inferred LinearMap (B)
201
+ LC = @inferred M + N
202
202
v = rand (ComplexF64, 10 )
203
203
w = similar (v)
204
204
b = @benchmarkable mul! (w, M, v)
@@ -251,11 +251,11 @@ Base.:(*)(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, v::Vector) = A.f
251
251
mul! (y:: Vector , A:: Union{SimpleFunctionMap,SimpleComplexFunctionMap} , x:: Vector ) = copyto! (y, * (A, x))
252
252
253
253
@testset " composition" begin
254
- F = LinearMap (cumsum, 10 ; ismutating= false )
254
+ F = @inferred LinearMap (cumsum, 10 ; ismutating= false )
255
255
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
256
256
B = rand (size (A)... )
257
- M = 1 * LinearMap (A)
258
- N = LinearMap (B)
257
+ M = @inferred 1 * LinearMap (A)
258
+ N = @inferred LinearMap (B)
259
259
@test @inferred (F * F) * v == @inferred F * (F * v)
260
260
@test @inferred (F * A) * v == @inferred F * (A * v)
261
261
@test @inferred (A * F) * v == @inferred A * (F * v)
@@ -276,20 +276,21 @@ mul!(y::Vector, A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, x::Vector)
276
276
@test @inferred transpose (M * F) == @inferred transpose (F) * transpose (M)
277
277
@test @inferred (4 * ((- 3 * M)* 2 )) == @inferred - 12 M* 2
278
278
@test @inferred (4 * ((3 * (- M))* 2 )* (- 5 )) == @inferred - 12 M* (- 10 )
279
- L = 3 * F + 1im * A + F * M' * F
279
+ L = @inferred 3 * F + 1im * A + F * M' * F
280
280
LF = 3 * Matrix (F) + 1im * A + Matrix (F) * Matrix (M)' * Matrix (F)
281
281
@test Array (L) ≈ LF
282
282
R1 = rand (ComplexF64, 10 , 10 ); L1 = LinearMap (R1)
283
283
R2 = rand (ComplexF64, 10 , 10 ); L2 = LinearMap (R2)
284
284
R3 = rand (ComplexF64, 10 , 10 ); L3 = LinearMap (R3)
285
285
CompositeR = prod (R -> LinearMap (R), [R1, R2, R3])
286
- @test transpose (CompositeR) == transpose (L3) * transpose (L2) * transpose (L1)
287
- @test adjoint (CompositeR) == L3' * L2' * L1'
288
- @test adjoint (adjoint ((CompositeR))) == CompositeR
286
+ @test @inferred L1 * L2 * L3 == CompositeR
287
+ @test @inferred transpose (CompositeR) == transpose (L3) * transpose (L2) * transpose (L1)
288
+ @test @inferred adjoint (CompositeR) == L3' * L2' * L1'
289
+ @test @inferred adjoint (adjoint ((CompositeR))) == CompositeR
289
290
@test transpose (transpose ((CompositeR))) == CompositeR
290
- Lt = transpose (LinearMap (CompositeR))
291
+ Lt = @inferred transpose (LinearMap (CompositeR))
291
292
@test Lt * v ≈ transpose (R3) * transpose (R2) * transpose (R1) * v
292
- Lc = adjoint (LinearMap (CompositeR))
293
+ Lc = @inferred adjoint (LinearMap (CompositeR))
293
294
@test Lc * v ≈ R3' * R2' * R1' * v
294
295
295
296
# test inplace operations
@@ -360,9 +361,9 @@ A = rand(10, 20)
360
361
B = rand (ComplexF64, 10 , 20 )
361
362
SA = A' A + I
362
363
SB = B' B + I
363
- L = LinearMap {Float64} (A)
364
- MA = LinearMap (SA)
365
- MB = LinearMap (SB)
364
+ L = @inferred LinearMap {Float64} (A)
365
+ MA = @inferred LinearMap (SA)
366
+ MB = @inferred LinearMap (SB)
366
367
@testset " wrapped maps" begin
367
368
@test size (L) == size (A)
368
369
@test @inferred ! issymmetric (L)
@@ -375,12 +376,12 @@ end
375
376
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
376
377
B = rand (size (A)... )
377
378
M = @inferred 1 * LinearMap (A)
378
- N = LinearMap (B)
379
- LC = M + N
379
+ N = @inferred LinearMap (B)
380
+ LC = @inferred M + N
380
381
v = rand (ComplexF64, 10 )
381
382
w = similar (v)
382
383
@testset " identity/scaling map" begin
383
- Id = LinearMaps. UniformScalingMap (1 , 10 )
384
+ Id = @inferred LinearMaps. UniformScalingMap (1 , 10 )
384
385
@test_throws ErrorException LinearMaps. UniformScalingMap (1 , 10 , 20 )
385
386
@test_throws ErrorException LinearMaps. UniformScalingMap (1 , (10 , 20 ))
386
387
@test size (Id) == (10 , 10 )
@@ -538,16 +539,16 @@ end
538
539
@test size (L) == size (A)
539
540
@test L * x ≈ A * x
540
541
@test Matrix (L) ≈ A
541
- Lt = transform (L)
542
+ Lt = @inferred transform (L)
542
543
@test Lt isa LinearMaps. LinearMap{elty}
543
544
@test Lt * x ≈ transform (A) * x
544
- Lt = transform (LinearMap (L))
545
+ Lt = @inferred transform (LinearMap (L))
545
546
@test Lt * x ≈ transform (A) * x
546
547
@test Matrix (Lt) ≈ Matrix (transform (A))
547
548
A21 = rand (elty, 10 , 10 )
548
549
A = [I A12; A21 I]
549
550
L = [I LinearMap (A12); LinearMap (A21) I]
550
- Lt = transform (L)
551
+ Lt = @inferred transform (L)
551
552
@test Lt isa LinearMaps. LinearMap{elty}
552
553
@test Lt * x ≈ transform (A) * x
553
554
@test Matrix (Lt) ≈ Matrix (transform (A))
0 commit comments