Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a compact show for MvNormal. #1786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/multivariate/mvnormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ distrname(d::ZeroMeanIsoNormal) = "ZeroMeanIsoNormal"
distrname(d::ZeroMeanDiagNormal) = "ZeroMeanDiagNormal"
distrname(d::ZeroMeanFullNormal) = "ZeroMeanFullNormal"

Base.show(io::IO, d::MvNormal) =
Base.show(io::IO, ::MIME"text/plain", d::MvNormal) =
show_multline(io, d, [(:dim, length(d)), (:μ, mean(d)), (:Σ, cov(d))])
Base.show(io::IO, d::MvNormal) =
print(io, "MvNormal($(d.μ), $(d.Σ))")
Comment on lines +250 to +251
Copy link
Member

Choose a reason for hiding this comment

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

There's already a show_oneline implementation in Distributions for compact representation. IMO it should actually be the default for show(io, dist), and only show(io, ::MIME"text/plain", dist) should use the current path which returns a one- or multiline representation depending on the number of parameters.

So I wonder what the implications of changing

show(io::IO, d::Distribution) = show(io, d, fieldnames(typeof(d)))
to

show(io::IO, d::Distribution) = show_oneline(io, d, fieldnames(typeof(d)))
show(io::IO, ::MIME"text/plain", d::Distribution) = show(io, d, fieldnames(typeof(d)))

would be.

Copy link
Author

Choose a reason for hiding this comment

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

show_oneline looks messy. Compare the two:

julia> "$dist" # show_oneline
"MvNormal{Bool, PDMats.PDiagMat{Bool, Vector{Bool}}, FillArrays.Falses{1, Tuple{Base.OneTo{Int64}}}}(dim=2, μ=Zeros{Bool}(2), Σ=Bool[1 0; 0 1])"

julia> "$dist" # the new show method
"MvNormal(Zeros{Bool}(2), Bool[1 0; 0 1])"

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, maybe the type parameters should be omitted in show_oneline. Additionally, I don't think you'd want to add the dim output to MvNormal, the vanilla show_oneline with the fields should be sufficient.


### Basic statistics

Expand Down
Loading