Skip to content

Commit 8e373fa

Browse files
leburgelclaude
andcommitted
Keep the blocks in the order in which their uncoupled sectors first occur
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5de53f0 commit 8e373fa

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

‎src/spaces/homspace.jl‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,15 @@ function fusionblocks(W::HomSpace)
211211
I = sectortype(W)
212212
N₁, N₂ = numout(W), numin(W)
213213
F = fusiontreetype(I, N₁, N₂)
214-
# group the (cached) fusion trees of `W` by their uncoupled sectors
215-
groups = Dict{Tuple{NTuple{N₁, I}, NTuple{N₂, I}}, Vector{F}}()
214+
# group the (cached) fusion trees of `W` by their uncoupled sectors, in the order in which
215+
# these first occur
216+
groups = Vector{F}[]
217+
group_of = Dict{Tuple{NTuple{N₁, I}, NTuple{N₂, I}}, Vector{F}}()
216218
for (f₁, f₂) in fusiontrees(W)
217-
push!(get!(Vector{F}, groups, (f₁.uncoupled, f₂.uncoupled)), (f₁, f₂))
219+
group = get!(() -> push!(groups, F[])[end], group_of, (f₁.uncoupled, f₂.uncoupled))
220+
push!(group, (f₁, f₂))
218221
end
219-
# in the order of `sectors(domain(W))` (outer) and `sectors(codomain(W))` (inner), each of
220-
# which runs fastest over its first space (the sectors of a dual space are sorted by their dual)
221-
key(V, s) = isdual(V) ? dual(s) : s
222-
rank((u₁, u₂)) = (reverse(map(key, domain(W).spaces, u₂)), reverse(map(key, codomain(W).spaces, u₁)))
223-
us = collect(keys(groups))
224-
return map(i -> FusionTreeBlock(groups[us[i]]), sortperm(map(rank, us))) # each rank computed once
222+
return map(FusionTreeBlock, groups)
225223
end
226224

227225
function diagonalblockstructure(W::HomSpace)

‎test/symmetries/doubletree.jl‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ using TensorKitSectors
245245
@test fusiontrees(block) == filter(f -> (f[1].uncoupled, f[2].uncoupled) == block.uncoupled, trees)
246246
end
247247
@test sum(length, blocks) == length(trees)
248-
# the blocks are ordered as `sectors(domain(W))` (outer) and `sectors(codomain(W))` (inner)
249-
uncoupled = [(u₁, u₂) for u₂ in sectors(domain(W)) for u₁ in sectors(codomain(W))]
250-
@test map(block -> block.uncoupled, blocks) == filter(u -> any(f -> (f[1].uncoupled, f[2].uncoupled) == u, trees), uncoupled)
248+
@test allunique(map(block -> block.uncoupled, blocks))
251249
end
252250

253251
@testset "Double fusion tree: planar trace" begin

0 commit comments

Comments
 (0)