22
22
A = 2 * rand (ComplexF64, (20 , 10 )) .- 1
23
23
v = rand (ComplexF64, 10 )
24
24
w = rand (ComplexF64, 20 )
25
- wdest = copy (w)
26
25
V = rand (ComplexF64, 10 , 3 )
27
26
W = rand (ComplexF64, 20 , 3 )
28
- Wdest = copy (W)
29
27
α = rand ()
30
28
β = rand ()
31
29
32
30
# test wrapped map for matrix
33
31
M = LinearMap (A)
34
32
@test M * v == A * v
35
- mul! (Wdest , M, V)
36
- @test Wdest ≈ A * V
33
+ @test mul! (w , M, v) == A * v
34
+ @test mul! ( copy (W), M, V) ≈ A * V
37
35
@test typeof (M * V) <: LinearMap
36
+ @test LinearMap (M) * v == A * v
38
37
39
38
# test of mul!
40
- mul! (wdest, M, v, 0 , 0 )
41
- @test wdest == zero (w)
42
- wdest = copy (w)
43
- mul! (wdest, M, v, 0 , 1 )
44
- @test wdest == w
45
- wdest = copy (w)
46
- mul! (wdest, M, v, 0 , β)
47
- @test wdest == β * w
48
- wdest = copy (w)
49
- mul! (wdest, M, v, 1 , 1 )
50
- @test wdest ≈ A * v + w
51
- wdest = copy (w)
52
- mul! (wdest, M, v, 1 , β)
53
- @test wdest ≈ A * v + β * w
54
- wdest = copy (w)
55
- mul! (wdest, M, v, α, 1 )
56
- @test wdest ≈ α * A * v + w
57
- wdest = copy (w)
58
- mul! (wdest, M, v, α, β)
59
- @test wdest ≈ α * A * v + β * w
60
- wdest = copy (w)
61
- mul! (wdest, M, v, α)
62
- @test wdest ≈ α * A * v
39
+ @test mul! (copy (w), M, v, 0 , 0 ) == zero (w)
40
+ @test mul! (copy (w), M, v, 0 , 1 ) == w
41
+ @test mul! (copy (w), M, v, 0 , β) == β * w
42
+ @test mul! (copy (w), M, v, 1 , 1 ) ≈ A * v + w
43
+ @test mul! (copy (w), M, v, 1 , β) ≈ A * v + β * w
44
+ @test mul! (copy (w), M, v, α, 1 ) ≈ α * A * v + w
45
+ @test mul! (copy (w), M, v, α, β) ≈ α * A * v + β * w
46
+ @test mul! (copy (w), M, v, α) ≈ α * A * v
63
47
64
48
# test matrix-mul!
65
- Wdest = copy (W)
66
- mul! (Wdest, M, V, α, β)
67
- @test Wdest ≈ α * A * V + β * W
68
- Wdest = copy (W)
69
- mul! (Wdest, M, V, α)
70
- @test Wdest ≈ α * A * V
49
+ @test mul! (copy (W), M, V, α, β) ≈ α * A * V + β * W
50
+ @test mul! (copy (W), M, V, α) ≈ α * A * V
71
51
72
52
# test transposition and Matrix
73
53
@test M' * w == A' * w
74
- mul! (V, adjoint (M), W)
75
- @test V ≈ A' * W
76
-
54
+ @test mul! (copy (V), adjoint (M), W) ≈ A' * W
77
55
@test transpose (M) * w == transpose (A) * w
78
- mul! (V, transpose (M), W)
79
- @test V ≈ transpose (A) * W
56
+ @test transpose (M' ) * v ≈ transpose (A ' ) * v
57
+ @test mul! ( copy (V), transpose (M), W) ≈ transpose (A) * W
80
58
81
59
@test Matrix (M) == A
82
60
@test Array (M) == A
@@ -99,7 +77,7 @@ B = LinearMap(Hermitian(rand(ComplexF64, 10, 10)))
99
77
@test convert (SparseMatrixCSC, M) == sparse (Array (M))
100
78
101
79
B = copy (A)
102
- B[rand (1 : length (A), 30 )] .= 0.
80
+ B[rand (1 : length (A), 30 )] .= 0
103
81
MS = LinearMap (B)
104
82
@test sparse (MS) == sparse (Array (MS))
105
83
@@ -130,7 +108,9 @@ v = randn(10);
130
108
131
109
# test linear combinations
132
110
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
111
+ B = rand (size (A)... )
133
112
M = LinearMap (A)
113
+ N = LinearMap (B)
134
114
v = rand (ComplexF64, 10 )
135
115
136
116
@test Matrix (3 * M) == 3 * A
@@ -140,20 +120,33 @@ v = rand(ComplexF64, 10)
140
120
@test (3 * M - 1im * F)' == 3 * M' + 1im * F'
141
121
142
122
@test (2 * M' + 3 * I) * v ≈ (2 * A' + 3 * I) * v
123
+ @test transpose (LinearMap (2 * M' + 3 * I)) * v ≈ transpose (2 * A' + 3 * I) * v
124
+ @test LinearMap (2 * M' + 3 * I)' * v ≈ (2 * A' + 3 * I)' * v
143
125
144
126
# test composition
145
127
@test (F * F) * v == F * (F * v)
146
128
@test (F * A) * v == F * (A * v)
147
129
@test Matrix (M * transpose (M)) ≈ A * transpose (A)
148
130
@test ! isposdef (M * transpose (M))
149
131
@test isposdef (M * M' )
132
+ @test issymmetric (N * N' )
133
+ @test ishermitian (N * N' )
134
+ @test ! issymmetric (M' * M)
135
+ @test ishermitian (M' * M)
150
136
@test isposdef (transpose (F) * F)
151
137
@test isposdef ((M * F)' * M * F)
152
138
@test transpose (M * F) == transpose (F) * transpose (M)
153
-
154
139
L = 3 * F + 1im * A + F * M' * F
155
140
LF = 3 * Matrix (F) + 1im * A + Matrix (F) * Matrix (M)' * Matrix (F)
156
141
@test Array (L) ≈ LF
142
+ R1 = rand (ComplexF64, 10 , 10 )
143
+ R2 = rand (ComplexF64, 10 , 10 )
144
+ R3 = rand (ComplexF64, 10 , 10 )
145
+ CompositeR = prod (R -> LinearMap (R), [R1, R2, R3])
146
+ Lt = transpose (LinearMap (CompositeR))
147
+ @test Lt * v ≈ transpose (R3) * transpose (R2) * transpose (R1) * v
148
+ Lc = adjoint (LinearMap (CompositeR))
149
+ @test Lc * v ≈ R3' * R2' * R1' * v
157
150
158
151
# test inplace operations
159
152
w = similar (v)
0 commit comments