Skip to content

Commit 3224fb2

Browse files
haampieandreasnoack
authored andcommitted
Remove plotting from algorithms (#135)
* Remove plotting from algorithms * Remove plot keyword from the docs
1 parent eacea1a commit 3224fb2

File tree

12 files changed

+28
-99
lines changed

12 files changed

+28
-99
lines changed

docs/src/user_manual.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,18 @@ etc.
7979
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
8080
containing extra information of the method execution.
8181

82-
`plot`: plot information relevant to the method. (Only for `Master` version)
83-
8482
### `log` keyword
8583

8684
All solvers contain the `log` keyword. This is to be used when obtaining
8785
more information is required, to use it place the set `log` to `true`.
8886

8987
```julia
9088
x, ch = cg(Master, rand(10, 10), rand(10) log=true)
91-
svd, L, ch = svdl(Master, rand(100, 100), plot=true, log=true)
89+
svd, L, ch = svdl(Master, rand(100, 100), log=true)
9290
```
9391

9492
The function will now return one more parameter of type `ConvergenceHistory`.
9593

96-
*`Note:`* Keyword argument `plot` is only available when `log` is set.
97-
9894
## ConvergenceHistory
9995

10096
A [`ConvergenceHistory`](@ref) instance stores information of a solver.

src/cg.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ cg(A, b; kwargs...) = cg!(zerox(A, b), A, b; kwargs...)
55
function cg!(x, A, b;
66
tol = sqrt(eps(real(eltype(b)))),
77
maxiter::Integer = min(20, size(A, 1)),
8-
plot = false,
98
log::Bool = false,
109
Pl = Identity(),
1110
kwargs...
1211
)
13-
(plot & !log) && error("Can't plot when log keyword is false")
1412
history = ConvergenceHistory(partial = !log)
1513
history[:tol] = tol
1614
log && reserve!(history, :resnorm, maxiter + 1)
1715
cg_method!(history, x, A, b, Pl; tol = tol, log = log, maxiter = maxiter, kwargs...)
1816
log && shrink!(history)
19-
plot && showplot(history)
2017
log ? (x, history) : x
2118
end
2219

@@ -193,7 +190,6 @@ $msg
193190
194191
If `log` is set to `true` is given, method will output a tuple `x, ch`. Where
195192
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `x`.
196-
The `plot` attribute can only be used when `log` is set version.
197193
198194
# Arguments
199195
@@ -216,8 +212,6 @@ $arg
216212
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
217213
containing extra information of the method execution.
218214
219-
`plot::Bool = false`: plot data. (Only when `log` is set)
220-
221215
# Output
222216
223217
**if `log` is `false`**

src/chebyshev.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ chebyshev(A, b, λmin::Real, λmax::Real; kwargs...) =
99

1010
function chebyshev!(x, A, b, λmin::Real, λmax::Real;
1111
n::Int=size(A,2), tol::Real = sqrt(eps(typeof(real(b[1])))),
12-
maxiter::Int = n^3, plot::Bool=false, log::Bool=false, kwargs...
12+
maxiter::Int = n^3, log::Bool=false, kwargs...
1313
)
1414
K = KrylovSubspace(A, n, 1, Adivtype(A, b))
1515
init!(K, x)
16-
17-
(plot & !log) && error("Can't plot when log keyword is false")
1816
history = ConvergenceHistory(partial=!log)
1917
history[:tol] = tol
2018
reserve!(history,:resnorm,maxiter)
2119
chebyshev_method!(history, x, K, b, λmin, λmax; tol=tol, maxiter=maxiter, kwargs...)
22-
(plot || log) && shrink!(history)
23-
plot && showplot(history)
20+
log && shrink!(history)
2421
log ? (x, history) : x
2522
end
2623

@@ -101,8 +98,6 @@ $msg
10198
If `log` is set to `true` is given, method will output a tuple `x, ch`. Where
10299
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `x`.
103100
104-
The `plot` attribute can only be used when `log` is set version.
105-
106101
# Arguments
107102
108103
$arg
@@ -124,8 +119,6 @@ $arg
124119
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
125120
containing extra information of the method execution.
126121
127-
`plot::Bool = false`: plot data. (Only with `Master` version)
128-
129122
# Output
130123
131124
**if `log` is `false`**

src/gmres.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ function gmres!(x, A, b;
88
tol = sqrt(eps(real(eltype(b)))),
99
restart::Int = min(20, length(b)),
1010
maxiter::Int = restart,
11-
plot::Bool = false,
1211
log::Bool = false,
1312
kwargs...
1413
)
15-
(plot & !log) && error("Can't plot when log keyword is false")
1614
history = ConvergenceHistory(partial = !log, restart = restart)
1715
history[:tol] = tol
1816
log && reserve!(history, :resnorm, maxiter)
1917
gmres_method!(history, x, A, b; Pl = Pl, Pr = Pr, tol = tol, maxiter = maxiter, restart = restart, log = log, kwargs...)
20-
(plot || log) && shrink!(history)
21-
plot && showplot(history)
18+
log && shrink!(history)
2219
log ? (x, history) : x
2320
end
2421

src/history.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ plotable(::Any)::Bool = false
265265
showplot(ch)
266266
267267
Print all plotable information inside `ConvergenceHistory` `ch`.
268-
*Note:* This is what is called when the `plot` keyword is set.
269268
"""
270269
function showplot(ch::ConvergenceHistory)
271270
candidates = collect(values(ch.data))

src/idrs.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ idrs(A, b; kwargs...) = idrs!(zerox(A,b), A, b; kwargs...)
99

1010
function idrs!(x, A, b;
1111
s = 8, tol=sqrt(eps(typeof(real(b[1])))), maxiter=length(x)^2,
12-
plot::Bool=false, log::Bool=false, kwargs...
12+
log::Bool=false, kwargs...
1313
)
14-
(plot & !log) && error("Can't plot when log keyword is false")
1514
history = ConvergenceHistory(partial=!log)
1615
history[:tol] = tol
1716
reserve!(history,:resnorm, maxiter)
1817
idrs_method!(history, x, linsys_op, (A,), b, s, tol, maxiter; kwargs...)
19-
(plot || log) && shrink!(history)
20-
plot && showplot(history)
18+
log && shrink!(history)
2119
log ? (x, history) : x
2220
end
2321

@@ -228,8 +226,6 @@ $msg
228226
If `log` is set to `true` is given, method will output a tuple `x, ch`. Where
229227
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `x`.
230228
231-
The `plot` attribute can only be used when `log` is set version.
232-
233229
# Arguments
234230
235231
$arg
@@ -255,8 +251,6 @@ $arg
255251
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
256252
containing extra information of the method execution.
257253
258-
`plot::Bool = false`: plot data. (Only when `log` is set)
259-
260254
# Output
261255
262256
**if `log` is `false`**

src/lanczos.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ export eiglancz
77
####################
88

99
function eiglancz(A;
10-
maxiter::Integer=size(A,1), plot::Bool=false,
10+
maxiter::Integer=size(A,1),
1111
tol::Real = size(A,1)^3*eps(real(eltype(A))), log::Bool=false, kwargs...
1212
)
13-
(plot & !log) && error("Can't plot when log keyword is false")
1413
history = ConvergenceHistory(partial=!log)
1514
history[:tol] = tol
1615
reserve!(history,:resnorm, maxiter)
1716
e1 = eiglancz_method(history, A; maxiter=maxiter, tol=tol, kwargs...)
18-
(plot || log) && shrink!(history)
19-
plot && showplot(history)
17+
log && shrink!(history)
2018
log ? (e1, history) : e1
2119
end
2220

@@ -89,8 +87,6 @@ $msg
8987
If `log` is set to `true` is given, method will output a tuple `eigs, ch`. Where
9088
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `eigs`.
9189
92-
The `plot` attribute can only be used when `log` is set version.
93-
9490
# Arguments
9591
9692
$arg
@@ -110,8 +106,6 @@ $arg
110106
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
111107
containing extra information of the method execution.
112108
113-
`plot::Bool = false`: plot data. (Only when `log` is set)
114-
115109
# Output
116110
117111
**if `log` is `false`**

src/lsmr.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ using Base.LinAlg
99
lsmr(A, b; kwargs...) = lsmr!(zerox(A, b), A, b; kwargs...)
1010

1111
function lsmr!(x, A, b;
12-
plot::Bool=false, maxiter::Integer = max(size(A,1), size(A,2)),
12+
maxiter::Integer = max(size(A,1), size(A,2)),
1313
log::Bool=false, kwargs...
1414
)
15-
(plot & !log) && error("Can't plot when log keyword is false")
1615
history = ConvergenceHistory(partial=!log)
1716
reserve!(history,[:anorm,:rnorm,:cnorm],maxiter)
1817

@@ -22,8 +21,7 @@ function lsmr!(x, A, b;
2221
copy!(btmp, b)
2322
v, h, hbar = similar(x, T), similar(x, T), similar(x, T)
2423
lsmr_method!(history, x, A, btmp, v, h, hbar; maxiter=maxiter, kwargs...)
25-
(plot || log) && shrink!(history)
26-
plot && showplot(history)
24+
log && shrink!(history)
2725
log ? (x, history) : x
2826
end
2927

@@ -273,8 +271,6 @@ but has better numerical properties, especially if A is ill-conditioned.
273271
If `log` is set to `true` is given, method will output a tuple `x, ch`. Where
274272
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `x`.
275273
276-
The `plot` attribute can only be used when `log` is set version.
277-
278274
# Arguments
279275
280276
$arg
@@ -307,8 +303,6 @@ may then be excessive.
307303
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
308304
containing extra information of the method execution.
309305
310-
`plot::Bool = false`: plot data. (Only when `log` is set)
311-
312306
# Output
313307
314308
**if `log` is `false`**

src/lsqr.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ export lsqr, lsqr!
77
lsqr(A, b; kwargs...) = lsqr!(zerox(A, b), A, b; kwargs...)
88

99
function lsqr!(x, A, b;
10-
plot::Bool=false, maxiter::Int=max(size(A,1), size(A,2)), log::Bool=false,
10+
maxiter::Int=max(size(A,1), size(A,2)), log::Bool=false,
1111
kwargs...
1212
)
1313
T = Adivtype(A, b)
1414
z = zero(T)
15-
16-
(plot & !log) && error("Can't plot when log keyword is false")
1715
history = ConvergenceHistory(partial=!log)
1816
reserve!(history,[:resnorm,:anorm,:rnorm,:cnorm],maxiter)
1917
lsqr_method!(history, x, A, b; maxiter=maxiter, kwargs...)
20-
(plot || log) && shrink!(history)
21-
plot && showplot(history)
18+
log && shrink!(history)
2219
log ? (x, history) : x
2320
end
2421

@@ -262,8 +259,6 @@ but has better numerical properties, especially if A is ill-conditioned.
262259
If `log` is set to `true` is given, method will output a tuple `x, ch`. Where
263260
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `x`.
264261
265-
The `plot` attribute can only be used when `log` is set version.
266-
267262
# Arguments
268263
269264
$arg
@@ -296,8 +291,6 @@ may then be excessive.
296291
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
297292
containing extra information of the method execution.
298293
299-
`plot::Bool = false`: plot data. (Only when `log` is set)
300-
301294
# Output
302295
303296
**if `log` is `false`**

src/simple.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ export powm, invpowm
77

88
function powm(A;
99
x=nothing, tol::Real=eps(real(eltype(A)))*size(A,2)^3, maxiter::Int=size(A,2),
10-
plot::Bool=false, log::Bool=false, kwargs...
10+
log::Bool=false, kwargs...
1111
)
1212
K = KrylovSubspace(A, 1)
1313
x==nothing ? initrand!(K) : init!(K, x/norm(x))
1414

15-
(plot & !log) && error("Can't plot when log keyword is false")
1615
history = ConvergenceHistory(partial=!log)
1716
history[:tol] = tol
1817
reserve!(history,:resnorm, maxiter)
1918
eig, v = powm_method!(history, K; tol=tol, maxiter=maxiter, kwargs...)
20-
(plot || log) && shrink!(history)
21-
plot && showplot(history)
19+
log && shrink!(history)
2220
log ? (eig, v, history) : (eig, v)
2321
end
2422

@@ -53,18 +51,16 @@ end
5351

5452
function invpowm(A;
5553
x=nothing, shift::Number=0, tol::Real=eps(real(eltype(A)))*size(A,2)^3,
56-
maxiter::Int=size(A,2), plot::Bool=false, log::Bool=false, kwargs...
54+
maxiter::Int=size(A,2), log::Bool=false, kwargs...
5755
)
5856
K = KrylovSubspace(A, 1)
5957
x==nothing ? initrand!(K) : init!(K, x/norm(x))
6058

61-
(plot & !log) && error("Can't plot when log keyword is false")
6259
history = ConvergenceHistory(partial=!log)
6360
history[:tol] = tol
6461
reserve!(history,:resnorm, maxiter)
6562
eig, v = invpowm_method!(history, K, shift; tol=tol, maxiter=maxiter, kwargs...)
66-
(plot || log) && shrink!(history)
67-
plot && showplot(history)
63+
log && shrink!(history)
6864
log ? (eig, v, history) : (eig, v)
6965
end
7066

@@ -131,8 +127,6 @@ $msg
131127
If `log` is set to `true` is given, method will output a tuple `eig, v, ch`. Where
132128
`ch` is a `ConvergenceHistory` object. Otherwise it will only return `eig, v`.
133129
134-
The `plot` attribute can only be used when `log` is set version.
135-
136130
# Arguments
137131
138132
`K::KrylovSubspace`: krylov subspace.
@@ -154,8 +148,6 @@ $karg
154148
`log::Bool = false`: output an extra element of type `ConvergenceHistory`
155149
containing extra information of the method execution.
156150
157-
`plot::Bool = false`: plot data. (Only when `log` is set)
158-
159151
# Output
160152
161153
**if `log` is `false`**

0 commit comments

Comments
 (0)