Skip to content

Commit c81a9ad

Browse files
authored
Merge pull request #178 from haampie/improve-coverage
Remove unused iterable constructors and add missing tests for initial guess for x
2 parents c69a85e + cb0cb43 commit c81a9ad

File tree

9 files changed

+47
-36
lines changed

9 files changed

+47
-36
lines changed

src/bicgstabl.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ mutable struct BiCGStabIterable{precT, matT, solT, vecT <: AbstractVector, small
2424
M::smallMatT
2525
end
2626

27-
bicgstabl_iterator(A, b, l; kwargs...) = bicgstabl_iterator!(zerox(A, b), A, b, l; initial_zero = true, kwargs...)
28-
2927
function bicgstabl_iterator!(x, A, b, l::Int = 2;
3028
Pl = Identity(),
3129
max_mv_products = size(A, 2),

src/cg.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Base: start, next, done
22

3-
export cg, cg!, CGIterable, PCGIterable, cg_iterator, cg_iterator!
3+
export cg, cg!, CGIterable, PCGIterable, cg_iterator!
44

55
mutable struct CGIterable{matT, solT, vecT, numT <: Real}
66
A::matT
@@ -92,8 +92,6 @@ end
9292

9393
# Utility functions
9494

95-
@inline cg_iterator(A, b, Pl = Identity(); kwargs...) = cg_iterator!(zerox(A, b), A, b, Pl; initially_zero = true, kwargs...)
96-
9795
function cg_iterator!(x, A, b, Pl = Identity();
9896
tol = sqrt(eps(real(eltype(b)))),
9997
maxiter::Int = size(A, 2),

src/chebyshev.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ function next(cheb::ChebyshevIterable, iteration::Int)
5454
cheb.resnorm, iteration + 1
5555
end
5656

57-
chebyshev_iterable(A, b, λmin::Real, λmax::Real; kwargs...) =
58-
chebyshev_iterable!(zerox(A, b), A, b, λmin, λmax; kwargs...)
59-
6057
function chebyshev_iterable!(x, A, b, λmin::Real, λmax::Real;
6158
tol = sqrt(eps(real(eltype(b)))), maxiter = size(A, 2), Pl = Identity(), initially_zero = false)
6259

src/gmres.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ function next(g::GMRESIterable, iteration::Int)
9898
g.residual.current, iteration + 1
9999
end
100100

101-
gmres_iterable(A, b; kwargs...) = gmres_iterable!(zerox(A, b), A, b; initially_zero = true, kwargs...)
102-
103101
function gmres_iterable!(x, A, b;
104102
Pl = Identity(),
105103
Pr = Identity(),

src/minres.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ mutable struct MINRESIterable{matT, solT, vecT <: DenseVector, smallVecT <: Dens
3636
resnorm::realT
3737
end
3838

39-
minres_iterable(A, b; kwargs...) = minres_iterable!(zerox(A, b), A, b; initially_zero = true, kwargs...)
40-
4139
function minres_iterable!(x, A, b;
4240
initially_zero::Bool = false,
4341
skew_hermitian::Bool = false,

src/simple.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ function powm_iterable!(A, x; tol = eps(real(eltype(A))) * size(A, 2) ^ 3, maxit
5454
PowerMethodIterable(A, x, tol, maxiter, zero(T), similar(x), similar(x), realmax(real(T)))
5555
end
5656

57-
function powm_iterable(A; kwargs...)
58-
x0 = rand(Complex{real(eltype(A))}, size(A, 1))
59-
scale!(x0, one(eltype(A)) / norm(x0))
60-
powm_iterable!(A, x0; kwargs...)
61-
end
62-
6357
"""
6458
powm(B; kwargs...) -> λ, x, [history]
6559

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)