-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]display and printingAesthetics and correctness of printed representations of objects.Aesthetics and correctness of printed representations of objects.
Description
It's pretty common to have array show methods give up trying to show information in tight vertical terminals whilst there's ample width to use.
Logging is a common place to see this.
julia> @info "foo" a=rand(6) b=rand(5) c=rand(6) d=rand(4) e=rand(8)
┌ Info: foo
│ a = 6-element Vector{Float64}: …
│ b = 5-element Vector{Float64}: …
│ c = 6-element Vector{Float64}: …
│ d = 4-element Vector{Float64}: …
└ e = 8-element Vector{Float64}: …
Or a slightly higher terminal. No further information, just different empty printing style.
julia> @info "foo" a=rand(6) b=rand(5) c=rand(6) d=rand(4) e=rand(8)
┌ Info: foo
│ a =
│ 6-element Vector{Float64}:
│ ⋮
│ b =
│ 5-element Vector{Float64}:
│ ⋮
│ c =
│ 6-element Vector{Float64}:
│ ⋮
│ d =
│ 4-element Vector{Float64}:
│ ⋮
│ e =
│ 8-element Vector{Float64}:
└ ⋮
One could imagine a more compact show method that restricts to a single line, like
julia> @info "foo" a=rand(6) b=rand(5) c=rand(6) d=rand(4) e=rand(8)
┌ Info: foo
│ a = 6-element Vector{Float64}: [0.8134601650024766, 0.7738397056728175, 0.3752414938409441, 0.8339099554400665, 0.939…
│ b = 5-element Vector{Float64}: [0.3017565712942871, 0.9252215221184537, 0.15223562011281377, 0.6634456753832947, 0.00…
│ c = 6-element Vector{Float64}: [0.2846876872744232, 0.6823462436053258, 0.19578819449271656, 0.5046565581624222, 0.27…
│ d = 4-element Vector{Float64}: [0.7399563617687338, 0.30720428725219673, 0.520680715274417, 0.8960050441206099]
└ e = 8-element Vector{Float64}: [0.2538020231959873, 0.08291789857121101, 0.33046327452562985, 0.8337790739561953, 0.3…
But it's tricky to implement because:
- The objects within the vector might define their own show with multiple lines in each
- The truncation of each line should happen eagerly, to prevent spending ages printing a long vector just to show the very start of it (
print_array
handles that kind of thing). - To know what width to truncate to you need to know what column you're starting printing on.. so the
Base.show
methods need to be told that to do their job eagerly. Width limits are harder than height in this regard.
Maybe more information could be passed in via an IOContext
like maxwidth
or singleline
for show
methods to respect.
I don't have a good suggestion, but opening for discussion.
One workaround proposed by @jkrumbiegel was to wrap things in Ref
but that gives no width truncation and wastes space on Base.RefValue{Vector{Float64}}(
julia> @info "foo" a=Ref(rand(6)) b=Ref(rand(5)) c=Ref(rand(6)) d=Ref(rand(4)) e=Ref(rand(8))
┌ Info: foo
│ a = Base.RefValue{Vector{Float64}}([0.3759948665717201, 0.9793671630005392, 0.521479561480086, 0.9683689501672195, 0.8500692498244814, 0.9817497212596576])
│ b = Base.RefValue{Vector{Float64}}([0.9519333852652635, 0.6214464833723727, 0.873721718796774, 0.1242648588068741, 0.5602350570723447])
│ c = Base.RefValue{Vector{Float64}}([0.1708377789524652, 0.2620076506595481, 0.1776606008776388, 0.854482265631028, 0.26584629467345566, 0.17861997191656154])
│ d = Base.RefValue{Vector{Float64}}([0.8474625546579776, 0.13387194867377128, 0.1996171012959429, 0.9794546185250278])
└ e = Base.RefValue{Vector{Float64}}([0.6013082818316436, 0.1764535079543318, 0.8076186192928289, 0.3356844956152647, 0.9841811511405628, 0.5832216044509186, 0.41564993724099897, 0.012678830142036301])
jeremiedb
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]display and printingAesthetics and correctness of printed representations of objects.Aesthetics and correctness of printed representations of objects.