Skip to content

Commit

Permalink
Change braidingtensor syntax to resolve ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Mar 18, 2024
1 parent a3de709 commit ddf2261
Showing 1 changed file with 31 additions and 40 deletions.
71 changes: 31 additions & 40 deletions src/tensors/braidingtensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ end
# TensorOperations
# ----------------
# TODO: implement specialized methods

function TO.tensoradd!(C::AbstractTensorMap, pC::Index2Tuple,
A::BraidingTensor, conjA::Symbol, α::Number, β::Number,
backend::Backend...)
Expand All @@ -217,21 +218,28 @@ end

# Planar operations
# -----------------
# TODO: implement specialized methods

function planaradd!(C::AbstractTensorMap,
A::BraidingTensor, p::Index2Tuple,
α::Number, β::Number,
backend::Backend...)
return planaradd!(C, copy(A), p, α, β, backend...)
end

function planarcontract!(C::AbstractTensorMap{<:Number,S,N₁,N₂},
A::BraidingTensor{<:Number,S},
(oindA, cindA)::Index2Tuple{2,2},
B::AbstractTensorMap{<:Number,S},
(cindB, oindB)::Index2Tuple{2,N₃},
(p1, p2)::Index2Tuple{N₁,N₂},
function planarcontract!(C::AbstractTensorMap,
A::BraidingTensor,
(oindA, cindA)::Index2Tuple,
B::AbstractTensorMap,
(cindB, oindB)::Index2Tuple,
(p1, p2)::Index2Tuple,
α::Number, β::Number,
backend::Backend...) where {S<:IndexSpace,N₁,N₂,N₃}
backend::Backend...)
# special case only defined for contracting 2 indices
length(oindA) == length(cindA) == 2 ||
return planarcontract!(C, copy(A), (oindA, cindA), B, (cindB, oindB), (p1, p2),
α, β, backend...)

codA, domA = codomainind(A), domainind(A)
codB, domB = codomainind(B), domainind(B)
oindA, cindA, oindB, cindB = reorder_indices(codA, domA, codB, domB, oindA, cindA,
Expand Down Expand Up @@ -270,14 +278,19 @@ function planarcontract!(C::AbstractTensorMap{<:Number,S,N₁,N₂},
end
return C
end
function planarcontract!(C::AbstractTensorMap{<:Number,S,N₁,N₂},
A::AbstractTensorMap{<:Number,S},
(oindA, cindA)::Index2Tuple{N₃,2},
B::BraidingTensor{<:Number,S},
(cindB, oindB)::Index2Tuple{2,2},
(p1, p2)::Index2Tuple{N₁,N₂},
function planarcontract!(C::AbstractTensorMap,
A::AbstractTensorMap,
(oindA, cindA)::Index2Tuple,
B::BraidingTensor,
(cindB, oindB)::Index2Tuple,
(p1, p2)::Index2Tuple,
α::Number, β::Number,
backend::Backend...) where {S<:IndexSpace,N₁,N₂,N₃}
backend::Backend...)
# special case only defined for contracting 2 indices
length(oindB) == length(cindB) == 2 ||
return planarcontract!(C, A, (oindA, cindA), copy(B), (cindB, oindB), (p1, p2),
α, β, backend...)

codA, domA = codomainind(A), domainind(A)
codB, domB = codomainind(B), domainind(B)
oindA, cindA, oindB, cindB = reorder_indices(codA, domA, codB, domB, oindA, cindA,
Expand Down Expand Up @@ -316,34 +329,12 @@ function planarcontract!(C::AbstractTensorMap{<:Number,S,N₁,N₂},
end
return C
end
function planarcontract!(C::AbstractTensorMap{<:Number,S,N₁,N₂},
A::BraidingTensor{<:Number,S},
(oindA, cindA)::Index2Tuple{2,2},
B::BraidingTensor{<:Number,S},
(cindB, oindB)::Index2Tuple{2,2},
(p1, p2)::Index2Tuple{N₁,N₂},
α::Number, β::Number,
backend::Backend...) where {S<:IndexSpace,N₁,N₂}
return planarcontract!(C, copy(A), (oindA, cindA), B, (cindB, oindB), (p1, p2), α, β,
backend...)
end

# Fallback cases for planarcontract!
# TODO: implement specialised cases for contracting 0, 1, 3 and 4 indices
function planarcontract!(C::AbstractTensorMap, A::BraidingTensor, pA::Index2Tuple,
B::BraidingTensor, pB::Index2Tuple, α::Number, β::Number,
backend::Backend...)
return planarcontract!(C, copy(A), pA, copy(B), pB, α, β, backend...)
end
# ambiguity fix:
function planarcontract!(C::AbstractTensorMap, A::BraidingTensor, pA::Index2Tuple,
B::AbstractTensorMap, pB::Index2Tuple, α::Number, β::Number,
backend::Backend...)
return planarcontract!(C, copy(A), pA, B, pB, α, β, backend...)
end
function planarcontract!(C::AbstractTensorMap, A::AbstractTensorMap, pA::Index2Tuple,
B::BraidingTensor, pB::Index2Tuple, α::Number, β::Number,
backend::Backend...)
return planarcontract!(C, A, pA, copy(B), pB, α, β, backend...)
B::BraidingTensor, pB::Index2Tuple, pC::Index2Tuple,
α::Number, β::Number, backend::Backend...)
return planarcontract!(C, copy(A), pA, copy(B), pB, pC, α, β, backend...)
end

function planartrace!(C::AbstractTensorMap,
Expand Down

0 comments on commit ddf2261

Please sign in to comment.