1- const ImplementedBimoduleSectors = [ :A4 ]
1+ const ImplementedBimoduleSectors = ( :A4 ,)
22
33struct BimoduleSector{Name} <: Sector
44 i:: Int
@@ -7,19 +7,18 @@ struct BimoduleSector{Name} <: Sector
77 function BimoduleSector {Name} (i:: Int , j:: Int , label:: Int ) where {Name}
88 Name ∈ ImplementedBimoduleSectors ||
99 throw (ArgumentError (" BimoduleSector $Name not implemented" ))
10- i <= size (BimoduleSector{Name}) && j <= size (BimoduleSector{Name}) ||
11- throw (DomainError (" object outside the matrix $Name " ))
12- return label <= _numlabels (BimoduleSector{Name}, i, j) ? new {Name} (i, j, label) :
13- throw (DomainError (" label outside category $Name ($i , $j )" ))
10+ r = rank (BimoduleSector{Name})
11+ (1 <= i <= r && 1 <= j <= r) ||
12+ throw (DomainError ((i, j), " subcategory outside the $r ×$r matrix $Name " ))
13+ return 1 <= label <= _numlabels (BimoduleSector{Name}, i, j) ? new {Name} (i, j, label) :
14+ throw (DomainError (label, " label outside category $Name ($i , $j )" ))
1415 end
1516end
1617
1718BimoduleSector {Name} (data:: NTuple{3, Int} ) where {Name} = BimoduleSector {Name} (data... )
1819BimoduleSectorName (:: Type{BimoduleSector{Name}} ) where {Name} = Name
1920const A4Object = BimoduleSector{:A4 }
2021
21- Base. convert (:: Type{<:BimoduleSector{Name}} , labels:: NTuple{3, Int} ) where {Name} = BimoduleSector {Name} (labels... )
22-
2322function Base. show (io:: IO , a:: BimoduleSector{Name} ) where {Name}
2423 if get (io, :typeinfo , nothing ) === typeof (a)
2524 print (io, (a. i, a. j, a. label))
@@ -39,27 +38,24 @@ function Base.convert(::Type{BimoduleSector{Name}}, d::NTuple{3, Int}) where {Na
3938 return BimoduleSector {Name} (d... )
4039end
4140
42- Base . size ( :: Type{A4Object } ) = 7
41+ rank (I :: Type{<:BimoduleSector } ) = size ( _get_dual_cache (I)[ 3 ], 1 )
4342
4443Base. IteratorSize (:: Type{<:SectorValues{<:BimoduleSector}} ) = Base. SizeUnknown ()
4544
46- function Base. iterate (iter:: SectorValues{<:BimoduleSector} , (I , label) = (1 , 1 ))
45+ function Base. iterate (iter:: SectorValues{<:BimoduleSector} , (n , label) = (1 , 1 ))
4746 A = eltype (iter)
48- s = size (A)
49- I > s * s && return nothing
50- i, j = CartesianIndices ((s , s))[I] . I
47+ s = rank (A)
48+ n > s * s && return nothing
49+ i, j = fldmod1 (n , s)
5150 maxlabel = _numlabels (A, i, j)
5251 return if label > maxlabel
53- iterate (iter, (I + 1 , 1 ))
52+ iterate (iter, (n + 1 , 1 ))
5453 else
55- A (i, j, label), (I , label + 1 )
54+ A (i, j, label), (n , label + 1 )
5655 end
5756end
5857
59- function Base. length (:: SectorValues{I} ) where {I <: BimoduleSector }
60- s = size (I)
61- return sum (_numlabels (I, i, j) for i in 1 : s, j in 1 : s)
62- end
58+ Base. length (:: SectorValues{I} ) where {I <: BimoduleSector } = sum (_get_dual_cache (I)[3 ])
6359
6460TensorKitSectors. FusionStyle (:: Type{A4Object} ) = GenericFusion ()
6561TensorKitSectors. BraidingStyle (:: Type{<:BimoduleSector} ) = NoBraiding ()
@@ -76,8 +72,9 @@ function TensorKitSectors.:⊗(a::I, b::I) where {I <: BimoduleSector}
7672end
7773
7874function _numlabels (:: Type{T} , i, j) where {T <: BimoduleSector }
79- return length ( _get_dual_cache (T)[2 ][i, j])
75+ return _get_dual_cache (T)[3 ][i, j]
8076end
77+ _unitlabel (:: Type{I} , i:: Int ) where {I <: BimoduleSector } = _get_dual_cache (I)[1 ][i]
8178
8279# User-friendly functions
8380# -------------------
@@ -92,10 +89,12 @@ function extract_Nsymbol(::Type{I}) where {I <: BimoduleSector}
9289 filename = joinpath (artifact_path, name, " Nsymbol.txt" )
9390 isfile (filename) || throw (LoadError (filename, 0 , " Nsymbol file not found for $name " ))
9491 Narray = readdlm (filename) # matrix with 7 columns
92+ size (Narray, 2 ) == 7 ||
93+ throw (ArgumentError (" Nsymbol file for $name has wrong number of columns: $(size (Narray, 2 )) != 7" ))
9594
9695 data_dict = Dict {NTuple{3, Int}, Dict{NTuple{3, Int}, Int}} ()
9796 for row in eachrow (Narray)
98- i, j, k, a, b, c, N = Int .(@view (row[1 : size (I) ]))
97+ i, j, k, a, b, c, N = Int .(@view (row[1 : 7 ]))
9998 colordict = get! (data_dict, (i, j, k), Dict {NTuple{3, Int}, Int} ())
10099 push! (colordict, (a, b, c) => N)
101100 end
@@ -120,7 +119,7 @@ function TensorKitSectors.Nsymbol(a::I, b::I, c::I) where {I <: BimoduleSector}
120119 return get (_get_Ncache (I)[i, j, k], (a. label, b. label, c. label), 0 )
121120end
122121
123- const Dualcache = IdDict{Type{<: BimoduleSector }, Tuple{Vector{Int64}, Matrix{Vector{Int64}}}}()
122+ const Dualcache = IdDict{Type{<: BimoduleSector }, Tuple{Vector{Int64}, Matrix{Vector{Int64}}, Matrix{Int64} }}()
124123
125124function _get_dual_cache (:: Type{T} ) where {T <: BimoduleSector }
126125 global Dualcache
@@ -131,80 +130,72 @@ end
131130
132131function extract_dual (:: Type{I} ) where {I <: BimoduleSector }
133132 N = _get_Ncache (I)
134- ncats = size (I )
135- Is = zeros (Int, ncats)
133+ ncats = maximum (maximum, keys (N) )
134+ nobj = [ maximum (first, keys (N[i, j, j])) for i in 1 : ncats, j in 1 : ncats]
136135
137- map (1 : ncats) do i
136+ Is = map (1 : ncats) do i
138137 Niii = N[i, i, i]
139- nobji = maximum (first, keys (N[i, i, i]))
140138 # want to return a leftunit and rightunit for each entry in multifusion cat
141139 # leftunit/rightunit needs to at least be the unit object within a fusion cat
142- Is[i] = findfirst (1 : nobji ) do a
140+ u = findfirst (1 : nobj[i, i] ) do a
143141 get (Niii, (a, a, a), 0 ) == 1 || return false # I x I -> I
144- for othera in 1 : nobji
145- get (Niii, (othera, a, othera), 0 ) == 1 || return false # a x I -> a
146- get (Niii, (a, othera, othera), 0 ) == 1 || return false # I x a -> a
147- end
148142
149- # check leftunit
150- map (1 : ncats) do j
151- nobjj = maximum (first, keys (N[j, j, j]))
152- for b in 1 : nobjj
153- get (N[i, j, j], (a, b, b), 0 ) == 1 || return false # I = leftunit(b)
154- end
143+ # I = leftunit(b) for every b in C_ij, I x b -> b in C_ii x C_ij -> C_ij
144+ for j in 1 : ncats, b in 1 : nobj[i, j]
145+ get (N[i, i, j], (a, b, b), 0 ) == 1 || return false
155146 end
156147
157- # check rightunit
158- map (1 : ncats) do k
159- nobjk = maximum (first, keys (N[k, k, k]))
160- for c in 1 : nobjk
161- get (N[k, i, k], (c, a, c), 0 ) == 1 || return false # I = rightunit(c)
162- end
148+ # I = rightunit(c) for every c in C_ki, c x I -> c in C_ki x C_ii -> C_ki
149+ for k in 1 : ncats, c in 1 : nobj[k, i]
150+ get (N[k, i, i], (c, a, c), 0 ) == 1 || return false
163151 end
164152 return true
165153 end
154+ isnothing (u) && throw (ArgumentError (" no unit object found in subcategory ($i , $i ) of $I " ))
155+ return u
166156 end
167157
168158 allduals = Matrix {Vector{Int}} (undef, ncats, ncats) # ncats square matrix of vectors
169- for i in 1 : ncats
170- nobji = maximum (first, keys (N[i, i, i]))
171- for j in 1 : ncats
172- allduals[i, j] = Int[]
173-
174- nobjj = maximum (first, keys (N[j, j, j]))
175- # the nested vectors contain the duals of the objects in 𝒞_ij, which are in C_ji
176- Niji = N[i, j, i] # 𝒞_ij x 𝒞_ji -> C_ii
177- Njij = N[j, i, j] # 𝒞_ji x 𝒞_ij -> C_jj
178- for i_ob in 1 : nobji, j_ob in 1 : nobjj
179- get (Niji, (i_ob, j_ob, Is[i]), 0 ) == 1 || continue # leftunit(c_ij) ∈ c_ij x c_ji
180- get (Njij, (j_ob, i_ob, Is[j]), 0 ) == 1 || continue # rightunit(c_ij) ∈ c_ji x c_ij
181- push! (allduals[i, j], j_ob)
159+ for i in 1 : ncats, j in 1 : ncats
160+ Niji = N[i, j, i] # 𝒞_ij x 𝒞_ji -> 𝒞_ii
161+ Njij = N[j, i, j] # 𝒞_ji x 𝒞_ij -> 𝒞_jj
162+ allduals[i, j] = map (1 : nobj[i, j]) do m
163+ mbar = findfirst (1 : nobj[j, i]) do n
164+ get (Niji, (m, n, Is[i]), 0 ) == 1 && # leftunit(m) in m x mbar
165+ get (Njij, (n, m, Is[j]), 0 ) == 1 # rightunit(m) in mbar x m
182166 end
167+ isnothing (mbar) && throw (ArgumentError (" no dual found for $I ($i , $j , $m )" ))
168+ return mbar
183169 end
184170 end
185- return Is, allduals
171+ return Is, allduals, nobj
186172end
187173
188174function TensorKitSectors. unit (a:: BimoduleSector )
189175 a. i == a. j || throw (DomainError (" unit of module category ($(a. i) , $(a. j) ) of $(typeof (a)) is ill-defined" ))
190- return typeof (a)(a. i, a. i, _get_dual_cache (typeof (a))[ 1 ][ a. i] )
176+ return typeof (a)(a. i, a. i, _unitlabel (typeof (a), a. i) )
191177end
192178
179+ TensorKitSectors. UnitStyle (:: Type{<:BimoduleSector} ) = GenericUnit ()
180+
193181function TensorKitSectors. allunits (:: Type{I} ) where {I <: BimoduleSector }
194- s = size (I)
195- return I[I (i, i, _get_dual_cache (I)[1 ][i]) for i in 1 : s]
182+ return I[I (i, i, u) for (i, u) in enumerate (_get_dual_cache (I)[1 ])]
183+ end
184+
185+ function TensorKitSectors. isunit (a:: BimoduleSector )
186+ return a. i == a. j && a. label == _unitlabel (typeof (a), a. i)
196187end
197188
198189function TensorKitSectors. unit (:: Type{<:BimoduleSector} )
199190 throw (ArgumentError (" unit of Type BimoduleSector doesn't exist" ))
200191end
201192
202193function TensorKitSectors. leftunit (a:: BimoduleSector )
203- return typeof (a)(a. i, a. i, _get_dual_cache (typeof (a))[ 1 ][ a. i] )
194+ return typeof (a)(a. i, a. i, _unitlabel (typeof (a), a. i) )
204195end
205196
206197function TensorKitSectors. rightunit (a:: BimoduleSector )
207- return typeof (a)(a. j, a. j, _get_dual_cache (typeof (a))[ 1 ][ a. j] )
198+ return typeof (a)(a. j, a. j, _unitlabel (typeof (a), a. j) )
208199end
209200
210201function TensorKitSectors. dual (a:: BimoduleSector )
@@ -218,6 +209,7 @@ function extract_Fsymbol(::Type{I}) where {I <: BimoduleSector}
218209 @assert isfile (filename) " cannot find $filename "
219210
220211 Farray = readdlm (filename)
212+ size (Farray, 2 ) == 16 || throw (ArgumentError (" Fsymbol file for $name has wrong number of columns: $(size (Farray, 2 )) != 16" ))
221213 for ((i, j, k, l), colordict) in convert_Fs (Farray)
222214 result[(i, j, k, l)] = Dict {NTuple{6, Int}, Array{ComplexF64, 4}} ()
223215 for ((a, b, c, d, e, f), Fvals) in colordict
@@ -272,11 +264,14 @@ function TensorKitSectors.Fsymbol(a::I, b::I, c::I, d::I, e::I, f::I) where {I <
272264 Nbcf = Nsymbol (b, c, f)
273265 Nafd = Nsymbol (a, f, d)
274266
275- zero_array = zeros ( sectorscalartype (I), Nabe, Necd, Nbcf, Nafd )
267+ T = sectorscalartype (I)
276268 Nabe > 0 && Necd > 0 && Nbcf > 0 && Nafd > 0 ||
277- return zero_array
269+ return zeros (T, Nabe, Necd, Nbcf, Nafd)
278270
279271 i, j, k, l = a. i, a. j, b. j, c. j
280272 colordict = _get_Fcache (I)[i, j, k, l]
281- return get! (colordict, (a. label, b. label, c. label, d. label, e. label, f. label), zero_array)
273+ return get! (
274+ () -> zeros (T, Nabe, Necd, Nbcf, Nafd),
275+ colordict, (a. label, b. label, c. label, d. label, e. label, f. label)
276+ )
282277end
0 commit comments