Skip to content

Commit a746467

Browse files
authored
Merge pull request #174 from haampie/remove-plots
Remove dependencies on UnicodePlots and LinearMaps
2 parents a7c0fb9 + 8ed1347 commit a746467

File tree

6 files changed

+63
-93
lines changed

6 files changed

+63
-93
lines changed

REQUIRE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
julia 0.6
22

3-
UnicodePlots
43
RecipesBase
54
SugarBLAS
6-
LinearMaps

docs/src/about/CONTRIBUTING.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ other git branches will let you use/test whatever there is.
4242

4343
## Adding or modifying iterative methods
4444

45-
Each iterative method method must log information using the inner `ConvergenceHistory`
46-
type. When information is not necessary to be stored (plot is set to `false`) then
47-
instead of `ConvergenceHistory` create a `DummyHistory`, this type has the same
48-
calls `ConvergenceHistory` does but without storing anything.
45+
Each iterative method method must log information using the inner `ConvergenceHistory` type.
4946

5047
There are two types of `ConvergenceHistory`: plain and restarted. The only real
5148
difference between the two is how they are plotted and how the number of restarts

src/common.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Base: A_ldiv_B!, \
22

3-
using LinearMaps
4-
53
export Identity
64

75
#### Type-handling

src/history.jl

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Base: getindex, setindex!, push!, keys
1+
using RecipesBase
2+
3+
import Base: getindex, setindex!, push!, keys
24

35
export ConvergenceHistory
46
export nprods, niters, nrests
57

6-
using UnicodePlots
7-
88
########
99
# Type #
1010
########
@@ -259,71 +259,6 @@ such objects.
259259
plotable(::VecOrMat{T}) where {T <: Real} = true
260260
plotable(::Any) = false
261261

262-
# inner plots
263-
264-
"""
265-
showplot(ch)
266-
267-
Print all plotable information inside `ConvergenceHistory` `ch`.
268-
"""
269-
function showplot(ch::ConvergenceHistory)
270-
candidates = collect(values(ch.data))
271-
plotables = convert(Vector{Bool},map(plotable, candidates))
272-
n = length(filter(identity, plotables))
273-
n > 0 || return
274-
println("\n")
275-
for (name, draw) in collect(ch.data)[plotables]
276-
restart = isa(ch, UnrestartedHistory) ? ch.iters : ch.restart
277-
drawing = plot_collection(draw, ch.iters, restart; name=string(name))
278-
println("$drawing\n\n")
279-
end
280-
end
281-
282-
"""
283-
plot_collection(x)
284-
285-
Build a `UnicodePlot.Plot` object from the plotable collection `x`.
286-
If `x` is a vector, a series will be made. In case of being a matrix an scatterplot
287-
will be returned.
288-
"""
289-
function plot_collection(vals::Vector{T}, iters::Int, gap::Int;
290-
restarts=Int(ceil(iters/gap)), color::Symbol=:blue, name::AbstractString="",
291-
title::AbstractString="", left::Int=1
292-
) where {T <: Real}
293-
maxy = round(maximum(vals),2)
294-
miny = round(minimum(vals),2)
295-
plot = lineplot([left],[miny],xlim=[left,iters],ylim=[miny,maxy],title=title,name=name)
296-
right = min(left+gap-1,iters)
297-
lineplot!(plot,collect(left:right),vals[left:right],color=color)
298-
for restart in 2:restarts
299-
left+=gap
300-
right = min(left+gap-1,iters)
301-
lineplot!(plot,collect(left:right),vals[left:right],color=color)
302-
lineplot!(plot,[left,left],[miny,maxy], color=:white)
303-
end
304-
plot
305-
end
306-
function plot_collection(vals::Matrix{T}, iters::Int, gap::Int;
307-
restarts=Int(ceil(iters/gap)), color::Symbol=:blue, name::AbstractString="",
308-
title::AbstractString="", left::Int=1
309-
) where {T <: Real}
310-
n = size(vals,2)
311-
maxy = round(maximum(vals),2)
312-
miny = round(minimum(vals),2)
313-
plot = scatterplot([left],[miny],xlim=[left,iters],ylim=[miny,maxy],title=title,name=name)
314-
for i in left:iters
315-
scatterplot!(plot,[i for j in 1:n],vec(vals[i,1:n]),color=color)
316-
end
317-
for restart in 2:restarts
318-
left+=gap
319-
lineplot!(plot,[left,left],[miny,maxy], color=:white)
320-
end
321-
plot
322-
end
323-
324-
## Recipes (See Plots.jl tutorial on recipes)
325-
326-
using RecipesBase
327262

