From fe509f797b6e9a20d8026494a305d68cb7bcef5d Mon Sep 17 00:00:00 2001 From: lkdvos Date: Tue, 18 Aug 2026 10:09:26 +0200 Subject: [PATCH 1/2] overload BraidingTensor constructors properly --- src/tensors/tensoroperations.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tensors/tensoroperations.jl b/src/tensors/tensoroperations.jl index a6f660b..a4fb563 100644 --- a/src/tensors/tensoroperations.jl +++ b/src/tensors/tensoroperations.jl @@ -119,6 +119,12 @@ function TK.BraidingTensor{T, S}( V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false ) where {T, S} τtype = TK.braidingtensortype(S, T) + return τtype(V1, V2, adjoint) +end +function TK.BraidingTensor{T, S, A}( + V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false + ) where {T, S, A} + τtype = BraidingTensor{T, S, A} cod, dom = adjoint ? (V1 ⊗ V2, V2 ⊗ V1) : (V2 ⊗ V1, V1 ⊗ V2) tdst = SparseBlockTensorMap{τtype}(undef, cod, dom) Vs = eachspace(tdst) @@ -130,3 +136,12 @@ function TK.BraidingTensor{T, S}( end return tdst end + +TK.braidingtensortype(::Type{SumSpace{S}}, ::Type{TorA}) where {S <: IndexSpace, TorA} = + TK.braidingtensortype(S, TorA) + +# TODO: remove once proper promotion rules in TensorKit are in place +TK.BraidingTensor{T, S, A}(V1::S, V2::SumSpace{S}, adjoint::Bool = false) where {T, S, A} = + BraidingTensor{T, S, A}(promote(V1, V2)..., adjoint) +TK.BraidingTensor{T, S, A}(V1::SumSpace{S}, V2::S, adjoint::Bool = false) where {T, S, A} = + BraidingTensor{T, S, A}(promote(V1, V2)..., adjoint) From 7087c48eac435ed2fcf9e84a0f5179a281715293 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Tue, 18 Aug 2026 10:09:32 +0200 Subject: [PATCH 2/2] add regression test --- test/abstracttensor/braidingtensor.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/abstracttensor/braidingtensor.jl b/test/abstracttensor/braidingtensor.jl index bb0a897..14ac8c8 100644 --- a/test/abstracttensor/braidingtensor.jl +++ b/test/abstracttensor/braidingtensor.jl @@ -1,6 +1,7 @@ using Test using TestExtras using TensorKit +using TensorKit: ℙ using BlockTensorKit using Random @@ -34,3 +35,14 @@ Random.seed!(1234) @test !(y ≈ braid(x, ((2, 1), (3,)), (2, 1, 3))) end end + +@testset "Issue #68" begin + x = randn(ComplexF64, (⊞(ℙ^1) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^1)) + O = randn(ComplexF64, ((ℙ^1 ⊞ ℙ^4 ⊞ ℙ^16 ⊞ ℙ^4) ⊗ ⊞(ℙ^2)) ← (⊞(ℙ^2) ⊗ ⊞(ℙ^1))) + A = randn(ComplexF64, (ℙ^4 ⊗ F^2 ⊗ (ℙ^2)') ← ℙ^1) + Ab = randn(ComplexF64, (ℙ^4 ⊗ ℙ^2 ⊗ (ℙ^2)') ← ℙ^1) + + @plansor y[-1 -2; -3] ≔ A[-1 4 2; 1] * O[-2 6; 4 5] * τ[5 7; 2 3] * + conj(Ab[-3 6 7; 8]) * x[1 3; 8] + @test space(y) == (⊞(ℙ^4) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^4) +end