Skip to content

Commit 8498952

Browse files
authored
Merge pull request #253 from platawiec/idrs-res
fix idrs! when near solution
2 parents 17ef261 + 88e614c commit 8498952

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/idrs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ function idrs_method!(log::ConvergenceHistory, X, A, C::T,
8484
T_s = zero(R)
8585
end
8686

87-
if normR <= tol # Initial guess is a good enough solution
88-
return X, ConvergenceHistory(0<= res[end] < tol, tol, length(res), res)
87+
if normR <= tol # Initial guess is a good enough solution
88+
setconv(log, 0<=normR<tol)
89+
return X
8990
end
9091

9192
Z = zero(C)
@@ -159,7 +160,6 @@ function idrs_method!(log::ConvergenceHistory, X, A, C::T,
159160
push!(log, :resnorm, normR)
160161
verbose && @printf("%3d\t%1.2e\n",iter,normR)
161162
if normR < tol || iter == maxiter
162-
shrink!(log)
163163
setconv(log, 0<=normR<tol)
164164
return X
165165
end

test/idrs.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@ end
4444
@test history.iters == 2
4545
@test length(history[:resnorm]) == 2
4646
end
47+
48+
@testset "Near solution (#222)" begin
49+
x = rand(5)
50+
A = rand(5, 5)
51+
b = rand(5)
52+
53+
x, history = idrs!(x, A, b, log=true)
54+
x_new = copy(x)
55+
x_new, history = idrs!(x_new, A, b, log=true)
56+
57+
@test x_new x
58+
end
59+
4760
end

0 commit comments

Comments
 (0)