From 3cc2c00e2c3ff27a37aee61eb1786a36a3767518 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 29 Oct 2025 13:43:43 -0400 Subject: [PATCH 1/5] fix typo in show --- src/spaces/gradedspace.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spaces/gradedspace.jl b/src/spaces/gradedspace.jl index 5f07821be..5e0d76674 100644 --- a/src/spaces/gradedspace.jl +++ b/src/spaces/gradedspace.jl @@ -230,7 +230,7 @@ end function Base.show(io::IO, ::MIME"text/plain", V::GradedSpace) # print small summary, e.g.: Vect[I](…) of dim d d = dim(V) - print(io, type_repr(typeof(d)), "(…)") + print(io, type_repr(typeof(V)), "(…)") isdual(V) && print(io, "'") print(io, " of dim ", d) From 1523d0ebd7ee51b9f3e3ea035eefb58464d360a8 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 29 Oct 2025 20:43:06 -0400 Subject: [PATCH 2/5] more `dims` --- src/spaces/homspace.jl | 2 ++ src/spaces/productspace.jl | 9 ++++++--- src/tensors/abstracttensor.jl | 7 ++++--- src/tensors/tensor.jl | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/spaces/homspace.jl b/src/spaces/homspace.jl index f020535c5..559ba2219 100644 --- a/src/spaces/homspace.jl +++ b/src/spaces/homspace.jl @@ -127,6 +127,8 @@ function dim(W::HomSpace) return d end +dims(W::HomSpace) = (dims(codomain(W))..., dims(domain(W))...) + """ fusiontrees(W::HomSpace) diff --git a/src/spaces/productspace.jl b/src/spaces/productspace.jl index 08e7011b0..b1442998b 100644 --- a/src/spaces/productspace.jl +++ b/src/spaces/productspace.jl @@ -48,11 +48,14 @@ end # Corresponding methods #----------------------- -""" +@doc """ dims(::ProductSpace{S, N}) -> Dims{N} = NTuple{N, Int} + dims(V::HomSpace) -> Dims{length(V)} + dims(t::AbstractTensorMap) -> Dims{numind(t)} + +Return the dimensions of the spaces in the tensor product space(s) as a tuple of integers. +""" dims -Return the dimensions of the spaces in the tensor product space as a tuple of integers. -""" dims(P::ProductSpace) = map(dim, P.spaces) dim(P::ProductSpace, n::Int) = dim(P.spaces[n]) dim(P::ProductSpace) = prod(dims(P)) diff --git a/src/tensors/abstracttensor.jl b/src/tensors/abstracttensor.jl index 67df680cc..69fdce784 100644 --- a/src/tensors/abstracttensor.jl +++ b/src/tensors/abstracttensor.jl @@ -195,6 +195,8 @@ symmetry. This is also the dimension of the `HomSpace` on which the `TensorMap` """ dim(t::AbstractTensorMap) = fusionblockstructure(t).totaldim +dims(t::AbstractTensorMap) = dims(space(t)) + """ blocksectors(t::AbstractTensorMap) @@ -461,8 +463,7 @@ end Base.getindex(t::AbstractTensorMap) t[] -Return a view into the data of `t` as a `StridedViews.StridedView` of size -`(dims(codomain(t))..., dims(domain(t))...)`. +Return a view into the data of `t` as a `StridedViews.StridedView` of size `dims(t)`. """ @inline function Base.getindex(t::AbstractTensorMap) return t[trivial_fusiontree(t)...] @@ -616,7 +617,7 @@ function Base.convert(::Type{Array}, t::AbstractTensorMap) dom = domain(t) T = sectorscalartype(I) <: Complex ? complex(scalartype(t)) : sectorscalartype(I) <: Integer ? scalartype(t) : float(scalartype(t)) - A = zeros(T, dims(cod)..., dims(dom)...) + A = zeros(T, dims(t)...) for (f₁, f₂) in fusiontrees(t) F = convert(Array, (f₁, f₂)) Aslice = StridedView(A)[axes(cod, f₁.uncoupled)..., axes(dom, f₂.uncoupled)...] diff --git a/src/tensors/tensor.jl b/src/tensors/tensor.jl index f8f04e99a..fe15d819d 100644 --- a/src/tensors/tensor.jl +++ b/src/tensors/tensor.jl @@ -333,7 +333,7 @@ function TensorMap( # dimension check codom = codomain(V) dom = domain(V) - arraysize = (dims(codom)..., dims(dom)...) + arraysize = dims(V) matsize = (dim(codom), dim(dom)) if !(size(data) == arraysize || size(data) == matsize) @@ -487,7 +487,7 @@ end @boundscheck begin sectortype(t) == Trivial || throw(SectorMismatch()) end - return sreshape(StridedView(t.data), (dims(codomain(t))..., dims(domain(t))...)) + return sreshape(StridedView(t.data), dims(t)) end # Show From 7229cd59bf09cc356c54676990ed826406e134fd Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 29 Oct 2025 20:44:48 -0400 Subject: [PATCH 3/5] update printing of `ProductSpace{<:Any,0}` --- src/spaces/productspace.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/spaces/productspace.jl b/src/spaces/productspace.jl index b1442998b..5974422d0 100644 --- a/src/spaces/productspace.jl +++ b/src/spaces/productspace.jl @@ -71,10 +71,11 @@ dual(P::ProductSpace) = ProductSpace(map(dual, reverse(P.spaces))) function Base.show(io::IO, P::ProductSpace{S}) where {S <: ElementarySpace} spaces = P.spaces if length(spaces) == 0 - print(io, "ProductSpace{", S, ", 0}") + print(io, "one(", type_repr(S), ")") + return nothing end if length(spaces) == 1 - print(io, "ProductSpace") + print(io, "⊗") end print(io, "(") for i in 1:length(spaces) From 0d1ae533a32503ba2b91aa6ef13d622b58feb991 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 29 Oct 2025 20:44:54 -0400 Subject: [PATCH 4/5] bump v 0.15.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 04a5cb6f4..7d754d817 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TensorKit" uuid = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec" authors = ["Jutho Haegeman"] -version = "0.15.2" +version = "0.15.3" [deps] LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637" From d9536cc16befb5fab3e94fb409a81eea266987bd Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 29 Oct 2025 20:53:55 -0400 Subject: [PATCH 5/5] add tests for show --- test/symmetries/spaces.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/symmetries/spaces.jl b/test/symmetries/spaces.jl index a9edb5828..a952d4b6b 100644 --- a/test/symmetries/spaces.jl +++ b/test/symmetries/spaces.jl @@ -452,4 +452,12 @@ end end 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" +end + TensorKit.empty_globalcaches!()