@@ -81,15 +81,6 @@ Base.length(::SectorFusionTree{<:Any,N}) where {N} = N
8181# GradedUnitRanges interface
8282GradedUnitRanges. sector_type (:: Type{<:SectorFusionTree{S}} ) where {S} = S
8383
84- function build_trees (legs:: Vararg{AbstractGradedUnitRange} )
85- tree_arrows = isdual .(legs)
86- sectors = blocklabels .(legs)
87- return mapreduce (vcat, CartesianIndices (blocklength .(legs))) do it
88- block_sectors = getindex .(sectors, Tuple (it)) # why not type stable?
89- return build_trees (block_sectors, tree_arrows)
90- end
91- end
92-
9384# SymmetrySectors interface
9485function SymmetrySectors.:× (f1:: SectorFusionTree , f2:: SectorFusionTree )
9586 @assert arrows (f1) == arrows (f2)
154145# TBD change type depending on AbelianStyle?
155146fusiontree_eltype (:: Type{<:AbstractSector} ) = Float64
156147
148+ # constructors
149+ function build_trees (legs:: Vararg{AbstractGradedUnitRange} )
150+ # construct all authorized trees for each outer block in legs
151+ tree_arrows = isdual .(legs)
152+ return mapreduce (vcat, Iterators. product (blocklabels .(legs)... )) do it
153+ return build_trees (it, tree_arrows)
154+ end
155+ end
156+
157+ function build_trees (
158+ sectors_to_fuse:: NTuple{N,<:AbstractSector} , arrows_to_fuse:: NTuple{N,Bool}
159+ ) where {N}
160+ # construct all authorized trees with fixed outer sectors
161+ trees = [SectorFusionTree (first (sectors_to_fuse), first (arrows_to_fuse))]
162+ return recursive_build_trees (trees, Base. tail (sectors_to_fuse), Base. tail (arrows_to_fuse))
163+ end
164+
157165#
158166# ===================================== Internals ========================================
159167#
@@ -205,7 +213,7 @@ function braid_tuples(t1::Tuple{Vararg{Any,N}}, t2::Tuple{Vararg{Any,N}}) where
205213 return flatten_tuples (nested)
206214end
207215
208- function grow_tree (
216+ function append_tree_leave (
209217 parent_tree:: SectorFusionTree ,
210218 branch_sector:: AbstractSector ,
211219 level_arrow:: Bool ,
@@ -221,38 +229,33 @@ function grow_tree(
221229 )
222230end
223231
224- function grow_tree (
232+ function fuse_next_sector (
225233 parent_tree:: SectorFusionTree , branch_sector:: AbstractSector , level_arrow:: Bool
226234)
227235 new_space = fusion_product (root_sector (parent_tree), branch_sector)
228236 return mapreduce (vcat, zip (blocklabels (new_space), blocklengths (new_space))) do (la, n)
229237 return [
230- grow_tree (parent_tree, branch_sector, level_arrow, la, outer_mult) for
238+ append_tree_leave (parent_tree, branch_sector, level_arrow, la, outer_mult) for
231239 outer_mult in 1 : n
232240 ]
233241 end
234242end
235243
236- function build_trees (old_trees:: Vector , sectors_to_fuse:: Tuple , arrows_to_fuse:: Tuple )
244+ function recursive_build_trees (
245+ old_trees:: Vector , sectors_to_fuse:: Tuple , arrows_to_fuse:: Tuple
246+ )
237247 next_level_trees = mapreduce (vcat, old_trees) do tree
238- return grow_tree (tree, first (sectors_to_fuse), first (arrows_to_fuse))
248+ return fuse_next_sector (tree, first (sectors_to_fuse), first (arrows_to_fuse))
239249 end
240- return build_trees (
250+ return recursive_build_trees (
241251 next_level_trees, Base. tail (sectors_to_fuse), Base. tail (arrows_to_fuse)
242252 )
243253end
244254
245- function build_trees (trees:: Vector , :: Tuple{} , :: Tuple{} )
255+ function recursive_build_trees (trees:: Vector , :: Tuple{} , :: Tuple{} )
246256 return trees
247257end
248258
249- function build_trees (
250- sectors_to_fuse:: NTuple{N,<:AbstractSector} , arrows_to_fuse:: NTuple{N,Bool}
251- ) where {N}
252- trees = [SectorFusionTree (first (sectors_to_fuse), first (arrows_to_fuse))]
253- return build_trees (trees, Base. tail (sectors_to_fuse), Base. tail (arrows_to_fuse))
254- end
255-
256259# --------------- convert to Array ---------------
257260to_array (:: SectorFusionTree{<:Any,0} ) = ones (1 )
258261
0 commit comments