Skip to content

Commit 063bdd7

Browse files
committed
Improve show(::SumSpace)
1 parent 67ee7cc commit 063bdd7

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/vectorspaces/sumspace.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,27 @@ end
196196

197197
# Show
198198
# ----
199+
# adapted from Base.show_vector
200+
# https://github.com/JuliaLang/julia/blob/9af96508e9715e22154fc7b5a7283ad41d23765a/base/arrayshow.jl#L514
201+
const SUMSPACE_SHOW_LIMIT = Ref(5)
199202
function Base.show(io::IO, V::SumSpace)
200203
if length(V) == 1
201-
print(io, "⊕(", V[1], ")")
202-
else
203-
print(io, "(")
204-
Base.join(io, V, "")
204+
print(io, "⊕(")
205+
show(io, V[1])
205206
print(io, ")")
207+
return nothing
208+
end
209+
210+
limited = get(io, :limited, true)
211+
if limited && length(V) > SUMSPACE_SHOW_LIMIT[]
212+
ax = axes(V.spaces, 1)
213+
f, l = first(ax), last(ax)
214+
h = SUMSPACE_SHOW_LIMIT[] ÷ 2
215+
Base.show_delim_array(io, V.spaces, "(", "", "", false, f, f + h)
216+
print(io, " ⊕ ⋯ ⊕ ")
217+
Base.show_delim_array(io, V.spaces, "", "", ")", false, l - h, l)
218+
else
219+
Base.show_delim_array(io, V.spaces, "(", "", ")", false)
206220
end
207221
return nothing
208222
end

0 commit comments

Comments
 (0)