Skip to content

Commit

Permalink
improve names and loops
Browse files Browse the repository at this point in the history
  • Loading branch information
ogauthe committed Jan 15, 2025
1 parent c754d35 commit 7aad297
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
49 changes: 26 additions & 23 deletions src/fusion_trees/fusiontree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ Base.length(::SectorFusionTree{<:Any,N}) where {N} = N
# GradedUnitRanges interface
GradedUnitRanges.sector_type(::Type{<:SectorFusionTree{S}}) where {S} = S

Check warning on line 82 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L82

Added line #L82 was not covered by tests

function build_trees(legs::Vararg{AbstractGradedUnitRange})
tree_arrows = isdual.(legs)
sectors = blocklabels.(legs)
return mapreduce(vcat, CartesianIndices(blocklength.(legs))) do it
block_sectors = getindex.(sectors, Tuple(it)) # why not type stable?
return build_trees(block_sectors, tree_arrows)
end
end

# SymmetrySectors interface
function SymmetrySectors.:×(f1::SectorFusionTree, f2::SectorFusionTree)
@assert arrows(f1) == arrows(f2)
Expand Down Expand Up @@ -154,6 +145,23 @@ end
# TBD change type depending on AbelianStyle?
fusiontree_eltype(::Type{<:AbstractSector}) = Float64

Check warning on line 146 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L146

Added line #L146 was not covered by tests

# constructors
function build_trees(legs::Vararg{AbstractGradedUnitRange})

Check warning on line 149 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L149

Added line #L149 was not covered by tests
# construct all authorized trees for each outer block in legs
tree_arrows = isdual.(legs)
return mapreduce(vcat, Iterators.product(blocklabels.(legs)...)) do it
return build_trees(it, tree_arrows)

Check warning on line 153 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L151-L153

Added lines #L151 - L153 were not covered by tests
end
end

function build_trees(

Check warning on line 157 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L157

Added line #L157 was not covered by tests
sectors_to_fuse::NTuple{N,<:AbstractSector}, arrows_to_fuse::NTuple{N,Bool}
) where {N}
# construct all authorized trees with fixed outer sectors
trees = [SectorFusionTree(first(sectors_to_fuse), first(arrows_to_fuse))]
return recursive_build_trees(trees, Base.tail(sectors_to_fuse), Base.tail(arrows_to_fuse))

Check warning on line 162 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L161-L162

Added lines #L161 - L162 were not covered by tests
end

#
# ===================================== Internals ========================================
#
Expand Down Expand Up @@ -205,7 +213,7 @@ function braid_tuples(t1::Tuple{Vararg{Any,N}}, t2::Tuple{Vararg{Any,N}}) where
return flatten_tuples(nested)

Check warning on line 213 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L210-L213

Added lines #L210 - L213 were not covered by tests
end

