@@ -8,19 +8,19 @@ n=12 #Size of matrix problem to test
8
8
srand (1 )
9
9
10
10
@testset for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
11
- d = convert (Vector{elty}, randn (n))
12
- v = convert (Vector{elty}, randn (n))
13
- U = convert (Matrix{elty}, randn (n,n))
11
+ dd = convert (Vector{elty}, randn (n))
12
+ vv = convert (Vector{elty}, randn (n))
13
+ UU = convert (Matrix{elty}, randn (n,n))
14
14
if elty <: Complex
15
- d += im* convert (Vector{elty}, randn (n))
16
- v += im* convert (Vector{elty}, randn (n))
17
- U += im* convert (Matrix{elty}, randn (n,n))
15
+ dd += im* convert (Vector{elty}, randn (n))
16
+ vv += im* convert (Vector{elty}, randn (n))
17
+ UU += im* convert (Matrix{elty}, randn (n,n))
18
18
end
19
- D = Diagonal (d )
20
- DM = diagm (d )
19
+ D = Diagonal (dd )
20
+ DM = diagm (dd )
21
21
22
22
@testset " constructor" begin
23
- for x in (d , GenericArray (d ))
23
+ for x in (dd , GenericArray (dd ))
24
24
@test Diagonal (x):: Diagonal{elty,typeof(x)} == DM
25
25
@test Diagonal (x). diag === x
26
26
@test Diagonal {elty} (x):: Diagonal{elty,typeof(x)} == DM
@@ -38,9 +38,9 @@ srand(1)
38
38
@test Array (abs .(D)) == abs .(DM)
39
39
@test Array (imag (D)) == imag (DM)
40
40
41
- @test parent (D) == d
42
- @test diag (D) == d
43
- @test D[1 ,1 ] == d [1 ]
41
+ @test parent (D) == dd
42
+ @test diag (D) == dd
43
+ @test D[1 ,1 ] == dd [1 ]
44
44
@test D[1 ,2 ] == 0
45
45
46
46
@test issymmetric (D)
@@ -73,61 +73,49 @@ srand(1)
73
73
end
74
74
75
75
@testset " Linear solve" begin
76
- let vv = v, UU = U
77
- @testset for atype in (" Array" , " SubArray" )
78
- if atype == " Array"
79
- v = vv
80
- U = UU
81
- else
82
- v = view (vv, 1 : n)
83
- U = view (UU, 1 : n, 1 : 2 )
84
- end
85
-
86
- @test D* v ≈ DM* v atol= n* eps (relty)* (1 + (elty<: Complex ))
87
- @test D* U ≈ DM* U atol= n^ 2 * eps (relty)* (1 + (elty<: Complex ))
88
-
89
- @test U.' * D ≈ U.' * Array (D)
90
- @test U' * D ≈ U' * Array (D)
91
-
92
- if relty != BigFloat
93
- atol_two = 2 n^ 2 * eps (relty) * (1 + (elty <: Complex ))
94
- atol_three = 2 n^ 3 * eps (relty) * (1 + (elty <: Complex ))
95
- @test D\ v ≈ DM\ v atol= atol_two
96
- @test D\ U ≈ DM\ U atol= atol_three
97
- @test A_ldiv_B! (D, copy (v)) ≈ DM\ v atol= atol_two
98
- @test At_ldiv_B! (D, copy (v)) ≈ DM\ v atol= atol_two
99
- @test Ac_ldiv_B! (conj (D), copy (v)) ≈ DM\ v atol= atol_two
100
- @test A_ldiv_B! (D, copy (U)) ≈ DM\ U atol= atol_three
101
- @test At_ldiv_B! (D, copy (U)) ≈ DM\ U atol= atol_three
102
- @test Ac_ldiv_B! (conj (D), copy (U)) ≈ DM\ U atol= atol_three
103
- Uc = adjoint (U)
104
- target = scale! (Uc, inv .(D. diag))
105
- @test A_rdiv_B! (Uc, D) ≈ target atol= atol_three
106
- @test_throws DimensionMismatch A_rdiv_B! (eye (elty, n- 1 ), D)
107
- @test_throws SingularException A_rdiv_B! (Uc, zeros (D))
108
- @test A_rdiv_Bt! (Uc, D) ≈ target atol= atol_three
109
- @test A_rdiv_Bc! (Uc, conj (D)) ≈ target atol= atol_three
110
- @test A_ldiv_B! (D, eye (D)) ≈ D\ eye (D) atol= atol_three
111
- @test_throws DimensionMismatch A_ldiv_B! (D, ones (elty, n + 1 ))
112
- @test_throws SingularException A_ldiv_B! (Diagonal (zeros (relty, n)), copy (v))
113
- b = rand (elty, n, n)
114
- b = sparse (b)
115
- @test A_ldiv_B! (D, copy (b)) ≈ Array (D)\ Array (b)
116
- @test_throws SingularException A_ldiv_B! (Diagonal (zeros (elty, n)), copy (b))
117
- b = view (rand (elty, n), collect (1 : n))
118
- b2 = copy (b)
119
- c = A_ldiv_B! (D, b)
120
- d = Array (D)\ b2
121
- for i in 1 : n
122
- @test c[i] ≈ d[i]
123
- end
124
- @test_throws SingularException A_ldiv_B! (Diagonal (zeros (elty, n)), b)
125
- b = rand (elty, n+ 1 , n+ 1 )
126
- b = sparse (b)
127
- @test_throws DimensionMismatch A_ldiv_B! (D, copy (b))
128
- b = view (rand (elty, n+ 1 ), collect (1 : n+ 1 ))
129
- @test_throws DimensionMismatch A_ldiv_B! (D, b)
130
- end
76
+ for (v, U) in ((vv, UU), (view (vv, 1 : n), view (UU, 1 : n, 1 : 2 )))
77
+ @test D* v ≈ DM* v atol= n* eps (relty)* (1 + (elty<: Complex ))
78
+ @test D* U ≈ DM* U atol= n^ 2 * eps (relty)* (1 + (elty<: Complex ))
79
+
80
+ @test U.' * D ≈ U.' * Array (D)
81
+ @test U' * D ≈ U' * Array (D)
82
+
83
+ if relty != BigFloat
84
+ atol_two = 2 n^ 2 * eps (relty) * (1 + (elty <: Complex ))
85
+ atol_three = 2 n^ 3 * eps (relty) * (1 + (elty <: Complex ))
86
+ @test D\ v ≈ DM\ v atol= atol_two
87
+ @test D\ U ≈ DM\ U atol= atol_three
88
+ @test A_ldiv_B! (D, copy (v)) ≈ DM\ v atol= atol_two
89
+ @test At_ldiv_B! (D, copy (v)) ≈ DM\ v atol= atol_two
90
+ @test Ac_ldiv_B! (conj (D), copy (v)) ≈ DM\ v atol= atol_two
91
+ @test A_ldiv_B! (D, copy (U)) ≈ DM\ U atol= atol_three
92
+ @test At_ldiv_B! (D, copy (U)) ≈ DM\ U atol= atol_three
93
+ @test Ac_ldiv_B! (conj (D), copy (U)) ≈ DM\ U atol= atol_three
94
+ Uc = adjoint (U)
95
+ target = scale! (Uc, inv .(D. diag))
96
+ @test A_rdiv_B! (Uc, D) ≈ target atol= atol_three
97
+ @test_throws DimensionMismatch A_rdiv_B! (eye (elty, n- 1 ), D)
98
+ @test_throws SingularException A_rdiv_B! (Uc, zeros (D))
99
+ @test A_rdiv_Bt! (Uc, D) ≈ target atol= atol_three
100
+ @test A_rdiv_Bc! (Uc, conj (D)) ≈ target atol= atol_three
101
+ @test A_ldiv_B! (D, eye (D)) ≈ D\ eye (D) atol= atol_three
102
+ @test_throws DimensionMismatch A_ldiv_B! (D, ones (elty, n + 1 ))
103
+ @test_throws SingularException A_ldiv_B! (Diagonal (zeros (relty, n)), copy (v))
104
+ b = rand (elty, n, n)
105
+ b = sparse (b)
106
+ @test A_ldiv_B! (D, copy (b)) ≈ Array (D)\ Array (b)
107
+ @test_throws SingularException A_ldiv_B! (Diagonal (zeros (elty, n)), copy (b))
108
+ b = view (rand (elty, n), collect (1 : n))
109
+ b2 = copy (b)
110
+ c = A_ldiv_B! (D, b)
111
+ d = Array (D)\ b2
112
+ @test c ≈ d
113
+ @test_throws SingularException A_ldiv_B! (Diagonal (zeros (elty, n)), b)
114
+ b = rand (elty, n+ 1 , n+ 1 )
115
+ b = sparse (b)
116
+ @test_throws DimensionMismatch A_ldiv_B! (D, copy (b))
117
+ b = view (rand (elty, n+ 1 ), collect (1 : n+ 1 ))
118
+ @test_throws DimensionMismatch A_ldiv_B! (D, b)
131
119
end
132
120
end
133
121
end
@@ -163,15 +151,15 @@ srand(1)
163
151
@test D\ D2 ≈ Diagonal (D2. diag./ D. diag)
164
152
165
153
# Performance specialisations for A*_mul_B!
166
- vv = similar (v )
167
- @test (r = full (D) * v ; A_mul_B! (vv , D, v ) ≈ r ≈ vv )
168
- @test (r = full (D)' * v ; Ac_mul_B! (vv , D, v ) ≈ r ≈ vv )
169
- @test (r = full (D).' * v ; At_mul_B! (vv , D, v ) ≈ r ≈ vv )
154
+ vvv = similar (vv )
155
+ @test (r = full (D) * vv ; A_mul_B! (vvv , D, vv ) ≈ r ≈ vvv )
156
+ @test (r = full (D)' * vv ; Ac_mul_B! (vvv , D, vv ) ≈ r ≈ vvv )
157
+ @test (r = full (D).' * vv ; At_mul_B! (vvv , D, vv ) ≈ r ≈ vvv )
170
158
171
- UU = similar (U )
172
- @test (r = full (D) * U ; A_mul_B! (UU , D, U ) ≈ r ≈ UU )
173
- @test (r = full (D)' * U ; Ac_mul_B! (UU , D, U ) ≈ r ≈ UU )
174
- @test (r = full (D).' * U ; At_mul_B! (UU , D, U ) ≈ r ≈ UU )
159
+ UUU = similar (UU )
160
+ @test (r = full (D) * UU ; A_mul_B! (UUU , D, UU ) ≈ r ≈ UUU )
161
+ @test (r = full (D)' * UU ; Ac_mul_B! (UUU , D, UU ) ≈ r ≈ UUU )
162
+ @test (r = full (D).' * UU ; At_mul_B! (UUU , D, UU ) ≈ r ≈ UUU )
175
163
176
164
# make sure that A_mul_B{c,t}! works with B as a Diagonal
177
165
VV = Array (D)
@@ -225,8 +213,8 @@ srand(1)
225
213
@test adjoint (D) == conj (D)
226
214
end
227
215
# Translates to Ac/t_mul_B, which is specialized after issue 21286
228
- @test (D' * v == conj (D) * v )
229
- @test (D.' * v == D * v )
216
+ @test (D' * vv == conj (D) * vv )
217
+ @test (D.' * vv == D * vv )
230
218
end
231
219
232
220
# logdet
0 commit comments