Skip to content

Commit db09a2f

Browse files
authored
remove'\n' in compact printing of tensors (#310)
* remove newlines in :compact printing * be less strict in type assertion * fix missing variable * more robust tests
1 parent bbeb8e5 commit db09a2f

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/spaces/gradedspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ end
200200
Base.summary(io::IO, V::GradedSpace) = print(io, type_repr(typeof(V)))
201201

202202
function Base.show(io::IO, V::GradedSpace)
203-
opn = (get(io, :typeinfo, Any)::DataType == typeof(V) ? "" : type_repr(typeof(V)))
203+
opn = (get(io, :typeinfo, Any)::Type == typeof(V) ? "" : type_repr(typeof(V)))
204204
opn *= "("
205205
if isdual(V)
206206
cls = ")'"

src/tensors/abstracttensor.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,26 @@ function Base.summary(io::IO, t::AbstractTensorMap)
644644
end
645645

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

651+
# case without `\n`:
652+
if get(io, :compact, true)
653+
print(io, "(…, ")
654+
show(io, mime, space(t))
655+
print(io, ')')
656+
return nothing
657+
end
658+
659+
# case with `\n`
652660
# 2) show spaces
653-
# println(io, " space(t):")
661+
println(io, ':')
654662
println(io, " codomain: ", codomain(t))
655663
println(io, " domain: ", domain(t))
656664

657665
# 3) [optional]: show data
658-
get(io, :compact, true) && return nothing
659-
ioc = IOContext(io, :typeinfo => sectortype(t))
660666
println(io, "\n\n blocks: ")
661-
show_blocks(io, MIME"text/plain"(), blocks(t))
667+
show_blocks(io, mime, blocks(t))
662668
return nothing
663669
end

test/symmetries/spaces.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ end
454454

455455
@timedtestset "show and friends" begin
456456
V = U1Space(i => 1 for i in 1:3)
457-
@test string(V) == "Rep[U₁](1 => 1, 2 => 1, 3 => 1)"
458-
@test string(V') == "Rep[U₁](1 => 1, 2 => 1, 3 => 1)'"
459-
@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"
460-
@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"
457+
@test string(V) == "$(type_repr(typeof(V)))(1 => 1, 2 => 1, 3 => 1)"
458+
@test string(V') == "$(type_repr(typeof(V)))(1 => 1, 2 => 1, 3 => 1)'"
459+
@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"
460+
@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"
461461
end
462462

463463
TensorKit.empty_globalcaches!()

0 commit comments

Comments
 (0)