Skip to content

Commit 39a8b85

Browse files
authored
Move show methods from ApproxFun (#122)
* move show methods from ApproxFun * version bump to v0.6
1 parent 4d8a9b4 commit 39a8b85

File tree

5 files changed

+217
-1
lines changed

5 files changed

+217
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.5.15"
3+
version = "0.6.0"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/ApproxFunBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ include("Spaces/Spaces.jl")
114114
include("hacks.jl")
115115
include("testing.jl")
116116
include("specialfunctions.jl")
117+
include("show.jl")
117118

118119
end #module

src/show.jl

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
## Fun
2+
3+
show(io::IO, ::MIME"text/plain", f::Fun) = show(io, f)
4+
5+
function show(io::IO, f::Fun)
6+
print(io,"Fun(")
7+
show(io,space(f))
8+
print(io,", ")
9+
show(io,coefficients(f))
10+
print(io,")")
11+
end
12+
13+
show(io::IO,f::Fun{<:ConstantSpace{AnyDomain}}) =
14+
print(io,"$(convert(Number,f)) anywhere")
15+
16+
show(io::IO,f::Fun{<:ConstantSpace}) =
17+
print(io,"$(convert(Number,f)) on $(domain(f))")
18+
19+
## MultivariateFun
20+
21+
show(io::IO, ::MIME"text/plain", f::MultivariateFun) = show(io, f)
22+
23+
function show(io::IO,L::LowRankFun)
24+
print(io,"LowRankFun on ",space(L)," of rank ",rank(L),".")
25+
end
26+
27+
function show(io::IO,P::ProductFun)
28+
print(io,"ProductFun on ",space(P),".")
29+
end
30+
31+
## Operator
32+
33+
summarystr(B::Operator) = string(typeof(B).name.name, " : ", domainspace(B), "", rangespace(B))
34+
summary(io::IO, B::Operator) = print(io, summarystr(B))
35+
36+
struct PrintShow
37+
str
38+
end
39+
Base.show(io::IO,N::PrintShow) = print(io,N.str)
40+
41+
show(io::IO, B::Operator) = summary(io, B)
42+
43+
function show(io::IO, ::MIME"text/plain", B::Operator;header::Bool=true)
44+
header && summary(io, B)
45+
dsp = domainspace(B)
46+
47+
if !isambiguous(domainspace(B)) && (eltype(B) <: Number)
48+
println()
49+
if isbanded(B) && isinf(size(B,1)) && isinf(size(B,2))
50+
BM=B[1:10,1:10]
51+
52+
M=Matrix{Any}(undef,11,11)
53+
fill!(M,PrintShow(""))
54+
for j = 1:size(BM,2),k = colrange(BM,j)
55+
M[k,j]=BM[k,j]
56+
end
57+
58+
for k=max(1,11-bandwidth(B,2)):11
59+
M[k,end]=PrintShow("")
60+
end
61+
for j=max(1,11-bandwidth(B,1)):10
62+
M[end,j]=PrintShow("")
63+
end
64+
65+
print_array(io, M)
66+
elseif isinf(size(B,1)) && isinf(size(B,2))
67+
BM=B[1:10,1:10]
68+
69+
M=Matrix{Any}(undef,11,11)
70+
for k=1:10,j=1:10
71+
M[k,j]=BM[k,j]
72+
end
73+
74+
M[1,end]=PrintShow("")
75+
M[end,1]=PrintShow("")
76+
77+
for k=2:11
78+
M[k,end]=M[end,k]=PrintShow("")
79+
end
80+
81+
print_array(io, M)
82+
elseif isinf(size(B,1))
83+
BM=B[1:10,1:size(B,2)]
84+
85+
M=Matrix{Any}(undef,11,size(B,2))
86+
for k=1:10,j=1:size(B,2)
87+
M[k,j]=BM[k,j]
88+
end
89+
for k=1:size(B,2)
90+
M[end,k]=PrintShow("")
91+
end
92+
93+
print_array(io, M)
94+
elseif isinf(size(B,2))
95+
BM=B[1:size(B,1),1:10]
96+
97+
M=Matrix{Any}(undef,size(B,1),11)
98+
for k=1:size(B,1),j=1:10
99+
M[k,j]=BM[k,j]
100+
end
101+
for k=1:size(B,1)
102+
M[k,end]=PrintShow("")
103+
end
104+
105+
print_array(io, M)
106+
else
107+
print_array(io, AbstractMatrix(B)[1:size(B,1),1:size(B,2)])
108+
end
109+
end
110+
end
111+
112+
## Space
113+
114+
function show(io::IO, S::PointSpace)
115+
print(io, "PointSpace(")
116+
show(io, points(S))
117+
print(io,")")
118+
end
119+
120+
function show(io::IO,s::QuotientSpace)
121+
show(io,s.space)
122+
print(io," /\n")
123+
show(io,s.bcs;header=false)
124+
end
125+
126+
127+
function show(io::IO,ss::SumSpace)
128+
s = components(ss)
129+
show(io,s[1])
130+
for sp in s[2:end]
131+
print(io,"")
132+
show(io,sp)
133+
end
134+
end
135+
136+
137+
function show(io::IO,ss::PiecewiseSpace)
138+
s = components(ss)
139+
show(io,s[1])
140+
for sp in s[2:end]
141+
print(io,"")
142+
show(io,sp)
143+
end
144+
end
145+
146+
summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
147+
summary(io::IO, ss::ArraySpace) = print(io, summarystr(ss))
148+
function show(io::IO,ss::ArraySpace;header::Bool=true)
149+
header && print(io,summarystr(ss)*":\n")
150+
show(io, ss.spaces)
151+
end
152+
153+
function show(io::IO,s::TensorSpace)
154+
d = length(s.spaces)
155+
for i=1:d-1
156+
show(io,s.spaces[i])
157+
print(io,"")
158+
end
159+
show(io,s.spaces[d])
160+
end
161+
162+
function show(io::IO,s::SubSpace)
163+
print(io,s.space)
164+
print(io,"|")
165+
show(io,s.indexes)
166+
end
167+
168+
show(io::IO,::ConstantSpace{AnyDomain}) = print(io,"ConstantSpace")
169+
show(io::IO,S::ConstantSpace) = print(io,"ConstantSpace($(domain(S)))")
170+
171+
## Segment
172+
173+
show(io::IO,d::Segment) = print(io,"the segment [$(leftendpoint(d)),$(rightendpoint(d))]")

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,4 @@ end
165165
end
166166

167167
@time include("ETDRK4Test.jl")
168+
include("show.jl")

test/show.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@testset "show" begin
2+
@testset "Domain" begin
3+
@testset "Segment" begin
4+
s = Segment(0, 1)
5+
@test contains(repr(s), repr(leftendpoint(s)))
6+
@test contains(repr(s), repr(rightendpoint(s)))
7+
end
8+
end
9+
@testset "Space" begin
10+
@testset "ConstantSpace" begin
11+
@test contains(repr(ConstantSpace()), "ConstantSpace")
12+
c = ConstantSpace(0..1)
13+
@test contains(repr(c), "ConstantSpace")
14+
@test contains(repr(c), repr(domain(c)))
15+
end
16+
end
17+
@testset "Fun" begin
18+
f = Fun(PointSpace(1:3), [1,2,3])
19+
s = repr(f)
20+
@test startswith(s, "Fun")
21+
@test contains(s, repr(space(f)))
22+
@test contains(s, repr(coefficients(f)))
23+
24+
f = Fun(ConstantSpace(0..1), [2])
25+
@test contains(repr(f), repr(coefficient(f, 1)))
26+
@test contains(repr(f), repr(domain(f)))
27+
28+
f = Fun(ConstantSpace(), [2])
29+
@test contains(repr(f), repr(coefficient(f, 1)))
30+
end
31+
@testset "Operator" begin
32+
@testset "Derivative" begin
33+
D = Derivative()
34+
dsum = ApproxFunBase.summarystr(D)
35+
@test repr(D) == dsum
36+
io = IOBuffer()
37+
show(io, MIME"text/plain"(), D)
38+
@test contains(String(take!(io)), dsum)
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)