@@ -4,118 +4,118 @@ using IterativeEigensolvers
4
4
using Test
5
5
6
6
@testset " eigs" begin
7
- guardsrand (1234 ) do
8
- n = 10
9
- areal = sprandn (n,n,0.4 )
10
- breal = sprandn (n,n,0.4 )
11
- acmplx = complex .(sprandn (n,n,0.4 ), sprandn (n,n,0.4 ))
12
- bcmplx = complex .(sprandn (n,n,0.4 ), sprandn (n,n,0.4 ))
7
+ srand (1234 )
8
+ n = 10
9
+ areal = sprandn (n,n,0.4 )
10
+ breal = sprandn (n,n,0.4 )
11
+ acmplx = complex .(sprandn (n,n,0.4 ), sprandn (n,n,0.4 ))
12
+ bcmplx = complex .(sprandn (n,n,0.4 ), sprandn (n,n,0.4 ))
13
13
14
- testtol = 1e-6
14
+ testtol = 1e-6
15
15
16
- @testset for elty in (Float64, ComplexF64)
17
- if elty == ComplexF32 || elty == ComplexF64
18
- a = acmplx
19
- b = bcmplx
20
- else
21
- a = areal
22
- b = breal
23
- end
24
- a_evs = eigvals (Array (a))
25
- a = convert (SparseMatrixCSC{elty}, a)
26
- asym = a' + a # symmetric indefinite
27
- apd = a' * a # symmetric positive-definite
16
+ @testset for elty in (Float64, ComplexF64)
17
+ if elty == ComplexF32 || elty == ComplexF64
18
+ a = acmplx
19
+ b = bcmplx
20
+ else
21
+ a = areal
22
+ b = breal
23
+ end
24
+ a_evs = eigvals (Array (a))
25
+ a = convert (SparseMatrixCSC{elty}, a)
26
+ asym = a' + a # symmetric indefinite
27
+ apd = a' * a # symmetric positive-definite
28
28
29
- b = convert (SparseMatrixCSC{elty}, b)
30
- bsym = b' + b
31
- bpd = b' * b
29
+ b = convert (SparseMatrixCSC{elty}, b)
30
+ bsym = b' + b
31
+ bpd = b' * b
32
32
33
- (d,v) = eigs (a, nev= 3 )
34
- @test a* v[:,2 ] ≈ d[2 ]* v[:,2 ]
35
- @test norm (v) > testtol # eigenvectors cannot be null vectors
36
- (d,v) = eigs (a, I, nev= 3 ) # test eigs(A, B; kwargs...)
37
- @test a* v[:,2 ] ≈ d[2 ]* v[:,2 ]
38
- @test norm (v) > testtol # eigenvectors cannot be null vectors
39
- @test_logs (:warn ," Use symbols instead of strings for specifying which eigenvalues to compute" ) eigs (a, which= " LM" )
40
- @test_logs (:warn ," Adjusting ncv from 1 to 4" ) eigs (a, ncv= 1 , nev= 2 )
41
- @test_logs (:warn ," Adjusting nev from $n to $(n- 2 ) " ) eigs (a, nev= n)
42
- # (d,v) = eigs(a, b, nev=3, tol=1e-8) # not handled yet
43
- # @test a*v[:,2] ≈ d[2]*b*v[:,2] atol=testtol
44
- # @test norm(v) > testtol # eigenvectors cannot be null vectors
45
- if elty <: Base.LinAlg.BlasComplex
46
- sr_ind = indmin (real .(a_evs))
47
- (d, v) = eigs (a, nev= 1 , which= :SR )
48
- @test d[1 ] ≈ a_evs[sr_ind]
49
- si_ind = indmin (imag .(a_evs))
50
- (d, v) = eigs (a, nev= 1 , which= :SI )
51
- @test d[1 ] ≈ a_evs[si_ind]
52
- lr_ind = indmax (real .(a_evs))
53
- (d, v) = eigs (a, nev= 1 , which= :LR )
54
- @test d[1 ] ≈ a_evs[lr_ind]
55
- li_ind = indmax (imag .(a_evs))
56
- (d, v) = eigs (a, nev= 1 , which= :LI )
57
- @test d[1 ] ≈ a_evs[li_ind]
58
- end
33
+ (d,v) = eigs (a, nev= 3 )
34
+ @test a* v[:,2 ] ≈ d[2 ]* v[:,2 ]
35
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
36
+ (d,v) = eigs (a, I, nev= 3 ) # test eigs(A, B; kwargs...)
37
+ @test a* v[:,2 ] ≈ d[2 ]* v[:,2 ]
38
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
39
+ @test_logs (:warn ," Use symbols instead of strings for specifying which eigenvalues to compute" ) eigs (a, which= " LM" )
40
+ @test_logs (:warn ," Adjusting ncv from 1 to 4" ) eigs (a, ncv= 1 , nev= 2 )
41
+ @test_logs (:warn ," Adjusting nev from $n to $(n- 2 ) " ) eigs (a, nev= n)
42
+ # (d,v) = eigs(a, b, nev=3, tol=1e-8) # not handled yet
43
+ # @test a*v[:,2] ≈ d[2]*b*v[:,2] atol=testtol
44
+ # @test norm(v) > testtol # eigenvectors cannot be null vectors
45
+ if elty <: Base.LinAlg.BlasComplex
46
+ sr_ind = indmin (real .(a_evs))
47
+ (d, v) = eigs (a, nev= 1 , which= :SR )
48
+ @test d[1 ] ≈ a_evs[sr_ind]
49
+ si_ind = indmin (imag .(a_evs))
50
+ (d, v) = eigs (a, nev= 1 , which= :SI )
51
+ @test d[1 ] ≈ a_evs[si_ind]
52
+ lr_ind = indmax (real .(a_evs))
53
+ (d, v) = eigs (a, nev= 1 , which= :LR )
54
+ @test d[1 ] ≈ a_evs[lr_ind]
55
+ li_ind = indmax (imag .(a_evs))
56
+ (d, v) = eigs (a, nev= 1 , which= :LI )
57
+ @test d[1 ] ≈ a_evs[li_ind]
58
+ end
59
59
60
- (d,v) = eigs (asym, nev= 3 )
61
- @test asym* v[:,1 ] ≈ d[1 ]* v[:,1 ]
62
- @test eigs (asym; nev= 1 , sigma= d[3 ])[1 ][1 ] ≈ d[3 ]
63
- @test norm (v) > testtol # eigenvectors cannot be null vectors
60
+ (d,v) = eigs (asym, nev= 3 )
61
+ @test asym* v[:,1 ] ≈ d[1 ]* v[:,1 ]
62
+ @test eigs (asym; nev= 1 , sigma= d[3 ])[1 ][1 ] ≈ d[3 ]
63
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
64
64
65
- (d,v) = eigs (apd, nev= 3 )
66
- @test apd* v[:,3 ] ≈ d[3 ]* v[:,3 ]
67
- @test eigs (apd; nev= 1 , sigma= d[3 ])[1 ][1 ] ≈ d[3 ]
65
+ (d,v) = eigs (apd, nev= 3 )
66
+ @test apd* v[:,3 ] ≈ d[3 ]* v[:,3 ]
67
+ @test eigs (apd; nev= 1 , sigma= d[3 ])[1 ][1 ] ≈ d[3 ]
68
68
69
- (d,v) = eigs (apd, bpd, nev= 3 , tol= 1e-8 )
70
- @test apd* v[:,2 ] ≈ d[2 ]* bpd* v[:,2 ] atol= testtol
71
- @test norm (v) > testtol # eigenvectors cannot be null vectors
69
+ (d,v) = eigs (apd, bpd, nev= 3 , tol= 1e-8 )
70
+ @test apd* v[:,2 ] ≈ d[2 ]* bpd* v[:,2 ] atol= testtol
71
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
72
72
73
- @testset " (shift-and-)invert mode" begin
74
- (d,v) = eigs (apd, nev= 3 , sigma= 0 )
75
- @test apd* v[:,3 ] ≈ d[3 ]* v[:,3 ]
76
- @test norm (v) > testtol # eigenvectors cannot be null vectors
73
+ @testset " (shift-and-)invert mode" begin
74
+ (d,v) = eigs (apd, nev= 3 , sigma= 0 )
75
+ @test apd* v[:,3 ] ≈ d[3 ]* v[:,3 ]
76
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
77
77
78
- (d,v) = eigs (apd, bpd, nev= 3 , sigma= 0 , tol= 1e-8 )
79
- @test apd* v[:,1 ] ≈ d[1 ]* bpd* v[:,1 ] atol= testtol
80
- @test norm (v) > testtol # eigenvectors cannot be null vectors
81
- end
78
+ (d,v) = eigs (apd, bpd, nev= 3 , sigma= 0 , tol= 1e-8 )
79
+ @test apd* v[:,1 ] ≈ d[1 ]* bpd* v[:,1 ] atol= testtol
80
+ @test norm (v) > testtol # eigenvectors cannot be null vectors
81
+ end
82
82
83
- @testset " ArgumentErrors" begin
84
- @test_throws ArgumentError eigs (rand (elty,2 ,2 ))
85
- @test_throws ArgumentError eigs (a, nev= - 1 )
86
- @test_throws ArgumentError eigs (a, which= :Z )
87
- @test_throws ArgumentError eigs (a, which= :BE )
88
- @test_throws DimensionMismatch eigs (a, v0= zeros (elty,n+ 2 ))
89
- @test_throws ArgumentError eigs (a, v0= zeros (Int,n))
90
- if elty == Float64
91
- @test_throws ArgumentError eigs (a+ a.' ,which= :SI )
92
- @test_throws ArgumentError eigs (a+ a.' ,which= :LI )
93
- @test_throws ArgumentError eigs (a,sigma= rand (ComplexF32))
94
- end
83
+ @testset " ArgumentErrors" begin
84
+ @test_throws ArgumentError eigs (rand (elty,2 ,2 ))
85
+ @test_throws ArgumentError eigs (a, nev= - 1 )
86
+ @test_throws ArgumentError eigs (a, which= :Z )
87
+ @test_throws ArgumentError eigs (a, which= :BE )
88
+ @test_throws DimensionMismatch eigs (a, v0= zeros (elty,n+ 2 ))
89
+ @test_throws ArgumentError eigs (a, v0= zeros (Int,n))
90
+ if elty == Float64
91
+ @test_throws ArgumentError eigs (a+ a.' ,which= :SI )
92
+ @test_throws ArgumentError eigs (a+ a.' ,which= :LI )
93
+ @test_throws ArgumentError eigs (a,sigma= rand (ComplexF32))
95
94
end
96
95
end
96
+ end
97
97
98
- @testset " Symmetric generalized with singular B" begin
99
- n = 10
100
- k = 3
101
- A = randn (n,n); A = A ' A
102
- B = randn (n,k ); B = B * B '
103
- @test sort ( eigs (A, B, nev = k, sigma = 1.0 )[ 1 ]) ≈ sort ( eigvals (A, B)[ 1 : k])
104
- end
98
+ @testset " Symmetric generalized with singular B" begin
99
+ srand ( 124 )
100
+ n = 10
101
+ k = 3
102
+ A = randn (n,n ); A = A ' A
103
+ B = randn (n,k); B = B * B '
104
+ @test sort ( eigs (A, B, nev = k, sigma = 1.0 )[ 1 ]) ≈ sort ( eigvals (A, B)[ 1 : k])
105
105
end
106
106
end
107
107
108
108
# Problematic example from #6965A
109
109
let A6965 = [
110
- 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
111
- - 1.0 2.0 0.0 0.0 0.0 0.0 0.0 1.0
112
- - 1.0 0.0 3.0 0.0 0.0 0.0 0.0 1.0
113
- - 1.0 0.0 0.0 4.0 0.0 0.0 0.0 1.0
114
- - 1.0 0.0 0.0 0.0 5.0 0.0 0.0 1.0
115
- - 1.0 0.0 0.0 0.0 0.0 6.0 0.0 1.0
116
- - 1.0 0.0 0.0 0.0 0.0 0.0 7.0 1.0
117
- - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 8.0
118
- ]
110
+ 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
111
+ - 1.0 2.0 0.0 0.0 0.0 0.0 0.0 1.0
112
+ - 1.0 0.0 3.0 0.0 0.0 0.0 0.0 1.0
113
+ - 1.0 0.0 0.0 4.0 0.0 0.0 0.0 1.0
114
+ - 1.0 0.0 0.0 0.0 5.0 0.0 0.0 1.0
115
+ - 1.0 0.0 0.0 0.0 0.0 6.0 0.0 1.0
116
+ - 1.0 0.0 0.0 0.0 0.0 0.0 7.0 1.0
117
+ - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 8.0
118
+ ]
119
119
d, = eigs (A6965,which= :SM ,nev= 2 ,ncv= 4 ,tol= eps ())
120
120
@test d[1 ] ≈ 2.5346936860350002
121
121
@test real (d[2 ]) ≈ 2.6159972444834976
0 commit comments