Skip to content

Commit

Permalink
Fix off-by-one error in iteration count of IDR(s) (#158)
Browse files Browse the repository at this point in the history
* Fix off-by-one error in iteration count

* Add test for # of iterations in IDR(s)
  • Loading branch information
haampie authored and andreasnoack committed Aug 17, 2017
1 parent c2a6698 commit fa377a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/idrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
verbose && @printf("=== idrs ===\n%4s\t%7s\n","iter","resnorm")
R = C - op(X, args...)::T
normR = vecnorm(R)
iter = 0
iter = 1

if smoothing
X_s = copy(X)
Expand All @@ -76,7 +76,7 @@ function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
c = zeros(eltype(C),s)

om::eltype(C) = 1
while normR > tol && iter < maxiter
while normR > tol && iter maxiter
for i in 1:s,
f[i] = vecdot(P[i], R)
end
Expand Down Expand Up @@ -144,16 +144,15 @@ function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
end
push!(log, :resnorm, normR)
verbose && @printf("%3d\t%1.2e\n",iter,normR)
iter += 1
if normR < tol || iter > maxiter
if normR < tol || iter == maxiter
shrink!(log)
setconv(log, 0<=normR<tol)
return X
end
if k < s
f[k+1:s] = f[k+1:s] - beta*M[k+1:s,k]
end

iter += 1
end

# Now we have sufficient vectors in G_j to compute residual in G_j+1
Expand Down
6 changes: 6 additions & 0 deletions test/idrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ end
@test history.isconverged
@test norm(A * x - b) / norm(b) tol
end

@testset "Maximum number of iterations" begin
x, history = idrs(rand(5, 5), rand(5), log=true, maxiter=2)
@test history.iters == 2
@test length(history[:resnorm]) == 2
end
end

0 comments on commit fa377a4

Please sign in to comment.