@@ -13,7 +13,7 @@ mutable struct BiCGStabIterable{precT, matT, solT, vecT <: AbstractVector, small
13
13
14
14
max_mv_products:: Int
15
15
mv_products:: Int
16
- reltol :: realT
16
+ tol :: realT
17
17
residual:: realT
18
18
19
19
Pl:: precT
@@ -25,11 +25,12 @@ mutable struct BiCGStabIterable{precT, matT, solT, vecT <: AbstractVector, small
25
25
end
26
26
27
27
function bicgstabl_iterator! (x, A, b, l:: Int = 2 ;
28
- Pl = Identity (),
29
- max_mv_products = size (A, 2 ),
30
- initial_zero = false ,
31
- tol = sqrt (eps (real (eltype (b))))
32
- )
28
+ Pl = Identity (),
29
+ max_mv_products = size (A, 2 ),
30
+ abstol:: Real = zero (real (eltype (b))),
31
+ reltol:: Real = sqrt (eps (real (eltype (b)))),
32
+ tol = nothing , # TODO : Deprecations introduced in v0.8
33
+ initial_zero = false )
33
34
T = eltype (x)
34
35
n = size (A, 1 )
35
36
mv_products = 0
@@ -41,6 +42,12 @@ function bicgstabl_iterator!(x, A, b, l::Int = 2;
41
42
42
43
residual = view (rs, :, 1 )
43
44
45
+ # TODO : Deprecations introduced in v0.8
46
+ if tol != = nothing
47
+ Base. depwarn (" The keyword argument `tol` is deprecated, use `reltol` instead." , :bicgstabl_iterator! )
48
+ reltol = tol
49
+ end
50
+
44
51
# Compute the initial residual rs[:, 1] = b - A * x
45
52
# Avoid computing A * 0.
46
53
if initial_zero
@@ -62,17 +69,17 @@ function bicgstabl_iterator!(x, A, b, l::Int = 2;
62
69
# For the least-squares problem
63
70
M = zeros (T, l + 1 , l + 1 )
64
71
65
- # Stopping condition based on relative tolerance.
66
- reltol = nrm * tol
72
+ # Stopping condition based on absolute and relative tolerance.
73
+ tolerance = max (reltol * nrm, abstol)
67
74
68
75
BiCGStabIterable (A, l, x, r_shadow, rs, us,
69
- max_mv_products, mv_products, reltol , nrm,
76
+ max_mv_products, mv_products, tolerance , nrm,
70
77
Pl,
71
78
γ, ω, σ, M
72
79
)
73
80
end
74
81
75
- @inline converged (it:: BiCGStabIterable ) = it. residual ≤ it. reltol
82
+ @inline converged (it:: BiCGStabIterable ) = it. residual ≤ it. tol
76
83
@inline start (:: BiCGStabIterable ) = 0
77
84
@inline done (it:: BiCGStabIterable , iteration:: Int ) = it. mv_products ≥ it. max_mv_products || converged (it)
78
85
@@ -157,10 +164,16 @@ bicgstabl(A, b, l = 2; kwargs...) = bicgstabl!(zerox(A, b), A, b, l; initial_zer
157
164
- `max_mv_products::Int = size(A, 2)`: maximum number of matrix vector products.
158
165
For BiCGStab(l) this is a less dubious term than "number of iterations";
159
166
- `Pl = Identity()`: left preconditioner of the method;
160
- - `tol::Real = sqrt(eps(real(eltype(b))))`: tolerance for stopping condition `|r_k| / |r_0| ≤ tol`.
161
- Note that (1) the true residual norm is never computed during the iterations,
162
- only an approximation; and (2) if a preconditioner is given, the stopping condition is based on the
163
- *preconditioned residual*.
167
+ - `abstol::Real = zero(real(eltype(b)))`,
168
+ `reltol::Real = sqrt(eps(real(eltype(b))))`: absolute and relative
169
+ tolerance for the stopping condition
170
+ `|r_k| / |r_0| ≤ max(reltol * resnorm, abstol)`, where `r_k = A * x_k - b`
171
+ is the residual in the `k`th iteration;
172
+ !!! note
173
+ 1. The true residual norm is never computed during the iterations,
174
+ only an approximation;
175
+ 2. If a left preconditioner is given, the stopping condition is based on the
176
+ *preconditioned residual*.
164
177
165
178
# Return values
166
179
@@ -174,21 +187,31 @@ For BiCGStab(l) this is a less dubious term than "number of iterations";
174
187
- `history`: convergence history.
175
188
"""
176
189
function bicgstabl! (x, A, b, l = 2 ;
177
- tol = sqrt (eps (real (eltype (b)))),
178
- max_mv_products:: Int = size (A, 2 ),
179
- log:: Bool = false ,
180
- verbose:: Bool = false ,
181
- Pl = Identity (),
182
- kwargs...
183
- )
190
+ abstol:: Real = zero (real (eltype (b))),
191
+ reltol:: Real = sqrt (eps (real (eltype (b)))),
192
+ tol = nothing , # TODO : Deprecations introduced in v0.8
193
+ max_mv_products:: Int = size (A, 2 ),
194
+ log:: Bool = false ,
195
+ verbose:: Bool = false ,
196
+ Pl = Identity (),
197
+ kwargs... )
184
198
history = ConvergenceHistory (partial = ! log)
185
- history[:tol ] = tol
199
+ history[:abstol ] = abstol
200
+ history[:reltol ] = reltol
186
201
187
202
# This doesn't yet make sense: the number of iters is smaller.
188
203
log && reserve! (history, :resnorm , max_mv_products)
189
204
190
- # Actually perform CG
191
- iterable = bicgstabl_iterator! (x, A, b, l; Pl = Pl, tol = tol, max_mv_products = max_mv_products, kwargs... )
205
+ # TODO : Deprecations introduced in v0.8
206
+ if tol != = nothing
207
+ Base. depwarn (" The keyword argument `tol` is deprecated, use `reltol` instead." , :bicgstabl! )
208
+ reltol = tol
209
+ end
210
+
211
+ # Actually perform iterative solve
212
+ iterable = bicgstabl_iterator! (x, A, b, l; Pl = Pl,
213
+ abstol = abstol, reltol = reltol,
214
+ max_mv_products = max_mv_products, kwargs... )
192
215
193
216
if log
194
217
history. mvps = iterable. mv_products
0 commit comments