Skip to content

Commit cd43348

Browse files
committed
log only when log is true
1 parent aee7c2d commit cd43348

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/multilevel.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,27 @@ function solve(ml::MultiLevel, b::AbstractVector{T},
106106
V = promote_type(eltype(A), eltype(b))
107107
x = zeros(V, size(b))
108108
tol = eltype(b)(tol)
109-
residuals = Vector{V}()
110-
normb = norm(b)
109+
log && (residuals = Vector{V}())
110+
normres = normb = norm(b)
111111
if normb != 0
112112
tol *= normb
113113
end
114-
push!(residuals, normb)
114+
log && push!(residuals, normb)
115115

116-
lvl = 1
117-
while length(residuals) <= maxiter && residuals[end] > tol
116+
itr = lvl = 1
117+
while itr <= maxiter && normres > tol
118118
if length(ml) == 1
119119
ml.coarse_solver(x, b)
120120
else
121121
__solve!(x, ml, cycle, b, lvl)
122122
end
123-
push!(residuals, T(norm(b - A * x)))
123+
normres = norm(b - A * x)
124+
log && push!(residuals, normres)
125+
itr += 1
124126
end
125127

126128
# @show residuals
127-
if log
128-
return x, residuals
129-
else
130-
return x
131-
end
129+
log ? (x, residuals) : x
132130
end
133131
function __solve!(x, ml, v::V, b, lvl)
134132

0 commit comments

Comments
 (0)