1
1
using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools, InteractiveUtils
2
- using LinearMaps: FiveArg, ThreeArg
2
+ using LinearMaps: FiveArg
3
3
4
4
@testset " block maps" begin
5
5
@testset " hcat" begin
@@ -8,6 +8,10 @@ using LinearMaps: FiveArg, ThreeArg
8
8
A12 = rand (elty, 10 , n2)
9
9
v = rand (elty, 10 )
10
10
L = @inferred hcat (LinearMap (A11), LinearMap (A12))
11
+ @test L. maps isa Tuple
12
+ Lv = @inferred LinearMaps. BlockMap {elty} ([LinearMap (A11), LinearMap (A12)], (2 ,))
13
+ @test Lv. maps isa Vector
14
+ @test L == Lv == LinearMaps. BlockMap ([LinearMap (A11), LinearMap (A12)], (2 ,))
11
15
@test occursin (" 10×$(10 + n2) LinearMaps.BlockMap{$elty }" , sprint ((t, s) -> show (t, " text/plain" , s), L))
12
16
@test @inferred (LinearMaps. MulStyle (L)) === FiveArg ()
13
17
@test L isa LinearMaps. BlockMap{elty}
@@ -16,9 +20,9 @@ using LinearMaps: FiveArg, ThreeArg
16
20
end
17
21
A = [A11 A12]
18
22
x = rand (10 + n2)
19
- @test size (L) == size (A)
20
- @test Matrix (L) ≈ A
21
- @test L * x ≈ A * x
23
+ @test size (L) == size (A) == size (Lv)
24
+ @test Matrix (L) ≈ A ≈ Matrix (Lv)
25
+ @test L * x ≈ A * x ≈ Lv * x
22
26
L = @inferred hcat (LinearMap (A11), LinearMap (A12), LinearMap (A11))
23
27
A = [A11 A12 A11]
24
28
@test Matrix (L) ≈ A
@@ -53,15 +57,19 @@ using LinearMaps: FiveArg, ThreeArg
53
57
@test Matrix (L) ≈ A11
54
58
A21 = rand (elty, 20 , 10 )
55
59
L = @inferred vcat (LinearMap (A11), LinearMap (A21))
60
+ @test L. maps isa Tuple
61
+ Lv = LinearMaps. BlockMap {elty} ([LinearMap (A11), LinearMap (A21)], (1 ,1 ))
62
+ @test Lv. maps isa Vector
63
+ @test L == Lv
56
64
@test occursin (" 30×10 LinearMaps.BlockMap{$elty }" , sprint ((t, s) -> show (t, " text/plain" , s), L))
57
65
@test L isa LinearMaps. BlockMap{elty}
58
66
@test @inferred (LinearMaps. MulStyle (L)) === FiveArg ()
59
67
@test (@which [A11; A21]). module != LinearMaps
60
68
A = [A11; A21]
61
69
x = rand (10 )
62
70
@test size (L) == size (A)
63
- @test Matrix (L) ≈ A
64
- @test L * x ≈ A * x
71
+ @test Matrix (L) == Matrix (Lv) == A
72
+ @test L * x ≈ Lv * x ≈ A * x
65
73
A = [I; I; I; A11; A11; A11; v v v v v v v v v v]
66
74
@test (@which [I; I; I; A11; A11; A11; v v v v v v v v v v]). module != LinearMaps
67
75
L = @inferred vcat (I, I, I, LinearMap (A11), LinearMap (A11), LinearMap (A11), reduce (hcat, fill (v, 10 )))
@@ -85,14 +93,17 @@ using LinearMaps: FiveArg, ThreeArg
85
93
@test (@which [A11 A12; A21 A22]). module != LinearMaps
86
94
@inferred hvcat ((2 ,2 ), LinearMap (A11), LinearMap (A12), LinearMap (A21), LinearMap (A22))
87
95
L = [LinearMap (A11) LinearMap (A12); LinearMap (A21) LinearMap (A22)]
96
+ @test L. maps isa Tuple
97
+ Lv = @inferred LinearMaps. BlockMap {elty} ([LinearMap (A11), LinearMap (A12), LinearMap (A21), LinearMap (A22)], (2 ,2 ))
98
+ @test Lv. maps isa Vector
88
99
@test @inferred (LinearMaps. MulStyle (L)) === FiveArg ()
89
100
@test @inferred ! issymmetric (L)
90
101
@test @inferred ! ishermitian (L)
91
102
x = rand (30 )
92
103
@test L isa LinearMaps. BlockMap{elty}
93
104
@test size (L) == size (A)
94
- @test L * x ≈ A * x
95
- @test Matrix (L) == A
105
+ @test L * x ≈ Lv * x ≈ A * x
106
+ @test Matrix (L) == Matrix (Lv) == A
96
107
@test convert (AbstractMatrix, L) == A
97
108
A = [I A12; A21 I]
98
109
@test (@which [I A12; A21 I]). module != LinearMaps
@@ -202,6 +213,9 @@ using LinearMaps: FiveArg, ThreeArg
202
213
@test (@which cat (M1, M2, M3, M2, M1; dims= (1 ,2 ))). module != LinearMaps
203
214
x = randn (elty, size (Md, 2 ))
204
215
Bd = @inferred blockdiag (L1, L2, L3, L2, L1)
216
+ @test Bd. maps isa Tuple
217
+ Bdv = @inferred LinearMaps. BlockDiagonalMap {elty} ([L1, L2, L3, L2, L1])
218
+ @test Bdv. maps isa Vector
205
219
@test @inferred (LinearMaps. MulStyle (Bd)) === FiveArg ()
206
220
@test occursin (" 25×39 LinearMaps.BlockDiagonalMap{$elty }" , sprint ((t, s) -> show (t, " text/plain" , s), Bd))
207
221
@test Matrix (Bd) == Md
@@ -211,24 +225,26 @@ using LinearMaps: FiveArg, ThreeArg
211
225
@test Matrix (@inferred blockdiag (L1, L2)) == blockdiag (sparse .((M1, M2))... )
212
226
Bd2 = @inferred cat (L1, L2, L3, L2, L1; dims= (1 ,2 ))
213
227
@test_throws ArgumentError cat (L1, L2, L3, L2, L1; dims= (2 ,2 ))
214
- @test Bd == Bd2
228
+ @test Bd == Bdv == Bd2
215
229
@test Bd == blockdiag (L1, M2, M3, M2, M1)
216
230
@test size (Bd) == (25 , 39 )
217
231
@test ! issymmetric (Bd)
218
232
@test ! ishermitian (Bd)
219
- @test @inferred Bd * x ≈ Md * x
233
+ @test ( @inferred Bd * x) ≈ Bdv * x ≈ Md * x
220
234
for transform in (identity, adjoint, transpose)
221
235
@test Matrix (@inferred transform (Bd)) == transform (Md)
222
236
@test Matrix (@inferred transform (LinearMap (Bd))) == transform (Md)
223
237
end
224
238
y = randn (elty, size (Md, 1 ))
225
239
for α in (0 , 1 , rand (elty)), β in (0 , 1 , rand (elty))
226
240
@test mul! (copy (y), Bd, x, α, β) ≈ y* β .+ Md* x* α
241
+ @test mul! (copy (y), Bdv, x, α, β) ≈ y* β .+ Md* x* α
227
242
end
228
243
X = randn (elty, size (Md, 2 ), 10 )
229
244
Y = randn (elty, size (Md, 1 ), 10 )
230
245
for α in (0 , 1 , rand (elty)), β in (0 , 1 , rand (elty))
231
246
@test mul! (copy (Y), Bd, X, α, β) ≈ Y* β .+ Md* X* α
247
+ @test mul! (copy (Y), Bdv, X, α, β) ≈ Y* β .+ Md* X* α
232
248
end
233
249
end
234
250
end
0 commit comments