Skip to content

Commit f3a4e49

Browse files
authored
Fix BraidingTensor not passing all parameters (#66)
* fix braidingtensor parameters and adjoint flag * add tests
1 parent bdcada7 commit f3a4e49

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎src/tensors/tensoroperations.jl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ end
118118
function TK.BraidingTensor{T, S}(
119119
V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false
120120
) where {T, S}
121-
τtype = BraidingTensor{T, S}
122-
tdst = SparseBlockTensorMap{τtype}(undef, V2 ⊗ V1, V1 ⊗ V2)
121+
τtype = TK.braidingtensortype(S, T)
122+
cod, dom = adjoint ? (V1 ⊗ V2, V2 ⊗ V1) : (V2 ⊗ V1, V1 ⊗ V2)
123+
tdst = SparseBlockTensorMap{τtype}(undef, cod, dom)
123124
Vs = eachspace(tdst)
124125
@inbounds for I in CartesianIndices(tdst)
125126
if I[1] == I[4] && I[2] == I[3]
126127
V = Vs[I]
127-
tdst[I] = TK.BraidingTensor{T, S}(V[2], V[1], adjoint)
128+
tdst[I] = adjoint ? τtype(V[1], V[2], true) : τtype(V[2], V[1], false)
128129
end
129130
end
130131
return tdst
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Test
2+
using TestExtras
3+
using TensorKit
4+
using BlockTensorKit
5+
using Random
6+
7+
Random.seed!(1234)
8+
9+
@testset "BraidingTensor with SumSpace: $(sectortype(V))" for V in (
10+
ℂ^2, Vect[Z2Irrep](0 => 1, 1 => 1), Vect[FibonacciAnyon](:I => 1, :τ => 1),
11+
)
12+
V1, V2 = V, V ⊕ V # V1 != V2 to test adjoint
13+
S1, S2 = SumSpace(V1), SumSpace(V2)
14+
τ = @constinferred BraidingTensor(S1, S2)
15+
16+
@test codomain(τ) == S2 ⊗ S1
17+
@test domain(τ) == S1 ⊗ S2
18+
@test TensorMap(τ[1, 1, 1, 1]) ≈ TensorMap(BraidingTensor(V1, V2))
19+
20+
t = TensorMap(τ)
21+
@test t' * t ≈ id(domain(t))
22+
τ_adj = @constinferred BraidingTensor(S1, S2, true)
23+
@test codomain(τ_adj) == S1 ⊗ S2
24+
@test domain(τ_adj) == S2 ⊗ S1
25+
@test TensorMap(τ_adj) ≈ t'
26+
27+
# agree with TensorKit's `braid`
28+
Sa, Sb, W = SumSpace(V1, V2), SumSpace(V2), SumSpace(V1)
29+
x = randn(ComplexF64, Sa ⊗ Sb, W)
30+
τm = @constinferred BraidingTensor(Sa, Sb)
31+
@plansor y[-1 -2; -3] := τm[-1 -2; 1 2] * x[1 2; -3]
32+
@test y ≈ braid(x, ((2, 1), (3,)), (1, 2, 3))
33+
if !(BraidingStyle(sectortype(V)) isa SymmetricBraiding)
34+
@test !(y ≈ braid(x, ((2, 1), (3,)), (2, 1, 3)))
35+
end
36+
end

‎test/runtests.jl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const GROUP = uppercase(
2828
@time @safetestset "SparseBlockTensor" begin
2929
include("abstracttensor/sparseblocktensor.jl")
3030
end
31+
@time @safetestset "BraidingTensor" begin
32+
include("abstracttensor/braidingtensor.jl")
33+
end
3134
end
3235

3336
if GROUP == "ALL" || GROUP == "LINALG"

0 commit comments

Comments
 (0)