Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/spaces/gradedspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ end
Base.summary(io::IO, V::GradedSpace) = print(io, type_repr(typeof(V)))

function Base.show(io::IO, V::GradedSpace)
opn = (get(io, :typeinfo, Any)::DataType == typeof(V) ? "" : type_repr(typeof(V)))
opn = (get(io, :typeinfo, Any)::Type == typeof(V) ? "" : type_repr(typeof(V)))
opn *= "("
if isdual(V)
cls = ")'"
Expand Down
20 changes: 13 additions & 7 deletions src/tensors/abstracttensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,20 +644,26 @@ function Base.summary(io::IO, t::AbstractTensorMap)
end

# Human-readable:
function Base.show(io::IO, ::MIME"text/plain", t::AbstractTensorMap)
# 1) show summary: typically d₁×d₂×… ← d₃×d₄×… $(typeof(t)):
function Base.show(io::IO, mime::MIME"text/plain", t::AbstractTensorMap)
# 1) show summary: typically d₁×d₂×… ← d₃×d₄×… $(typeof(t))
summary(io, t)
println(io, ":")

# case without `\n`:
if get(io, :compact, true)
print(io, "(…, ")
show(io, mime, space(t))
print(io, ')')
return nothing
end

# case with `\n`
# 2) show spaces
# println(io, " space(t):")
println(io, ':')
println(io, " codomain: ", codomain(t))
println(io, " domain: ", domain(t))

# 3) [optional]: show data
get(io, :compact, true) && return nothing
ioc = IOContext(io, :typeinfo => sectortype(t))
println(io, "\n\n blocks: ")
show_blocks(io, MIME"text/plain"(), blocks(t))
show_blocks(io, mime, blocks(t))
return nothing
end
8 changes: 4 additions & 4 deletions test/symmetries/spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ end

@timedtestset "show and friends" begin
V = U1Space(i => 1 for i in 1:3)
@test string(V) == "Rep[U₁](1 => 1, 2 => 1, 3 => 1)"
@test string(V') == "Rep[U₁](1 => 1, 2 => 1, 3 => 1)'"
@test sprint((x, y) -> show(x, MIME"text/plain"(), y), V) == "Rep[U₁](…) of dim 3:\n 1 => 1\n 2 => 1\n 3 => 1"
@test sprint((x, y) -> show(x, MIME"text/plain"(), y), V') == "Rep[U₁](…)' of dim 3:\n 1 => 1\n 2 => 1\n 3 => 1"
@test string(V) == "$(type_repr(typeof(V)))(1 => 1, 2 => 1, 3 => 1)"
@test string(V') == "$(type_repr(typeof(V)))(1 => 1, 2 => 1, 3 => 1)'"
@test sprint((x, y) -> show(x, MIME"text/plain"(), y), V) == "$(type_repr(typeof(V)))(…) of dim 3:\n 1 => 1\n 2 => 1\n 3 => 1"
@test sprint((x, y) -> show(x, MIME"text/plain"(), y), V') == "$(type_repr(typeof(V)))(…)' of dim 3:\n 1 => 1\n 2 => 1\n 3 => 1"
end

TensorKit.empty_globalcaches!()