@@ -25,6 +25,7 @@ Random.seed!(1234321)
25
25
A = randSPD (T, n)
26
26
b = rand (T, n)
27
27
reltol = √ (eps (real (T)))
28
+ abstol = reltol
28
29
29
30
@testset " Without preconditioner" begin
30
31
λ_min, λ_max = approx_eigenvalue_bounds (A)
@@ -38,11 +39,19 @@ Random.seed!(1234321)
38
39
@testset " With an initial guess" begin
39
40
λ_min, λ_max = approx_eigenvalue_bounds (A)
40
41
x0 = rand (T, n)
42
+ initial_residual = norm (A * x0 - b)
41
43
x, history = chebyshev! (x0, A, b, λ_min, λ_max, reltol= reltol, maxiter= 10 n, log= true )
42
44
@test isa (history, ConvergenceHistory)
43
45
@test history. isconverged
44
46
@test x == x0
45
- @test norm (A * x - b) / norm (b) ≤ reltol
47
+ @test norm (A * x - b) ≤ reltol * initial_residual
48
+
49
+ x0 = rand (T, n)
50
+ x, history = chebyshev! (x0, A, b, λ_min, λ_max, abstol= abstol, reltol= zero (real (T)), maxiter= 10 n, log= true )
51
+ @test isa (history, ConvergenceHistory)
52
+ @test history. isconverged
53
+ @test x == x0
54
+ @test norm (A * x - b) ≤ 2 * abstol
46
55
end
47
56
48
57
@testset " With a preconditioner" begin
@@ -54,4 +63,31 @@ Random.seed!(1234321)
54
63
@test norm (A * x - b) / norm (b) ≤ reltol
55
64
end
56
65
end
66
+
67
+ @testset " Termination criterion" begin
68
+ for T in (Float32, Float64, ComplexF32, ComplexF64)
69
+ A = T[ 2 - 1 0
70
+ - 1 2 - 1
71
+ 0 - 1 2 ]
72
+ n = size (A, 2 )
73
+ b = ones (T, n)
74
+ x0 = A \ b
75
+ perturbation = T[(- 1 )^ i for i in 1 : n]
76
+ λ_min, λ_max = approx_eigenvalue_bounds (A)
77
+
78
+ # If the initial residual is small and a small relative tolerance is used,
79
+ # many iterations are necessary
80
+ x = x0 + sqrt (eps (real (T))) * perturbation
81
+ initial_residual = norm (A * x - b)
82
+ x, ch = chebyshev! (x, A, b, λ_min, λ_max, log= true )
83
+ @test 2 ≤ niters (ch) ≤ n
84
+
85
+ # If the initial residual is small and a large absolute tolerance is used,
86
+ # no iterations are necessary
87
+ x = x0 + 10 * sqrt (eps (real (T))) * perturbation
88
+ initial_residual = norm (A * x - b)
89
+ x, ch = chebyshev! (x, A, b, λ_min, λ_max, abstol= 2 * initial_residual, reltol= zero (real (T)), log= true )
90
+ @test niters (ch) == 0
91
+ end
92
+ end
57
93
end
0 commit comments