Skip to content

Commit 82c0bcf

Browse files
author
Jutho Haegeman
committed
first fusion tree cache implementation, should be changed to an LRU cache
1 parent 6748c3e commit 82c0bcf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/fusiontrees/fusiontrees.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ function repartition(t1::FusionTree{G,N₁},
276276
end
277277

278278
# permute double fusion tree
279+
const permutedict = Dict{Any,Any}()
279280
"""
280281
function permute(t1::FusionTree{G}, t2::FusionTree{G},
281282
p1::NTuple{N₁,Int}, p2::NTuple{N₂,Int}) where {G,N₁,N₂}
@@ -290,6 +291,26 @@ repartitioning and permuting the tree such that sectors `p1` become outgoing and
290291
"""
291292
function permute(t1::FusionTree{G}, t2::FusionTree{G},
292293
p1::NTuple{N₁,Int}, p2::NTuple{N₂,Int}) where {G<:Sector, N₁,N₂}
294+
d = get!(permutedict, (t1, t2, p1, p2)) do
295+
_permute(t1, t2, p1, p2)
296+
end
297+
if FusionStyle(t1) isa Abelian
298+
u = one(G)
299+
T = typeof(sqrt(dim(u))*Fsymbol(u,u,u,u,u,u))
300+
F₁ = fusiontreetype(G, StaticLength(N₁))
301+
F₂ = fusiontreetype(G, StaticLength(N₂))
302+
return d::SingletonDict{Tuple{F₁,F₂}, T}
303+
else
304+
u = one(G)
305+
T = typeof(sqrt(dim(u))*Fsymbol(u,u,u,u,u,u))
306+
F₁ = fusiontreetype(G, StaticLength(N₁))
307+
F₂ = fusiontreetype(G, StaticLength(N₂))
308+
return d::Dict{Tuple{F₁,F₂}, T}
309+
end
310+
end
311+
312+
function _permute(t1::FusionTree{G}, t2::FusionTree{G},
313+
p1::NTuple{N₁,Int}, p2::NTuple{N₂,Int}) where {G<:Sector, N₁,N₂}
293314
@assert length(t1) + length(t2) == N₁ + N₂
294315
p = linearizepermutation(p1, p2, length(t1), length(t2))
295316
if FusionStyle(t1) isa Abelian
@@ -318,6 +339,7 @@ function permute(t1::FusionTree{G}, t2::FusionTree{G},
318339
throw(MethodError(permute, (t1, t2, p1, p2)))
319340
end
320341
end
342+
321343
# TODO: Make permute a @generated function that computes the result ones and stores it
322344
# TODO: take ideas from memoization
323345

0 commit comments

Comments
 (0)