Skip to content

Commit 746b3f2

Browse files
committed
various utility functions
1 parent bbeb8e5 commit 746b3f2

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/spaces/homspace.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const TensorMapSpace{S <: ElementarySpace, N₁, N₂} = HomSpace{
5050
S, ProductSpace{S, N₁},
5151
ProductSpace{S, N₂},
5252
}
53+
numout(::Type{TensorMapSpace{S, N₁, N₂}}) where {S, N₁, N₂} = N₁
54+
numin(::Type{TensorMapSpace{S, N₁, N₂}}) where {S, N₁, N₂} = N₂
55+
numind(T::Type{TensorMapSpace{S, N₁, N₂}}) where {S, N₁, N₂} = numout(T) + numin(T)
5356

5457
function Base.getindex(W::TensorMapSpace{<:IndexSpace, N₁, N₂}, i) where {N₁, N₂}
5558
return i <= N₁ ? codomain(W)[i] : dual(domain(W)[i - N₁])
@@ -139,18 +142,33 @@ fusiontrees(W::HomSpace) = fusionblockstructure(W).fusiontreelist
139142
# Operations on HomSpaces
140143
# -----------------------
141144
"""
142-
permute(W::HomSpace, (p₁, p₂)::Index2Tuple{N₁,N₂})
145+
permute(W::HomSpace, (p₁, p₂)::Index2Tuple)
143146
144147
Return the `HomSpace` obtained by permuting the indices of the domain and codomain of `W`
145148
according to the permutation `p₁` and `p₂` respectively.
146149
"""
147-
function permute(W::HomSpace{S}, (p₁, p₂)::Index2Tuple{N₁, N₂}) where {S, N₁, N₂}
150+
function permute(W::HomSpace, (p₁, p₂)::Index2Tuple)
148151
p = (p₁..., p₂...)
149152
TupleTools.isperm(p) && length(p) == numind(W) ||
150153
throw(ArgumentError("$((p₁, p₂)) is not a valid permutation for $(W)"))
151154
return select(W, (p₁, p₂))
152155
end
153156

157+
_transpose_indices(W::HomSpace) = (reverse(domainind(W)), reverse(codomainind(W)))
158+
159+
function LinearAlgebra.transpose(W::HomSpace, (p₁, p₂)::Index2Tuple = _transpose_indices(W))
160+
p = linearizepermutation(p₁, p₂, numout(W), numin(W))
161+
iscyclicpermutation(p) || throw(ArgumentError(lazy"$((p₁, p₂)) is not a cyclic permutation for $W"))
162+
return select(W, (p₁, p₂))
163+
end
164+
165+
function braid(W::HomSpace, (p₁, p₂)::Index2Tuple, lvls::IndexTuple)
166+
p = (p₁..., p₂...)
167+
TupleTools.isperm(p) && length(p) == numind(W) == length(lvls) ||
168+
throw(ArgumentError("$((p₁, p₂)), $lvls is not a valid braiding for $(W)"))
169+
return select(W, (p₁, p₂))
170+
end
171+
154172
"""
155173
select(W::HomSpace, (p₁, p₂)::Index2Tuple{N₁,N₂})
156174

src/tensors/abstracttensor.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,40 @@ numind(::Type{TT}) where {TT <: AbstractTensorMap} = numin(TT) + numout(TT)
119119
const order = numind
120120

121121
"""
122-
codomainind(::Union{TT,Type{TT}}) where {TT<:AbstractTensorMap} -> Tuple{Int}
122+
codomainind(::Union{TT, Type{TT}}) where {TT <: Union{HomSpace, AbstractTensorMap}} -> Tuple{Int}
123123
124-
Return all indices of the codomain of a tensor.
124+
Return all indices of the codomain of a tensor or tensor space.
125125
126126
See also [`domainind`](@ref) and [`allind`](@ref).
127127
"""
128-
function codomainind(::Type{TT}) where {TT <: AbstractTensorMap}
128+
function codomainind(::Type{TT}) where {TT <: Union{AbstractTensorMap, HomSpace}}
129129
return ntuple(identity, numout(TT))
130130
end
131-
codomainind(t::AbstractTensorMap) = codomainind(typeof(t))
131+
codomainind(t::Union{AbstractTensorMap, HomSpace}) = codomainind(typeof(t))
132132

133133
"""
134134
domainind(::Union{TT,Type{TT}}) where {TT<:AbstractTensorMap} -> Tuple{Int}
135135
136-
Return all indices of the domain of a tensor.
136+
Return all indices of the domain of a tensor or tensor space.
137137
138138
See also [`codomainind`](@ref) and [`allind`](@ref).
139139
"""
140-
function domainind(::Type{TT}) where {TT <: AbstractTensorMap}
140+
function domainind(::Type{TT}) where {TT <: Union{HomSpace, AbstractTensorMap}}
141141
return ntuple(n -> numout(TT) + n, numin(TT))
142142
end
143-
domainind(t::AbstractTensorMap) = domainind(typeof(t))
143+
domainind(t::Union{AbstractTensorMap, HomSpace}) = domainind(typeof(t))
144144

145145
"""
146146
allind(::Union{TT,Type{TT}}) where {TT<:AbstractTensorMap} -> Tuple{Int}
147147
148-
Return all indices of a tensor, i.e. the indices of its domain and codomain.
148+
Return all indices of a tensor or tensor space, i.e. the indices of its domain and codomain.
149149
150150
See also [`codomainind`](@ref) and [`domainind`](@ref).
151151
"""
152-
function allind(::Type{TT}) where {TT <: AbstractTensorMap}
152+
function allind(::Type{TT}) where {TT <: Union{HomSpace, AbstractTensorMap}}
153153
return ntuple(identity, numind(TT))
154154
end
155-
allind(t::AbstractTensorMap) = allind(typeof(t))
155+
allind(t::Union{HomSpace, AbstractTensorMap}) = allind(typeof(t))
156156

157157
function adjointtensorindex(t::AbstractTensorMap, i)
158158
return ifelse(i <= numout(t), numin(t) + i, i - numout(t))

0 commit comments

Comments
 (0)