From 9be7c5221568f4113abd073c76ff60c253f50956 Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Tue, 4 Aug 2026 18:03:30 +0200 Subject: [PATCH 1/2] fix braidingtensor parameters and adjoint flag --- src/tensors/tensoroperations.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tensors/tensoroperations.jl b/src/tensors/tensoroperations.jl index 80bb85a..a6f660b 100644 --- a/src/tensors/tensoroperations.jl +++ b/src/tensors/tensoroperations.jl @@ -118,13 +118,14 @@ end function TK.BraidingTensor{T, S}( V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false ) where {T, S} - τtype = BraidingTensor{T, S} - tdst = SparseBlockTensorMap{τtype}(undef, V2 ⊗ V1, V1 ⊗ V2) + τtype = TK.braidingtensortype(S, T) + cod, dom = adjoint ? (V1 ⊗ V2, V2 ⊗ V1) : (V2 ⊗ V1, V1 ⊗ V2) + tdst = SparseBlockTensorMap{τtype}(undef, cod, dom) Vs = eachspace(tdst) @inbounds for I in CartesianIndices(tdst) if I[1] == I[4] && I[2] == I[3] V = Vs[I] - tdst[I] = TK.BraidingTensor{T, S}(V[2], V[1], adjoint) + tdst[I] = adjoint ? τtype(V[1], V[2], true) : τtype(V[2], V[1], false) end end return tdst From 82509beafa51d7b77e4a8eca3f8be274a02a790f Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Tue, 4 Aug 2026 18:04:17 +0200 Subject: [PATCH 2/2] add tests --- test/abstracttensor/braidingtensor.jl | 36 +++++++++++++++++++++++++++ test/runtests.jl | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 test/abstracttensor/braidingtensor.jl diff --git a/test/abstracttensor/braidingtensor.jl b/test/abstracttensor/braidingtensor.jl new file mode 100644 index 0000000..bb0a897 --- /dev/null +++ b/test/abstracttensor/braidingtensor.jl @@ -0,0 +1,36 @@ +using Test +using TestExtras +using TensorKit +using BlockTensorKit +using Random + +Random.seed!(1234) + +@testset "BraidingTensor with SumSpace: $(sectortype(V))" for V in ( + ℂ^2, Vect[Z2Irrep](0 => 1, 1 => 1), Vect[FibonacciAnyon](:I => 1, :τ => 1), + ) + V1, V2 = V, V ⊕ V # V1 != V2 to test adjoint + S1, S2 = SumSpace(V1), SumSpace(V2) + τ = @constinferred BraidingTensor(S1, S2) + + @test codomain(τ) == S2 ⊗ S1 + @test domain(τ) == S1 ⊗ S2 + @test TensorMap(τ[1, 1, 1, 1]) ≈ TensorMap(BraidingTensor(V1, V2)) + + t = TensorMap(τ) + @test t' * t ≈ id(domain(t)) + τ_adj = @constinferred BraidingTensor(S1, S2, true) + @test codomain(τ_adj) == S1 ⊗ S2 + @test domain(τ_adj) == S2 ⊗ S1 + @test TensorMap(τ_adj) ≈ t' + + # agree with TensorKit's `braid` + Sa, Sb, W = SumSpace(V1, V2), SumSpace(V2), SumSpace(V1) + x = randn(ComplexF64, Sa ⊗ Sb, W) + τm = @constinferred BraidingTensor(Sa, Sb) + @plansor y[-1 -2; -3] := τm[-1 -2; 1 2] * x[1 2; -3] + @test y ≈ braid(x, ((2, 1), (3,)), (1, 2, 3)) + if !(BraidingStyle(sectortype(V)) isa SymmetricBraiding) + @test !(y ≈ braid(x, ((2, 1), (3,)), (2, 1, 3))) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 41e8d5a..8ffb374 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,6 +28,9 @@ const GROUP = uppercase( @time @safetestset "SparseBlockTensor" begin include("abstracttensor/sparseblocktensor.jl") end + @time @safetestset "BraidingTensor" begin + include("abstracttensor/braidingtensor.jl") + end end if GROUP == "ALL" || GROUP == "LINALG"