Skip to content

Commit 6b5cd8d

Browse files
committed
Setup D0
1 parent 7313bd1 commit 6b5cd8d

2 files changed

Lines changed: 45 additions & 46 deletions

File tree

test/testsuite/eig.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function test_eig_trunc(
7878
Ac = deepcopy(A)
7979
Tc = complex(eltype(T))
8080
# eigenvalues are sorted by ascending real component...
81-
D₀ = sort!(eig_vals(A); by = abs, rev = true)
81+
D₀ = collect(sort!(eig_vals(A); by = abs, rev = true))
8282
m = size(A, 1)
8383
rmin = findfirst(i -> abs(D₀[end - i]) != abs(D₀[end - i - 1]), 1:(m - 2))
8484
r = length(D₀) - rmin
@@ -150,7 +150,7 @@ function test_eig_trunc_algs(
150150
Ac = deepcopy(A)
151151
Tc = complex(eltype(T))
152152
# eigenvalues are sorted by ascending real component...
153-
D₀ = sort!(eig_vals(A; alg); by = abs, rev = true)
153+
D₀ = collect(sort!(eig_vals(A; alg); by = abs, rev = true))
154154
m = size(A, 1)
155155
rmin = findfirst(i -> abs(D₀[end - i]) != abs(D₀[end - i - 1]), 1:(m - 2))
156156
r = length(D₀) - rmin

test/testsuite/eigh.jl

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -76,50 +76,49 @@ function test_eigh_trunc(
7676
A = A * A'
7777
A = project_hermitian!(A)
7878
Ac = deepcopy(A)
79-
if !(T <: Diagonal)
8079

81-
m = size(A, 1)
82-
D₀ = reverse(eigh_vals(A))
83-
r = m - 2
84-
s = 1 + sqrt(eps(real(eltype(T))))
85-
atol = sqrt(eps(real(eltype(T))))
86-
# truncrank
87-
D1, V1, ϵ1 = @testinferred eigh_trunc(A; trunc = truncrank(r))
88-
@test length(diagview(D1)) == r
89-
@test isisometric(V1)
90-
@test A * V1 V1 * D1
91-
@test opnorm(A - V1 * D1 * V1') D₀[r + 1]
92-
@test ϵ1 norm(view(D₀, (r + 1):m)) atol = atol
93-
94-
# trunctol
95-
trunc = trunctol(; atol = s * D₀[r + 1])
96-
D2, V2, ϵ2 = @testinferred eigh_trunc(A; trunc)
97-
@test length(diagview(D2)) == r
98-
@test isisometric(V2)
99-
@test A * V2 V2 * D2
100-
@test ϵ2 norm(view(D₀, (r + 1):m)) atol = atol
101-
102-
#truncerror
103-
s = 1 - sqrt(eps(real(eltype(T))))
104-
trunc = truncerror(; atol = s * norm(@view(D₀[r:end]), 1), p = 1)
105-
D3, V3, ϵ3 = @testinferred eigh_trunc(A; trunc)
106-
@test length(diagview(D3)) == r
107-
@test A * V3 V3 * D3
108-
@test ϵ3 norm(view(D₀, (r + 1):m)) atol = atol
109-
110-
s = 1 - sqrt(eps(real(eltype(T))))
111-
trunc = truncerror(; atol = s * norm(@view(D₀[r:end]), 1), p = 1)
112-
D4, V4 = @testinferred eigh_trunc_no_error(A; trunc)
113-
@test length(diagview(D4)) == r
114-
@test A * V4 V4 * D4
115-
116-
# test for same subspace
117-
@test V1 * (V1' * V2) V2
118-
@test V2 * (V2' * V1) V1
119-
@test V1 * (V1' * V3) V3
120-
@test V3 * (V3' * V1) V1
121-
@test V4 * (V4' * V1) V1
122-
end
80+
m = size(A, 1)
81+
D₀ = collect(reverse(eigh_vals(A)))
82+
r = m - 2
83+
s = 1 + sqrt(eps(real(eltype(T))))
84+
atol = sqrt(eps(real(eltype(T))))
85+
# truncrank
86+
D1, V1, ϵ1 = @testinferred eigh_trunc(A; trunc = truncrank(r))
87+
@test length(diagview(D1)) == r
88+
@test isisometric(V1)
89+
@test A * V1 V1 * D1
90+
@test opnorm(A - V1 * D1 * V1') D₀[r + 1]
91+
@test ϵ1 norm(view(D₀, (r + 1):m)) atol = atol
92+
93+
# trunctol
94+
trunc = trunctol(; atol = s * D₀[r + 1])
95+
D2, V2, ϵ2 = @testinferred eigh_trunc(A; trunc)
96+
@test length(diagview(D2)) == r
97+
@test isisometric(V2)
98+
@test A * V2 V2 * D2
99+
@test ϵ2 norm(view(D₀, (r + 1):m)) atol = atol
100+
101+
#truncerror
102+
s = 1 - sqrt(eps(real(eltype(T))))
103+
trunc = truncerror(; atol = s * norm(@view(D₀[r:end]), 1), p = 1)
104+
D3, V3, ϵ3 = @testinferred eigh_trunc(A; trunc)
105+
@test length(diagview(D3)) == r
106+
@test A * V3 V3 * D3
107+
@test ϵ3 norm(view(D₀, (r + 1):m)) atol = atol
108+
109+
s = 1 - sqrt(eps(real(eltype(T))))
110+
trunc = truncerror(; atol = s * norm(@view(D₀[r:end]), 1), p = 1)
111+
D4, V4 = @testinferred eigh_trunc_no_error(A; trunc)
112+
@test length(diagview(D4)) == r
113+
@test A * V4 V4 * D4
114+
115+
# test for same subspace
116+
@test V1 * (V1' * V2) V2
117+
@test V2 * (V2' * V1) V1
118+
@test V1 * (V1' * V3) V3
119+
@test V3 * (V3' * V1) V1
120+
@test V4 * (V4' * V1) V1
121+
123122
@testset "specify truncation algorithm" begin
124123
atol = sqrt(eps(real(eltype(T))))
125124
m4 = 4
@@ -156,7 +155,7 @@ function test_eigh_trunc_algs(
156155
Ac = deepcopy(A)
157156

158157
m = size(A, 1)
159-
D₀ = reverse(eigh_vals(A))
158+
D₀ = collect(reverse(eigh_vals(A)))
160159
r = m - 2
161160
s = 1 + sqrt(eps(real(eltype(T))))
162161
# truncrank

0 commit comments

Comments
 (0)