@@ -8,18 +8,18 @@ Represents the linear space of morphisms with codomain of type `P1` and domain o
88Note that HomSpace is not a subtype of VectorSpace, i.e. we restrict the latter to denote
99certain categories and their objects, and keep HomSpace distinct.
1010"""
11- struct HomSpace{S<: ElementarySpace ,P1 <: CompositeSpace{S} ,P2 <: CompositeSpace{S} }
11+ struct HomSpace{S <: ElementarySpace , P1 <: CompositeSpace{S} , P2 <: CompositeSpace{S} }
1212 codomain:: P1
1313 domain:: P2
1414end
1515
16- function HomSpace (codomain:: S , domain:: CompositeSpace{S} ) where {S<: ElementarySpace }
16+ function HomSpace (codomain:: S , domain:: CompositeSpace{S} ) where {S <: ElementarySpace }
1717 return HomSpace (⊗ (codomain), domain)
1818end
19- function HomSpace (codomain:: CompositeSpace{S} , domain:: S ) where {S<: ElementarySpace }
19+ function HomSpace (codomain:: CompositeSpace{S} , domain:: S ) where {S <: ElementarySpace }
2020 return HomSpace (codomain, ⊗ (domain))
2121end
22- function HomSpace (codomain:: S , domain:: S ) where {S<: ElementarySpace }
22+ function HomSpace (codomain:: S , domain:: S ) where {S <: ElementarySpace }
2323 return HomSpace (⊗ (codomain), ⊗ (domain))
2424end
2525HomSpace (codomain:: VectorSpace ) = HomSpace (codomain, zerospace (codomain))
@@ -45,18 +45,20 @@ numout(W::HomSpace) = length(codomain(W))
4545numin (W:: HomSpace ) = length (domain (W))
4646numind (W:: HomSpace ) = numin (W) + numout (W)
4747
48- const TensorSpace{S<: ElementarySpace } = Union{S,ProductSpace{S}}
49- const TensorMapSpace{S<: ElementarySpace ,N₁,N₂} = HomSpace{S,ProductSpace{S,N₁},
50- ProductSpace{S,N₂}}
48+ const TensorSpace{S <: ElementarySpace } = Union{S, ProductSpace{S}}
49+ const TensorMapSpace{S <: ElementarySpace , N₁, N₂} = HomSpace{
50+ S, ProductSpace{S, N₁},
51+ ProductSpace{S, N₂},
52+ }
5153
52- function Base. getindex (W:: TensorMapSpace{<:IndexSpace,N₁,N₂} , i) where {N₁,N₂}
54+ function Base. getindex (W:: TensorMapSpace{<:IndexSpace, N₁, N₂} , i) where {N₁, N₂}
5355 return i <= N₁ ? codomain (W)[i] : dual (domain (W)[i - N₁])
5456end
5557
56- function ← (codom:: ProductSpace{S} , dom:: ProductSpace{S} ) where {S<: ElementarySpace }
58+ function ← (codom:: ProductSpace{S} , dom:: ProductSpace{S} ) where {S <: ElementarySpace }
5759 return HomSpace (codom, dom)
5860end
59- function ← (codom:: S , dom:: S ) where {S<: ElementarySpace }
61+ function ← (codom:: S , dom:: S ) where {S <: ElementarySpace }
6062 return HomSpace (ProductSpace (codom), ProductSpace (dom))
6163end
6264← (codom:: VectorSpace , dom:: VectorSpace ) = ← (promote (codom, dom)... )
@@ -69,7 +71,7 @@ function Base.show(io::IO, W::HomSpace)
6971 print (io, W. codomain)
7072 end
7173 print (io, " ← " )
72- if length (W. domain) == 1
74+ return if length (W. domain) == 1
7375 print (io, W. domain[1 ])
7476 else
7577 print (io, W. domain)
@@ -94,7 +96,7 @@ function blocksectors(W::HomSpace)
9496 N₁ = length (codom)
9597 N₂ = length (dom)
9698 I = sectortype (W)
97- if N₁ == 0 && N₂ == 0
99+ if N₁ == 0 && N₂ == 0
98100 return allunits (I)
99101 elseif N₁ == 0
100102 return filter! (isone, collect (blocksectors (dom))) # module space cannot end in empty space
@@ -130,6 +132,8 @@ function dim(W::HomSpace)
130132 return d
131133end
132134
135+ dims (W:: HomSpace ) = (dims (codomain (W))... , dims (domain (W))... )
136+
133137"""
134138 fusiontrees(W::HomSpace)
135139
@@ -145,7 +149,7 @@ fusiontrees(W::HomSpace) = fusionblockstructure(W).fusiontreelist
145149Return the `HomSpace` obtained by permuting the indices of the domain and codomain of `W`
146150according to the permutation `p₁` and `p₂` respectively.
147151"""
148- function permute (W:: HomSpace{S} , (p₁, p₂):: Index2Tuple{N₁,N₂} ) where {S,N₁,N₂}
152+ function permute (W:: HomSpace{S} , (p₁, p₂):: Index2Tuple{N₁, N₂} ) where {S, N₁, N₂}
149153 p = (p₁... , p₂... )
150154 TupleTools. isperm (p) && length (p) == numind (W) ||
151155 throw (ArgumentError (" $((p₁, p₂)) is not a valid permutation for $(W) " ))
158162Return the `HomSpace` obtained by a selection from the domain and codomain of `W` according
159163to the indices in `p₁` and `p₂` respectively.
160164"""
161- function select (W:: HomSpace{S} , (p₁, p₂):: Index2Tuple{N₁,N₂} ) where {S,N₁,N₂}
162- cod = ProductSpace {S,N₁} (map (n -> W[n], p₁))
163- dom = ProductSpace {S,N₂} (map (n -> dual (W[n]), p₂))
165+ function select (W:: HomSpace{S} , (p₁, p₂):: Index2Tuple{N₁, N₂} ) where {S, N₁, N₂}
166+ cod = ProductSpace {S, N₁} (map (n -> W[n], p₁))
167+ dom = ProductSpace {S, N₂} (map (n -> dual (W[n]), p₂))
164168 return cod ← dom
165169end
166170
@@ -201,8 +205,10 @@ More specifically, adds a left monoidal unit or its dual.
201205See also [`insertrightunitspace`](@ref insertrightunitspace(::HomSpace, ::Val{i}) where {i}),
202206[`removeunitspace`](@ref removeunitspace(::HomSpace, ::Val{i}) where {i}).
203207"""
204- function insertleftunitspace (W:: HomSpace , :: Val{i} = Val (numind (W) + 1 );
205- conj:: Bool = false , dual:: Bool = false ) where {i}
208+ function insertleftunitspace (
209+ W:: HomSpace , :: Val{i} = Val (numind (W) + 1 );
210+ conj:: Bool = false , dual:: Bool = false
211+ ) where {i}
206212 if i ≤ numout (W)
207213 return insertleftunitspace (codomain (W), Val (i); conj, dual) ← domain (W)
208214 else
@@ -220,8 +226,10 @@ More specifically, adds a right monoidal unit or its dual.
220226See also [`insertleftunitspace`](@ref insertleftunitspace(::HomSpace, ::Val{i}) where {i}),
221227[`removeunitspace`](@ref removeunitspace(::HomSpace, ::Val{i}) where {i}).
222228"""
223- function insertrightunitspace (W:: HomSpace , :: Val{i} = Val (numind (W));
224- conj:: Bool = false , dual:: Bool = false ) where {i}
229+ function insertrightunitspace (
230+ W:: HomSpace , :: Val{i} = Val (numind (W));
231+ conj:: Bool = false , dual:: Bool = false
232+ ) where {i}
225233 if i ≤ numout (W)
226234 return insertrightunitspace (codomain (W), Val (i); conj, dual) ← domain (W)
227235 else
@@ -251,14 +259,14 @@ end
251259# --------------------------------------------------------------------------
252260
253261# sizes, strides, offset
254- const StridedStructure{N} = Tuple{NTuple{N,Int},NTuple{N,Int},Int}
262+ const StridedStructure{N} = Tuple{NTuple{N, Int}, NTuple{N, Int}, Int}
255263
256- struct FusionBlockStructure{I,N, F₁,F₂}
264+ struct FusionBlockStructure{I, N, F₁, F₂}
257265 totaldim:: Int
258- blockstructure:: SectorDict{I,Tuple{Tuple{Int,Int},UnitRange{Int}}}
259- fusiontreelist:: Vector{Tuple{F₁,F₂}}
266+ blockstructure:: SectorDict{I, Tuple{Tuple{Int, Int}, UnitRange{Int}}}
267+ fusiontreelist:: Vector{Tuple{F₁, F₂}}
260268 fusiontreestructure:: Vector{StridedStructure{N}}
261- fusiontreeindices:: FusionTreeDict{Tuple{F₁,F₂},Int}
269+ fusiontreeindices:: FusionTreeDict{Tuple{F₁, F₂}, Int}
262270end
263271
264272function fusionblockstructuretype (W:: HomSpace )
@@ -268,7 +276,7 @@ function fusionblockstructuretype(W::HomSpace)
268276 I = sectortype (W)
269277 F₁ = fusiontreetype (I, N₁)
270278 F₂ = fusiontreetype (I, N₂)
271- return FusionBlockStructure{I,N, F₁,F₂}
279+ return FusionBlockStructure{I, N, F₁, F₂}
272280end
273281
274282@cached function fusionblockstructure (W:: HomSpace ):: fusionblockstructuretype (W)
@@ -281,13 +289,13 @@ end
281289 F₂ = fusiontreetype (I, N₂)
282290
283291 # output structure
284- blockstructure = SectorDict {I,Tuple{Tuple{Int,Int},UnitRange{Int}}} () # size, range
285- fusiontreelist = Vector {Tuple{F₁,F₂}} ()
286- fusiontreestructure = Vector {Tuple{NTuple{N₁ + N₂,Int},NTuple{N₁ + N₂,Int},Int}} () # size, strides, offset
292+ blockstructure = SectorDict {I, Tuple{Tuple{Int, Int}, UnitRange{Int}}} () # size, range
293+ fusiontreelist = Vector {Tuple{F₁, F₂}} ()
294+ fusiontreestructure = Vector {Tuple{NTuple{N₁ + N₂, Int}, NTuple{N₁ + N₂, Int}, Int}} () # size, strides, offset
287295
288296 # temporary data structures
289297 splittingtrees = Vector {F₁} ()
290- splittingstructure = Vector {Tuple{Int,Int}} ()
298+ splittingstructure = Vector {Tuple{Int, Int}} ()
291299
292300 # main computational routine
293301 blockoffset = 0
@@ -327,15 +335,17 @@ end
327335 blockstructure[c] = (blocksize, blockrange)
328336 end
329337
330- fusiontreeindices = sizehint! (FusionTreeDict {Tuple{F₁,F₂},Int} (),
331- length (fusiontreelist))
338+ fusiontreeindices = sizehint! (
339+ FusionTreeDict {Tuple{F₁, F₂}, Int} (),
340+ length (fusiontreelist)
341+ )
332342 for (i, f₁₂) in enumerate (fusiontreelist)
333343 fusiontreeindices[f₁₂] = i
334344 end
335345 totaldim = blockoffset
336- structure = FusionBlockStructure (totaldim, blockstructure,
337- fusiontreelist, fusiontreestructure,
338- fusiontreeindices )
346+ structure = FusionBlockStructure (
347+ totaldim, blockstructure, fusiontreelist, fusiontreestructure, fusiontreeindices
348+ )
339349 return structure
340350end
341351
357367function diagonalblockstructure (W:: HomSpace )
358368 ((numin (W) == numout (W) == 1 ) && domain (W) == codomain (W)) ||
359369 throw (SpaceMismatch (" Diagonal only support on V←V with a single space V" ))
360- structure = SectorDict {sectortype(W),UnitRange{Int}} () # range
370+ structure = SectorDict {sectortype(W), UnitRange{Int}} () # range
361371 offset = 0
362372 dom = domain (W)[1 ]
363373 for c in blocksectors (W)
0 commit comments