Skip to content

Commit 6c4fdb1

Browse files
committed
some test streamline
1 parent 125a55a commit 6c4fdb1

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

test/eig.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ end
4545
atol = sqrt(eps(real(T)))
4646

4747
D1, V1, ϵ1 = @constinferred eig_trunc(A; alg, trunc = truncrank(r))
48-
@test length(D1.diag) == r
48+
@test length(diagview(D1)) == r
4949
@test A * V1 V1 * D1
5050
@test ϵ1 norm(view(D₀, (r + 1):m)) atol = atol
5151

@@ -81,13 +81,13 @@ end
8181
A = V * D * inv(V)
8282
alg = TruncatedAlgorithm(LAPACK_Simple(), truncrank(2))
8383
D2, V2, ϵ2 = @constinferred eig_trunc(A; alg)
84-
@test diagview(D2) diagview(D)[1:2] rtol = sqrt(eps(real(T)))
84+
@test diagview(D2) diagview(D)[1:2]
8585
@test ϵ2 norm(diagview(D)[3:4]) atol = atol
8686
@test_throws ArgumentError eig_trunc(A; alg, trunc = (; maxrank = 2))
8787

8888
alg = TruncatedAlgorithm(LAPACK_Simple(), truncerror(; atol = 0.2, p = 1))
8989
D3, V3, ϵ3 = @constinferred eig_trunc(A; alg)
90-
@test diagview(D3) diagview(D)[1:2] rtol = sqrt(eps(real(T)))
90+
@test diagview(D3) diagview(D)[1:2]
9191
@test ϵ3 norm(diagview(D)[3:4]) atol = atol
9292
end
9393

test/eigh.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ end
9090
A = (A + A') / 2
9191
alg = TruncatedAlgorithm(LAPACK_QRIteration(), truncrank(2))
9292
D2, V2, ϵ2 = @constinferred eigh_trunc(A; alg)
93-
@test diagview(D2) diagview(D)[1:2] rtol = sqrt(eps(real(T)))
93+
@test diagview(D2) diagview(D)[1:2]
9494
@test_throws ArgumentError eigh_trunc(A; alg, trunc = (; maxrank = 2))
9595
@test ϵ2 norm(diagview(D)[3:4]) atol = atol
9696

9797
alg = TruncatedAlgorithm(LAPACK_QRIteration(), truncerror(; atol = 0.2))
9898
D3, V3, ϵ3 = @constinferred eigh_trunc(A; alg)
99-
@test diagview(D3) diagview(D)[1:2] rtol = sqrt(eps(real(T)))
99+
@test diagview(D3) diagview(D)[1:2]
100100
@test ϵ3 norm(diagview(D)[3:4]) atol = atol
101101
end
102102

test/svd.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ end
115115
r = minmn - 2
116116

117117
U1, S1, V1ᴴ, ϵ1 = @constinferred svd_trunc(A; alg, trunc = truncrank(r))
118-
@test length(S1.diag) == r
118+
@test length(diagview(S1)) == r
119+
@test diagview(S1) S₀[1:r]
119120
@test LinearAlgebra.opnorm(A - U1 * S1 * V1ᴴ) S₀[r + 1]
120121
# Test truncation error
121122
@test ϵ1 norm(view(S₀, (r + 1):minmn)) atol = atol
@@ -124,19 +125,19 @@ end
124125
trunc = trunctol(; atol = s * S₀[r + 1])
125126

126127
U2, S2, V2ᴴ, ϵ2 = @constinferred svd_trunc(A; alg, trunc)
127-
@test length(S2.diag) == r
128+
@test length(diagview(S2)) == r
128129
@test U1 U2
129130
@test S1 S2
130131
@test V1ᴴ V2ᴴ
131-
@test ϵ2 ϵ1
132+
@test ϵ2 norm(view(S₀, (r + 1):minmn)) atol = atol
132133

133134
trunc = truncerror(; atol = s * norm(@view(S₀[(r + 1):end])))
134135
U3, S3, V3ᴴ, ϵ3 = @constinferred svd_trunc(A; alg, trunc)
135-
@test length(S3.diag) == r
136+
@test length(diagview(S3)) == r
136137
@test U1 U3
137138
@test S1 S3
138139
@test V1ᴴ V3ᴴ
139-
@test ϵ3 ϵ1
140+
@test ϵ3 norm(view(S₀, (r + 1):minmn)) atol = atol
140141
end
141142
end
142143
end
@@ -162,27 +163,28 @@ end
162163
(rtol, maxrank) -> truncrank(maxrank) & trunctol(; rtol),
163164
)
164165
U1, S1, V1ᴴ, ϵ1 = svd_trunc(A; alg, trunc = trunc_fun(0.2, 1))
165-
@test length(S1.diag) == 1
166-
@test S1.diag S.diag[1:1] rtol = sqrt(eps(real(T)))
166+
@test length(diagview(S1)) == 1
167+
@test diagview(S1) diagview(S)[1:1]
167168

168169
U2, S2, V2ᴴ, ϵ2 = svd_trunc(A; alg, trunc = trunc_fun(0.2, 3))
169-
@test length(S2.diag) == 2
170-
@test S2.diag S.diag[1:2] rtol = sqrt(eps(real(T)))
170+
@test length(diagview(S2)) == 2
171+
@test diagview(S2) diagview(S)[1:2]
171172
end
172173
end
173174
end
174175

175176
@testset "svd_trunc! specify truncation algorithm T = $T" for T in BLASFloats
176177
rng = StableRNG(123)
178+
atol = sqrt(eps(real(T)))
177179
m = 4
178180
U = qr_compact(randn(rng, T, m, m))[1]
179181
S = Diagonal(real(T)[0.9, 0.3, 0.1, 0.01])
180182
Vᴴ = qr_compact(randn(rng, T, m, m))[1]
181183
A = U * S * Vᴴ
182184
alg = TruncatedAlgorithm(LAPACK_DivideAndConquer(), trunctol(; atol = 0.2))
183185
U2, S2, V2ᴴ, ϵ2 = @constinferred svd_trunc(A; alg)
184-
@test diagview(S2) diagview(S)[1:2] rtol = sqrt(eps(real(T)))
185-
@test ϵ2 norm(diagview(S)[3:4])
186+
@test diagview(S2) diagview(S)[1:2]
187+
@test ϵ2 norm(diagview(S)[3:4]) atol = atol
186188
@test_throws ArgumentError svd_trunc(A; alg, trunc = (; maxrank = 2))
187189
end
188190

0 commit comments

Comments
 (0)