Skip to content

Commit

Permalink
Merge pull request #781 from jishnub/compactshow
Browse files Browse the repository at this point in the history
Define compact show for operators to simplify display for containers
  • Loading branch information
jishnub authored Jul 27, 2022
2 parents f9b508f + d2678ac commit 7968dab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFun"
uuid = "28f2ccd6-bb30-5033-b560-165f7b14dc2f"
version = "0.13.3"
version = "0.13.4"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
14 changes: 8 additions & 6 deletions src/Extras/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ function show(io::IO,ss::PiecewiseSpace)
end
end

summary(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
summary(io::IO, ss::ArraySpace) = print(io, summarystr(ss))
function show(io::IO,ss::ArraySpace;header::Bool=true)
header && print(io,summary(ss)*":\n")
header && print(io,summarystr(ss)*":\n")
show(io, ss.spaces)
end

Expand Down Expand Up @@ -182,17 +183,18 @@ end

## Operator

summary(B::Operator) =
string(typeof(B).name.name)*" : "*string(domainspace(B))*""*string(rangespace(B))
summarystr(B::Operator) = string(typeof(B).name.name, " : ", domainspace(B), "", rangespace(B))
summary(io::IO, B::Operator) = print(io, summarystr(B))

struct PrintShow
str
end
Base.show(io::IO,N::PrintShow) = print(io,N.str)

show(io::IO, B::Operator) = summary(io, B)

function show(io::IO,B::Operator;header::Bool=true)
header && println(io,summary(B))
function show(io::IO, ::MIME"text/plain", B::Operator;header::Bool=true)
header && println(io, summarystr(B))
dsp=domainspace(B)

if !isambiguous(domainspace(B)) && (eltype(B) <: Number)
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,16 @@ end
N = u -> [u'(0), u(0)-1, x*u'' + 2*u' + x*u^n]
u = newton(N, u₀) # perform Newton iteration in function space
@test u(0.1) 0.9983370741307388
end
end

@testset "show" begin
op = Derivative(Chebyshev())
io = IOBuffer()
@test summary(io, op) isa Nothing
@test contains(String(take!(io)), " : $(domainspace(op))$(rangespace(op))")
show(io, op)
@test contains(String(take!(io)), " : $(domainspace(op))$(rangespace(op))")

@test summary(io, ApproxFun.ArraySpace(Chebyshev(), 2)) isa Nothing
@test contains(String(take!(io)), "ArraySpace")
end

2 comments on commit 7968dab

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/65090

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.4 -m "<description of version>" 7968dab6271e61e8c4fb3bb85adff9527605b99f
git push origin v0.13.4

Please sign in to comment.