Skip to content

Commit 511fbc6

Browse files
committed
Pretty-printing of FunctionProducts
1 parent 66286c3 commit 511fbc6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/densities.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ end
8080

8181
Base.eltype::FunctionProduct{<:Any,T}) where T = T
8282

83+
function Base.show(io::IO, ρ::FunctionProduct{Conjugated, T}) where {Conjugated,T}
84+
mL = size.L,2)
85+
mR = size.R,2)
86+
= length.ρ)
87+
write(io, "$(mL) .* $(mR) -> $(mρ) FunctionProduct $T")
88+
Conjugated && write(io, ", conjugated (<=> Density)")
89+
end
90+
91+
function Base.show(io::IO, ::MIME"text/plain", ρ::FunctionProduct)
92+
show(io, ρ)
93+
write(io, "; L .* R -> R, with\n L: ")
94+
show(io, ρ.L)
95+
write(io, "\n R: ")
96+
show(io, ρ.R)
97+
end
98+
8399
"""
84100
copyto!(ρ::FunctionProduct{Conjugated}, f::AbstractVector, g::AbstractVector) where Conjugated
85101

test/densities.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,29 @@
4242

4343
@test ch2 ch atol=1e-14 rtol=rtol
4444
end
45+
46+
@testset "Pretty-printing" begin
47+
R = FiniteDifferences(99, 0.1)
48+
u = R*rand(size(R,2))
49+
v = R*rand(size(R,2))
50+
ρ = Density(u, v)
51+
fp = FunctionProduct{false}(u, v)
52+
53+
@test string(ρ) == "99 .* 99 -> 99 FunctionProduct Float64, conjugated (<=> Density)"
54+
@test string(fp) == "99 .* 99 -> 99 FunctionProduct Float64"
55+
56+
buf = IOBuffer()
57+
show(buf, MIME"text/plain"(), ρ)
58+
@test String(take!(buf)) == """
59+
99 .* 99 -> 99 FunctionProduct Float64, conjugated (<=> Density); L .* R -> R, with
60+
L: $(string(R))
61+
R: $(string(R))"""
62+
63+
buf = IOBuffer()
64+
show(buf, MIME"text/plain"(), fp)
65+
@test String(take!(buf)) == """
66+
99 .* 99 -> 99 FunctionProduct Float64; L .* R -> R, with
67+
L: $(string(R))
68+
R: $(string(R))"""
69+
end
4570
end

0 commit comments

Comments
 (0)