328263
# Plot entire ConvergenceHistory. `sep` is the color of the restart separator.
329264
@recipe function chef(ch::CompleteHistory; sep = :white)

test/REQUIRE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
Plots
2-
UnicodePlots
31
LinearMaps

test/history.jl

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,68 @@
11
using IterativeSolvers
2-
using Plots
2+
using RecipesBase
3+
using Base.Test
34

4-
#Just check it doesn't crash
55
@testset "ConvergenceHistory" begin
66

7-
srand(1234321)
7+
const KW = Dict{Symbol, Any}
88

9-
#Use UnicodePlots backend because it is the lightest
10-
unicodeplots()
9+
RecipesBase.is_key_supported(k::Symbol) = k == :sep ? false : true
1110

12-
A = lu(rand(10, 10))[1]
13-
b = rand(10)
11+
# No plottables
12+
begin
13+
history = ConvergenceHistory(partial = false)
14+
@test_throws ErrorException RecipesBase.apply_recipe(KW(), history)
15+
end
1416

15-
for solver in (cg, gmres, minres, lsqr, lsmr, idrs)
16-
plot(solver(A, b; log=true)[2])
17-
end
17+
# Without restart markers
18+
begin
19+
history = ConvergenceHistory(partial = false)
20+
history.iters = 3
21+
history.data[:resnorm] = [10.0, 3.0, 0.1]
22+
23+
plots = (
24+
RecipesBase.apply_recipe(KW(), history),
25+
RecipesBase.apply_recipe(KW(), history, :resnorm)
26+
)
27+
28+
for data in plots
29+
@test length(data) == 1
30+
@test data[1].d[:label] == "resnorm"
31+
@test data[1].d[:seriestype] == :line
32+
end
33+
end
34+
35+
# With restart markers
36+
begin
37+
history = ConvergenceHistory(partial = false, restart = 2)
38+
history.iters = 3
39+
history.data[:resnorm] = [10.0, 3.0, 0.1]
40+
41+
plots = (
42+
RecipesBase.apply_recipe(KW(), history),
43+
RecipesBase.apply_recipe(KW(), history, :resnorm)
44+
)
45+
46+
for data in plots
47+
@test length(data) == 2
48+
@test data[2].d[:linecolor] == :white
49+
end
50+
end
51+
52+
# Custom color
53+
begin
54+
history = ConvergenceHistory(partial = false, restart = 2)
55+
history.iters = 3
56+
history.data[:resnorm] = [10.0, 3.0, 0.1]
57+
58+
plots = (
59+
RecipesBase.apply_recipe(KW(:sep => :red), history),
60+
RecipesBase.apply_recipe(KW(:sep => :red), history, :resnorm)
61+
)
1862

19-
plot(bicgstabl(A, b, 2, log=true)[2])
20-
plot(chebyshev(A, b, 0.5, 1.5; log=true)[2])
21-
plot(powm(A; log=true)[2])
22-
plot(invpowm(A; log=true)[2])
23-
plot(svdl(A; log=true)[3])
63+
for data in plots
64+
@test length(data) == 2
65+
@test data[2].d[:linecolor] == :red
66+
end
67+
end
2468
end

0 commit comments

Comments
 (0)