Skip to content

Commit 9a07b42

Browse files
committed
Use braidingtensortype
1 parent 8e515b5 commit 9a07b42

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/planar/preprocessors.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ function _construct_braidingtensors!(ex, preargs, indexmap, non_braiding) # ex i
184184
if foundV1 && foundV2
185185
s = gensym()
186186
storageex = Expr(:call, GlobalRef(TensorKit, :promote_storagetype), non_braiding...)
187-
constructex = Expr(:call, GlobalRef(TensorKit, :BraidingTensor), storageex, V1, V2)
187+
braidingex = Expr(:call, GlobalRef(TensorKit, :braidingtensortype), V1, V2, storageex)
188+
constructex = Expr(:call, braidingex, V1, V2)
188189
push!(preargs, Expr(:(=), s, constructex))
189190
obj = _is_adjoint(obj) ? _add_adjoint(s) : s
190191
success = true

src/tensors/braidingtensor.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,30 @@ function BraidingTensor{T}(V::HomSpace, adjoint::Bool = false) where {T}
5353
throw(SpaceMismatch("Cannot define a braiding on $V"))
5454
return BraidingTensor{T}(V[2], V[1], adjoint)
5555
end
56+
57+
function Base.adjoint(b::BraidingTensor{T, S, A}) where {T, S, A}
58+
return BraidingTensor{T, S, A}(b.V1, b.V2, !b.adjoint)
59+
end
60+
5661
# these are here to make the preprocessing for `@planar` expressions less painful
57-
function BraidingTensor(TorA::Type, V1::S, V2::S, adjoint::Bool = false) where {S <: IndexSpace}
62+
function braidingtensortype(::Type{S}, ::Type{TorA}) where {S <: IndexSpace, TorA}
5863
T = eltype(TorA)
5964
TA = similarstoragetype(TorA)
60-
return BraidingTensor{T, S, TA}(V1, V2, adjoint)
65+
return BraidingTensor{T, S, TA}
6166
end
62-
function BraidingTensor(TorA::Type, V1::IndexSpace, V2::IndexSpace, adjoint::Bool = false)
63-
return BraidingTensor(TorA, promote(V1, V2)..., adjoint)
67+
braidingtensortype(V::S, ::Type{TorA}) where {S <: IndexSpace, TorA} = braidingtensortype(S, TorA)
68+
braidingtensortype(V1::S, V2::S, ::Type{TorA}) where {S <: IndexSpace, TorA} = braidingtensortype(S, TorA)
69+
function braidingtensortype(V1::IndexSpace, V2::IndexSpace, ::Type{TorA}) where {TorA}
70+
S = promote(V1, V2)
71+
return braidingtensortype(S..., TorA)
6472
end
65-
function BraidingTensor(TorA::Type, V::HomSpace, adjoint::Bool = false)
73+
function braidingtensortype(V::HomSpace, ::Type{TorA}) where {TorA}
6674
domain(V) == reverse(codomain(V)) ||
6775
throw(SpaceMismatch("Cannot define a braiding on $V"))
6876
T = eltype(TorA)
6977
S = spacetype(V[2])
70-
TA = storagetype(TorA)
71-
return BraidingTensor{T, S, TA}(V[2], V[1], adjoint)
72-
end
73-
function Base.adjoint(b::BraidingTensor{T, S, A}) where {T, S, A}
74-
return BraidingTensor{T, S, A}(b.V1, b.V2, !b.adjoint)
78+
TA = similarstoragetype(TorA)
79+
return braidingtensortype(S, TA)
7580
end
7681

7782
storagetype(::Type{BraidingTensor{T, S, A}}) where {T, S, A} = A

0 commit comments

Comments
 (0)