Skip to content

Commit cb0cb43

Browse files
committed
Add missing tests for given initial guess
1 parent 3fafd15 commit cb0cb43

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

test/bicgstabl.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ n = 20
1818
x1, his1 = bicgstabl(A, b, l, max_mv_products = 100, log = true, tol = tol)
1919
@test isa(his1, ConvergenceHistory)
2020
@test norm(A * x1 - b) / norm(b) tol
21+
22+
# With an initial guess
23+
x_guess = rand(T, n)
24+
x2, his2 = bicgstabl!(x_guess, A, b, l, max_mv_products = 100, log = true, tol = tol)
25+
@test isa(his2, ConvergenceHistory)
26+
@test x2 == x_guess
27+
@test norm(A * x2 - b) / norm(b) tol
2128

2229
# Do an exact LU decomp of a nearby matrix
2330
F = lufact(A + rand(T, n, n))
24-
x2, his2 = bicgstabl(A, b, Pl = F, l, max_mv_products = 100, log = true, tol = tol)
25-
@test norm(A * x2 - b) / norm(b) tol
31+
x3, his3 = bicgstabl(A, b, Pl = F, l, max_mv_products = 100, log = true, tol = tol)
32+
@test norm(A * x3 - b) / norm(b) tol
2633
end
2734
end
2835
end

test/chebyshev.jl

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,37 @@ srand(1234321)
2222
@testset "Matrix{$T}" for T in (Float32, Float64, Complex64, Complex128)
2323
A = randSPD(T, n)
2424
b = rand(T, n)
25-
λ_min, λ_max = approx_eigenvalue_bounds(A)
2625
tol = (eps(real(T)))
2726

28-
x, history = chebyshev(A, b, λ_min, λ_max, tol=tol, maxiter=10n, log=true)
29-
@test isa(history, ConvergenceHistory)
30-
@test history.isconverged
31-
@test norm(A * x - b) / norm(b) tol
27+
# Without a preconditioner
28+
begin
29+
λ_min, λ_max = approx_eigenvalue_bounds(A)
30+
x0 = rand(n)
31+
x, history = chebyshev(A, b, λ_min, λ_max, tol=tol, maxiter=10n, log=true)
32+
@test isa(history, ConvergenceHistory)
33+
@test history.isconverged
34+
@test norm(A * x - b) / norm(b) tol
35+
end
3236

33-
# Preconditioned solve
34-
B = randSPD(T, n)
35-
B_fact = cholfact!(B)
36-
λ_min, λ_max = approx_eigenvalue_bounds(B_fact \ A)
37-
x, history = chebyshev(A, b, λ_min, λ_max, Pl = B_fact, tol=tol, maxiter=10n, log=true)
38-
@test history.isconverged
39-
@test norm(A * x - b) / norm(b) tol
37+
# With an initial guess
38+
begin
39+
λ_min, λ_max = approx_eigenvalue_bounds(A)
40+
x0 = rand(T, n)
41+
x, history = chebyshev!(x0, A, b, λ_min, λ_max, tol=tol, maxiter=10n, log=true)
42+
@test isa(history, ConvergenceHistory)
43+
@test history.isconverged
44+
@test x == x0
45+
@test norm(A * x - b) / norm(b) tol
46+
end
47+
48+
# With a preconditioner
49+
begin
50+
B = randSPD(T, n)
51+
B_fact = cholfact!(B)
52+
λ_min, λ_max = approx_eigenvalue_bounds(B_fact \ A)
53+
x, history = chebyshev(A, b, λ_min, λ_max, Pl = B_fact, tol=tol, maxiter=10n, log=true)
54+
@test history.isconverged
55+
@test norm(A * x - b) / norm(b) tol
56+
end
4057
end
4158
end

test/minres.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ n = 15
2727
@testset "Hermitian Matrix{$T}" for T in (Float32, Float64, Complex64, Complex128)
2828
A, x, b = hermitian_problem(T, n)
2929
tol = sqrt(eps(real(T)))
30+
x0 = rand(T, n)
3031

31-
x_approx, hist = minres(A, b, maxiter = 10n, tol = tol, log = true)
32+
x1, hist1 = minres(A, b, maxiter = 10n, tol = tol, log = true)
33+
x2, hist2 = minres!(x0, A, b, maxiter = 10n, tol = tol, log = true)
3234

33-
@test isa(hist, ConvergenceHistory)
34-
@test norm(b - A * x_approx) / norm(b) tol
35-
@test hist.isconverged
35+
@test isa(hist1, ConvergenceHistory)
36+
@test norm(b - A * x1) / norm(b) tol
37+
@test hist1.isconverged
38+
@test norm(b - A * x2) / norm(b) tol
39+
@test x2 == x0
3640
end
3741

3842
@testset "Skew-Hermitian Matrix{$T}" for T in (Float32, Float64, Complex64, Complex128)

0 commit comments

Comments
 (0)