function grow_tree(
function append_tree_leave(

Check warning on line 216 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L216

Added line #L216 was not covered by tests
parent_tree::SectorFusionTree,
branch_sector::AbstractSector,
level_arrow::Bool,
Expand All @@ -221,38 +229,33 @@ function grow_tree(
)
end

function grow_tree(
function fuse_next_sector(

Check warning on line 232 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L232

Added line #L232 was not covered by tests
parent_tree::SectorFusionTree, branch_sector::AbstractSector, level_arrow::Bool
)
new_space = fusion_product(root_sector(parent_tree), branch_sector)
return mapreduce(vcat, zip(blocklabels(new_space), blocklengths(new_space))) do (la, n)
return [

Check warning on line 237 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L235-L237

Added lines #L235 - L237 were not covered by tests
grow_tree(parent_tree, branch_sector, level_arrow, la, outer_mult) for
append_tree_leave(parent_tree, branch_sector, level_arrow, la, outer_mult) for
outer_mult in 1:n
]
end
end

function build_trees(old_trees::Vector, sectors_to_fuse::Tuple, arrows_to_fuse::Tuple)
function recursive_build_trees(

Check warning on line 244 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L244

Added line #L244 was not covered by tests
old_trees::Vector, sectors_to_fuse::Tuple, arrows_to_fuse::Tuple
)
next_level_trees = mapreduce(vcat, old_trees) do tree
return grow_tree(tree, first(sectors_to_fuse), first(arrows_to_fuse))
return fuse_next_sector(tree, first(sectors_to_fuse), first(arrows_to_fuse))

Check warning on line 248 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L247-L248

Added lines #L247 - L248 were not covered by tests
end
return build_trees(
return recursive_build_trees(

Check warning on line 250 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L250

Added line #L250 was not covered by tests
next_level_trees, Base.tail(sectors_to_fuse), Base.tail(arrows_to_fuse)
)
end

function build_trees(trees::Vector, ::Tuple{}, ::Tuple{})
function recursive_build_trees(trees::Vector, ::Tuple{}, ::Tuple{})
return trees

Check warning on line 256 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L255-L256

Added lines #L255 - L256 were not covered by tests
end

function build_trees(
sectors_to_fuse::NTuple{N,<:AbstractSector}, arrows_to_fuse::NTuple{N,Bool}
) where {N}
trees = [SectorFusionTree(first(sectors_to_fuse), first(arrows_to_fuse))]
return build_trees(trees, Base.tail(sectors_to_fuse), Base.tail(arrows_to_fuse))
end

# --------------- convert to Array ---------------
to_array(::SectorFusionTree{<:Any,0}) = ones(1)

Check warning on line 260 in src/fusion_trees/fusiontree.jl

View check run for this annotation

Codecov / codecov/patch

src/fusion_trees/fusiontree.jl#L260

Added line #L260 was not covered by tests

Expand Down
20 changes: 9 additions & 11 deletions src/fusiontensor/fusiontensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,20 @@ end
function fusion_trees_external_multiplicities(

Check warning on line 165 in src/fusiontensor/fusiontensor.jl

View check run for this annotation

Codecov / codecov/patch

src/fusiontensor/fusiontensor.jl#L165

Added line #L165 was not covered by tests
outer_legs::Tuple{Vararg{AbstractGradedUnitRange}}
)
return mapreduce(vcat, CartesianIndices(blocklength.(outer_legs))) do it
return fusion_trees_external_multiplicities(outer_legs, Tuple(it))
end
return Iterators.flatten(

Check warning on line 168 in src/fusiontensor/fusiontensor.jl

View check run for this annotation

Codecov / codecov/patch

src/fusiontensor/fusiontensor.jl#L168

Added line #L168 was not covered by tests
block_fusion_trees_external_multiplicities.(Iterators.product(blocks.(outer_legs)...))
)
end

function fusion_trees_external_multiplicities(
outer_legs::NTuple{N,AbstractGradedUnitRange}, indices::NTuple{N,Int}
function block_fusion_trees_external_multiplicities(

Check warning on line 173 in src/fusiontensor/fusiontensor.jl

View check run for this annotation

Codecov / codecov/patch

src/fusiontensor/fusiontensor.jl#L173

Added line #L173 was not covered by tests
it::NTuple{N,AbstractUnitRange}
) where {N}
block_sectors = map((g, i) -> blocklabels(g)[i], outer_legs, indices)
block_mult = mapreduce((g, i) -> blocklengths(g)[i], *, outer_legs, indices; init=1)
return build_trees(block_sectors, isdual.(outer_legs)) .=> block_mult
block_sectors = only.(blocklabels.(it))
block_mult = prod(length.(it))
return build_trees(block_sectors, isdual.(it)) .=> block_mult

Check warning on line 178 in src/fusiontensor/fusiontensor.jl

View check run for this annotation

Codecov / codecov/patch

src/fusiontensor/fusiontensor.jl#L176-L178

Added lines #L176 - L178 were not covered by tests
end

function compute_inner_ranges(
fusion_trees_mult::AbstractVector{<:Pair{<:SectorFusionTree,<:Integer}}
)
function compute_inner_ranges(fusion_trees_mult)
fused_leg = blockmergesort(

Check warning on line 182 in src/fusiontensor/fusiontensor.jl

View check run for this annotation

Codecov / codecov/patch

src/fusiontensor/fusiontensor.jl#L181-L182

Added lines #L181 - L182 were not covered by tests
gradedrange(root_sector.(first.(fusion_trees_mult)) .=> last.(fusion_trees_mult))
)
Expand Down

0 comments on commit 7aad297

Please sign in to comment.