Skip to content

Commit 099bca6

Browse files
committed
reduce allocations
1 parent 99f6d4b commit 099bca6

File tree

1 file changed

+29
-50
lines changed

1 file changed

+29
-50
lines changed

src/irreps/a4irrep.jl

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ function Rsymbol(a::I, b::I, c::I) where {I <: A4Irrep}
114114
return R
115115
end
116116

117+
# choice of basis: https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.82.2701
118+
# triplet is a real representation -> can make all representation matrices real
117119
function fusiontensor(a::I, b::I, c::I) where {I <: A4Irrep}
118120
T = sectorscalartype(I)
119121
Nabc = Nsymbol(a, b, c)
@@ -124,62 +126,39 @@ function fusiontensor(a::I, b::I, c::I) where {I <: A4Irrep}
124126

125127
if a.n == b.n == 3 # 3 ⊗ 3
126128
if c.n != 3 # singlets
127-
C = A4Irrep_fusiontensor_3x3_to_1(c.n)
128-
else
129-
C = A4Irrep_fusiontensor_3x3_to_3()
129+
invsqrt3 = 1 / sqrt(3.0)
130+
for i in 1:3
131+
j = 4 - mod1(i - c.n - 1, 3)
132+
C[i, j, 1, 1] = invsqrt3
133+
end
134+
else # triplet: eq 38 in above reference
135+
s2 = 1 / sqrt(2.0)
136+
s6 = 1 / sqrt(6.0)
137+
138+
# antisymmetric channel
139+
C[:, :, 1, 1] .= [0 0 0; 0 0 s2; 0 -s2 0]
140+
C[:, :, 2, 1] .= [0 s2 0; -s2 0 0; 0 0 0]
141+
C[:, :, 3, 1] .= [0 0 -s2; 0 0 0; s2 0 0]
142+
143+
# symmetric channel
144+
C[:, :, 1, 2] .= [-2 * s6 0 0; 0 0 s6; 0 s6 0]
145+
C[:, :, 2, 2] .= [0 s6 0; s6 0 0; 0 0 -2 * s6]
146+
C[:, :, 3, 2] .= [0 0 s6; 0 -2 * s6 0; s6 0 0]
130147
end
131148
else
132149
if a.n != 3 && b.n != 3 # 1d x 1d
133150
C[1, 1, 1] = one(T)
134151
elseif a.n == 3 && b.n != 3 # 3 x 1d
135-
C = A4Irrep_fusiontensor_3x1_to_3(b.n)
136-
else # 1d x 3
137-
C = reshape(A4Irrep_fusiontensor_3x1_to_3(a.n), 1, 3, 3, 1)
152+
for i in 1:3
153+
j = mod1(i - b.n, 3)
154+
C[j, 1, i, 1] = one(T)
155+
end
156+
else # 1d x 3: reshape of 3 x 1d
157+
for i in 1:3
158+
j = mod1(i - a.n, 3)
159+
C[1, j, i, 1] = one(T)
160+
end
138161
end
139162
end
140163
return C
141164
end
142-
143-
# choice of basis: https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.82.2701
144-
# triplet is a real representation -> can make all representation matrices real
145-
# μ = 1 is the antisymmetric channel, μ = 2 is the symmetric channel
146-
function A4Irrep_fusiontensor_3x3_to_3()
147-
S = zeros(Float64, 3, 3, 3, 2)
148-
s2 = 1 / sqrt(2.0)
149-
s6 = 1 / sqrt(6.0)
150-
151-
im = (2, 1, 1)
152-
jm = (3, 2, 3)
153-
154-
for i in 1:3
155-
S[im[i], jm[i], i, 1] = (i == 3) ? -s2 : s2
156-
S[jm[i], im[i], i, 1] = (i == 3) ? s2 : -s2
157-
S[im[i], jm[i], i, 2] += s6
158-
S[jm[i], im[i], i, 2] += s6
159-
end
160-
S[1, 1, 1, 2] = -2 * s6
161-
S[3, 3, 2, 2] = -2 * s6
162-
S[2, 2, 3, 2] = -2 * s6
163-
return S
164-
end
165-
166-
function A4Irrep_fusiontensor_3x3_to_1(n)
167-
C = zeros(Float64, 3, 3, 1, 1)
168-
sqrt3 = sqrt(3.0)
169-
i1s = [1, 2, 3]
170-
i2s = circshift(reverse(i1s), n + 1)
171-
is = [i1s i2s]
172-
for i in 1:3
173-
C[is[i, 1], is[i, 2], 1, 1] = 1 / sqrt3
174-
end
175-
return C
176-
end
177-
178-
function A4Irrep_fusiontensor_3x1_to_3(n)
179-
C = zeros(Float64, 3, 1, 3, 1)
180-
is = circshift([1, 2, 3], n)
181-
for i in 1:3
182-
C[is[i], 1, i, 1] = 1.0
183-
end
184-
return C
185-
end

0 commit comments

Comments
 (0)