Skip to content

Commit 7aad297

Browse files
committed
improve names and loops
1 parent c754d35 commit 7aad297

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/fusion_trees/fusiontree.jl

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ Base.length(::SectorFusionTree{<:Any,N}) where {N} = N
8181
# GradedUnitRanges interface
8282
GradedUnitRanges.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
9485
function SymmetrySectors.:×(f1::SectorFusionTree, f2::SectorFusionTree)
9586
@assert arrows(f1) == arrows(f2)
@@ -154,6 +145,23 @@ end
154145
# TBD change type depending on AbelianStyle?
155146
fusiontree_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)
206214
end
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
)
222230
end
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
234242
end
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
)
243253
end
244254

245-
function build_trees(trees::Vector, ::Tuple{}, ::Tuple{})
255+
function recursive_build_trees(trees::Vector, ::Tuple{}, ::Tuple{})
246256
return trees
247257
end
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 ---------------
257260
to_array(::SectorFusionTree{<:Any,0}) = ones(1)
258261

src/fusiontensor/fusiontensor.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,20 @@ end
165165
function fusion_trees_external_multiplicities(
166166
outer_legs::Tuple{Vararg{AbstractGradedUnitRange}}
167167
)
168-
return mapreduce(vcat, CartesianIndices(blocklength.(outer_legs))) do it
169-
return fusion_trees_external_multiplicities(outer_legs, Tuple(it))
170-
end
168+
return Iterators.flatten(
169+
block_fusion_trees_external_multiplicities.(Iterators.product(blocks.(outer_legs)...))
170+
)
171171
end
172172

173-
function fusion_trees_external_multiplicities(
174-
outer_legs::NTuple{N,AbstractGradedUnitRange}, indices::NTuple{N,Int}
173+
function block_fusion_trees_external_multiplicities(
174+
it::NTuple{N,AbstractUnitRange}
175175
) where {N}
176-
block_sectors = map((g, i) -> blocklabels(g)[i], outer_legs, indices)
177-
block_mult = mapreduce((g, i) -> blocklengths(g)[i], *, outer_legs, indices; init=1)
178-
return build_trees(block_sectors, isdual.(outer_legs)) .=> block_mult
176+
block_sectors = only.(blocklabels.(it))
177+
block_mult = prod(length.(it))
178+
return build_trees(block_sectors, isdual.(it)) .=> block_mult
179179
end
180180

181-
function compute_inner_ranges(
182-
fusion_trees_mult::AbstractVector{<:Pair{<:SectorFusionTree,<:Integer}}
183-
)
181+
function compute_inner_ranges(fusion_trees_mult)
184182
fused_leg = blockmergesort(
185183
gradedrange(root_sector.(first.(fusion_trees_mult)) .=> last.(fusion_trees_mult))
186184
)

0 commit comments

Comments
 (0)