|
3 | 3 | using Test
|
4 | 4 |
|
5 | 5 | @testset "eigs" begin
|
6 |
| - srand(1234) |
7 |
| - n = 10 |
8 |
| - areal = sprandn(n,n,0.4) |
9 |
| - breal = sprandn(n,n,0.4) |
10 |
| - acmplx = complex.(sprandn(n,n,0.4), sprandn(n,n,0.4)) |
11 |
| - bcmplx = complex.(sprandn(n,n,0.4), sprandn(n,n,0.4)) |
12 |
| - |
13 |
| - testtol = 1e-6 |
14 |
| - |
15 |
| - @testset for elty in (Float64, Complex128) |
16 |
| - if elty == Complex64 || elty == Complex128 |
17 |
| - a = acmplx |
18 |
| - b = bcmplx |
19 |
| - else |
20 |
| - a = areal |
21 |
| - b = breal |
22 |
| - end |
23 |
| - a = convert(SparseMatrixCSC{elty}, a) |
24 |
| - asym = a' + a # symmetric indefinite |
25 |
| - apd = a'*a # symmetric positive-definite |
| 6 | + guardsrand(1234) do |
| 7 | + n = 10 |
| 8 | + areal = sprandn(n,n,0.4) |
| 9 | + breal = sprandn(n,n,0.4) |
| 10 | + acmplx = complex.(sprandn(n,n,0.4), sprandn(n,n,0.4)) |
| 11 | + bcmplx = complex.(sprandn(n,n,0.4), sprandn(n,n,0.4)) |
26 | 12 |
|
27 |
| - b = convert(SparseMatrixCSC{elty}, b) |
28 |
| - bsym = b' + b |
29 |
| - bpd = b'*b |
| 13 | + testtol = 1e-6 |
30 | 14 |
|
31 |
| - (d,v) = eigs(a, nev=3) |
32 |
| - @test a*v[:,2] ≈ d[2]*v[:,2] |
33 |
| - @test norm(v) > testtol # eigenvectors cannot be null vectors |
34 |
| - (d,v) = eigs(a, I, nev=3) # test eigs(A, B; kwargs...) |
35 |
| - @test a*v[:,2] ≈ d[2]*v[:,2] |
36 |
| - @test norm(v) > testtol # eigenvectors cannot be null vectors |
37 |
| - @test_warn "Use symbols instead of strings for specifying which eigenvalues to compute" eigs(a, which="LM") |
38 |
| - # (d,v) = eigs(a, b, nev=3, tol=1e-8) # not handled yet |
39 |
| - # @test a*v[:,2] ≈ d[2]*b*v[:,2] atol=testtol |
40 |
| - # @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 15 | + @testset for elty in (Float64, Complex128) |
| 16 | + if elty == Complex64 || elty == Complex128 |
| 17 | + a = acmplx |
| 18 | + b = bcmplx |
| 19 | + else |
| 20 | + a = areal |
| 21 | + b = breal |
| 22 | + end |
| 23 | + a = convert(SparseMatrixCSC{elty}, a) |
| 24 | + asym = a' + a # symmetric indefinite |
| 25 | + apd = a'*a # symmetric positive-definite |
41 | 26 |
|
42 |
| - (d,v) = eigs(asym, nev=3) |
43 |
| - @test asym*v[:,1] ≈ d[1]*v[:,1] |
44 |
| - @test eigs(asym; nev=1, sigma=d[3])[1][1] ≈ d[3] |
45 |
| - @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 27 | + b = convert(SparseMatrixCSC{elty}, b) |
| 28 | + bsym = b' + b |
| 29 | + bpd = b'*b |
46 | 30 |
|
47 |
| - (d,v) = eigs(apd, nev=3) |
48 |
| - @test apd*v[:,3] ≈ d[3]*v[:,3] |
49 |
| - @test eigs(apd; nev=1, sigma=d[3])[1][1] ≈ d[3] |
| 31 | + (d,v) = eigs(a, nev=3) |
| 32 | + @test a*v[:,2] ≈ d[2]*v[:,2] |
| 33 | + @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 34 | + (d,v) = eigs(a, I, nev=3) # test eigs(A, B; kwargs...) |
| 35 | + @test a*v[:,2] ≈ d[2]*v[:,2] |
| 36 | + @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 37 | + @test_warn "Use symbols instead of strings for specifying which eigenvalues to compute" eigs(a, which="LM") |
| 38 | + # (d,v) = eigs(a, b, nev=3, tol=1e-8) # not handled yet |
| 39 | + # @test a*v[:,2] ≈ d[2]*b*v[:,2] atol=testtol |
| 40 | + # @test norm(v) > testtol # eigenvectors cannot be null vectors |
50 | 41 |
|
51 |
| - (d,v) = eigs(apd, bpd, nev=3, tol=1e-8) |
52 |
| - @test apd*v[:,2] ≈ d[2]*bpd*v[:,2] atol=testtol |
53 |
| - @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 42 | + (d,v) = eigs(asym, nev=3) |
| 43 | + @test asym*v[:,1] ≈ d[1]*v[:,1] |
| 44 | + @test eigs(asym; nev=1, sigma=d[3])[1][1] ≈ d[3] |
| 45 | + @test norm(v) > testtol # eigenvectors cannot be null vectors |
54 | 46 |
|
55 |
| - @testset "(shift-and-)invert mode" begin |
56 |
| - (d,v) = eigs(apd, nev=3, sigma=0) |
| 47 | + (d,v) = eigs(apd, nev=3) |
57 | 48 | @test apd*v[:,3] ≈ d[3]*v[:,3]
|
58 |
| - @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 49 | + @test eigs(apd; nev=1, sigma=d[3])[1][1] ≈ d[3] |
59 | 50 |
|
60 |
| - (d,v) = eigs(apd, bpd, nev=3, sigma=0, tol=1e-8) |
61 |
| - @test apd*v[:,1] ≈ d[1]*bpd*v[:,1] atol=testtol |
| 51 | + (d,v) = eigs(apd, bpd, nev=3, tol=1e-8) |
| 52 | + @test apd*v[:,2] ≈ d[2]*bpd*v[:,2] atol=testtol |
62 | 53 | @test norm(v) > testtol # eigenvectors cannot be null vectors
|
63 |
| - end |
64 | 54 |
|
65 |
| - @testset "ArgumentErrors" begin |
66 |
| - @test_throws ArgumentError eigs(rand(elty,2,2)) |
67 |
| - @test_throws ArgumentError eigs(a, nev=-1) |
68 |
| - @test_throws ArgumentError eigs(a, which=:Z) |
69 |
| - @test_throws ArgumentError eigs(a, which=:BE) |
70 |
| - @test_throws DimensionMismatch eigs(a, v0=zeros(elty,n+2)) |
71 |
| - @test_throws ArgumentError eigs(a, v0=zeros(Int,n)) |
72 |
| - if elty == Float64 |
73 |
| - @test_throws ArgumentError eigs(a+a.',which=:SI) |
74 |
| - @test_throws ArgumentError eigs(a+a.',which=:LI) |
75 |
| - @test_throws ArgumentError eigs(a,sigma=rand(Complex64)) |
| 55 | + @testset "(shift-and-)invert mode" begin |
| 56 | + (d,v) = eigs(apd, nev=3, sigma=0) |
| 57 | + @test apd*v[:,3] ≈ d[3]*v[:,3] |
| 58 | + @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 59 | + |
| 60 | + (d,v) = eigs(apd, bpd, nev=3, sigma=0, tol=1e-8) |
| 61 | + @test apd*v[:,1] ≈ d[1]*bpd*v[:,1] atol=testtol |
| 62 | + @test norm(v) > testtol # eigenvectors cannot be null vectors |
| 63 | + end |
| 64 | + |
| 65 | + @testset "ArgumentErrors" begin |
| 66 | + @test_throws ArgumentError eigs(rand(elty,2,2)) |
| 67 | + @test_throws ArgumentError eigs(a, nev=-1) |
| 68 | + @test_throws ArgumentError eigs(a, which=:Z) |
| 69 | + @test_throws ArgumentError eigs(a, which=:BE) |
| 70 | + @test_throws DimensionMismatch eigs(a, v0=zeros(elty,n+2)) |
| 71 | + @test_throws ArgumentError eigs(a, v0=zeros(Int,n)) |
| 72 | + if elty == Float64 |
| 73 | + @test_throws ArgumentError eigs(a+a.',which=:SI) |
| 74 | + @test_throws ArgumentError eigs(a+a.',which=:LI) |
| 75 | + @test_throws ArgumentError eigs(a,sigma=rand(Complex64)) |
| 76 | + end |
76 | 77 | end
|
77 | 78 | end
|
78 |
| - end |
79 | 79 |
|
80 |
| - @testset "Symmetric generalized with singular B" begin |
81 |
| - n = 10 |
82 |
| - k = 3 |
83 |
| - A = randn(n,n); A = A'A |
84 |
| - B = randn(n,k); B = B*B' |
85 |
| - @test sort(eigs(A, B, nev = k, sigma = 1.0)[1]) ≈ sort(eigvals(A, B)[1:k]) |
| 80 | + @testset "Symmetric generalized with singular B" begin |
| 81 | + n = 10 |
| 82 | + k = 3 |
| 83 | + A = randn(n,n); A = A'A |
| 84 | + B = randn(n,k); B = B*B' |
| 85 | + @test sort(eigs(A, B, nev = k, sigma = 1.0)[1]) ≈ sort(eigvals(A, B)[1:k]) |
| 86 | + end |
86 | 87 | end
|
87 | 88 | end
|
88 | 89 |
|
|
0 commit comments