Skip to content

Commit bbeb8e5

Browse files
authored
fix typo in show(::GradedSpace) (#308)
* fix typo in show * more `dims` * update printing of `ProductSpace{<:Any,0}` * bump v 0.15.3 * add tests for show
1 parent 30f440e commit bbeb8e5

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorKit"
22
uuid = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
33
authors = ["Jutho Haegeman"]
4-
version = "0.15.2"
4+
version = "0.15.3"
55

66
[deps]
77
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"

src/spaces/gradedspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ end
230230
function Base.show(io::IO, ::MIME"text/plain", V::GradedSpace)
231231
# print small summary, e.g.: Vect[I](…) of dim d
232232
d = dim(V)
233-
print(io, type_repr(typeof(d)), "(…)")
233+
print(io, type_repr(typeof(V)), "(…)")
234234
isdual(V) && print(io, "'")
235235
print(io, " of dim ", d)
236236

src/spaces/homspace.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ function dim(W::HomSpace)
127127
return d
128128
end
129129

130+
dims(W::HomSpace) = (dims(codomain(W))..., dims(domain(W))...)
131+
130132
"""
131133
fusiontrees(W::HomSpace)
132134

src/spaces/productspace.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ end
4848

4949
# Corresponding methods
5050
#-----------------------
51-
"""
51+
@doc """
5252
dims(::ProductSpace{S, N}) -> Dims{N} = NTuple{N, Int}
53+
dims(V::HomSpace) -> Dims{length(V)}
54+
dims(t::AbstractTensorMap) -> Dims{numind(t)}
55+
56+
Return the dimensions of the spaces in the tensor product space(s) as a tuple of integers.
57+
""" dims
5358

54-
Return the dimensions of the spaces in the tensor product space as a tuple of integers.
55-
"""
5659
dims(P::ProductSpace) = map(dim, P.spaces)
5760
dim(P::ProductSpace, n::Int) = dim(P.spaces[n])
5861
dim(P::ProductSpace) = prod(dims(P))
@@ -68,10 +71,11 @@ dual(P::ProductSpace) = ProductSpace(map(dual, reverse(P.spaces)))
6871
function Base.show(io::IO, P::ProductSpace{S}) where {S <: ElementarySpace}
6972
spaces = P.spaces
7073
if length(spaces) == 0
71-
print(io, "ProductSpace{", S, ", 0}")
74+
print(io, "one(", type_repr(S), ")")
75+
return nothing
7276
end
7377
if length(spaces) == 1
74-
print(io, "ProductSpace")
78+
print(io, "")
7579
end
7680
print(io, "(")
7781
for i in 1:length(spaces)

src/tensors/abstracttensor.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ symmetry. This is also the dimension of the `HomSpace` on which the `TensorMap`
195195
"""
196196
dim(t::AbstractTensorMap) = fusionblockstructure(t).totaldim
197197

198+
dims(t::AbstractTensorMap) = dims(space(t))
199+
198200
"""
199201
blocksectors(t::AbstractTensorMap)
200202
@@ -461,8 +463,7 @@ end
461463
Base.getindex(t::AbstractTensorMap)
462464
t[]
463465
464-
Return a view into the data of `t` as a `StridedViews.StridedView` of size
465-
`(dims(codomain(t))..., dims(domain(t))...)`.
466+
Return a view into the data of `t` as a `StridedViews.StridedView` of size `dims(t)`.
466467
"""
467468
@inline function Base.getindex(t::AbstractTensorMap)
468469
return t[trivial_fusiontree(t)...]
@@ -616,7 +617,7 @@ function Base.convert(::Type{Array}, t::AbstractTensorMap)
616617
dom = domain(t)
617618
T = sectorscalartype(I) <: Complex ? complex(scalartype(t)) :
618619
sectorscalartype(I) <: Integer ? scalartype(t) : float(scalartype(t))
619-
A = zeros(T, dims(cod)..., dims(dom)...)
620+
A = zeros(T, dims(t)...)
620621
for (f₁, f₂) in fusiontrees(t)
621622
F = convert(Array, (f₁, f₂))
622623
Aslice = StridedView(A)[axes(cod, f₁.uncoupled)..., axes(dom, f₂.uncoupled)...]

src/tensors/tensor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function TensorMap(
333333
# dimension check
334334
codom = codomain(V)
335335
dom = domain(V)
336-
arraysize = (dims(codom)..., dims(dom)...)
336+
arraysize = dims(V)
337337
matsize = (dim(codom), dim(dom))
338338

339339
if !(size(data) == arraysize || size(data) == matsize)
@@ -487,7 +487,7 @@ end
487487
@boundscheck begin
488488
sectortype(t) == Trivial || throw(SectorMismatch())
489489
end
490-
return sreshape(StridedView(t.data), (dims(codomain(t))..., dims(domain(t))...))
490+
return sreshape(StridedView(t.data), dims(t))
491491
end
492492

493493
# Show

test/symmetries/spaces.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,12 @@ end
452452
end
453453
end
454454

455+
@timedtestset "show and friends" begin
456+
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"
461+
end
462+
455463
TensorKit.empty_globalcaches!()

0 commit comments

Comments
 (0)