Skip to content

Commit ee0152d

Browse files
authored
BraidingTensor constructors with SumSpace instances (#69)
1 parent f3a4e49 commit ee0152d

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/tensors/tensoroperations.jl‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ function TK.BraidingTensor{T, S}(
119119
V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false
120120
) where {T, S}
121121
τtype = TK.braidingtensortype(S, T)
122+
return τtype(V1, V2, adjoint)
123+
end
124+
function TK.BraidingTensor{T, S, A}(
125+
V1::SumSpace{S}, V2::SumSpace{S}, adjoint::Bool = false
126+
) where {T, S, A}
127+
τtype = BraidingTensor{T, S, A}
122128
cod, dom = adjoint ? (V1 ⊗ V2, V2 ⊗ V1) : (V2 ⊗ V1, V1 ⊗ V2)
123129
tdst = SparseBlockTensorMap{τtype}(undef, cod, dom)
124130
Vs = eachspace(tdst)
@@ -130,3 +136,12 @@ function TK.BraidingTensor{T, S}(
130136
end
131137
return tdst
132138
end
139+
140+
TK.braidingtensortype(::Type{SumSpace{S}}, ::Type{TorA}) where {S <: IndexSpace, TorA} =
141+
TK.braidingtensortype(S, TorA)
142+
143+
# TODO: remove once proper promotion rules in TensorKit are in place
144+
TK.BraidingTensor{T, S, A}(V1::S, V2::SumSpace{S}, adjoint::Bool = false) where {T, S, A} =
145+
BraidingTensor{T, S, A}(promote(V1, V2)..., adjoint)
146+
TK.BraidingTensor{T, S, A}(V1::SumSpace{S}, V2::S, adjoint::Bool = false) where {T, S, A} =
147+
BraidingTensor{T, S, A}(promote(V1, V2)..., adjoint)

‎test/abstracttensor/braidingtensor.jl‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22
using TestExtras
33
using TensorKit
4+
using TensorKit: ℙ
45
using BlockTensorKit
56
using Random
67

@@ -34,3 +35,14 @@ Random.seed!(1234)
3435
@test !(y ≈ braid(x, ((2, 1), (3,)), (2, 1, 3)))
3536
end
3637
end
38+
39+
@testset "Issue #68" begin
40+
x = randn(ComplexF64, (⊞(ℙ^1) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^1))
41+
O = randn(ComplexF64, ((ℙ^1 ⊞ ℙ^4 ⊞ ℙ^16 ⊞ ℙ^4) ⊗ ⊞(ℙ^2)) ← (⊞(ℙ^2) ⊗ ⊞(ℙ^1)))
42+
A = randn(ComplexF64, (ℙ^4 ⊗ F^2 ⊗ (ℙ^2)') ← ℙ^1)
43+
Ab = randn(ComplexF64, (ℙ^4 ⊗ ℙ^2 ⊗ (ℙ^2)') ← ℙ^1)
44+
45+
@plansor y[-1 -2; -3] ≔ A[-1 4 2; 1] * O[-2 6; 4 5] * τ[5 7; 2 3] *
46+
conj(Ab[-3 6 7; 8]) * x[1 3; 8]
47+
@test space(y) == (⊞(ℙ^4) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^4)
48+
end

0 commit comments

Comments
 (0)