11using Test: @test , @test_throws , @testset
22
33using BlockArrays: Block
4- using BlockSparseArrays: BlockSparseArray
4+ using BlockSparseArrays: BlockSparseArray, eachblockstoredindex
55using FusionTensors:
66 FusionTensor,
77 FusionTensorAxes,
@@ -28,15 +28,23 @@ using GradedArrays:
2828 space_isequal
2929using TensorAlgebra: tuplemortar
3030using TensorProducts: tensor_product
31+ using LinearAlgebra: LinearAlgebra
32+ using Random: Random
3133
3234include (" setup.jl" )
3335
3436@testset " Fusion matrix" begin
3537 g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
3638 g2 = dual (gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ]))
3739
40+ fta = FusionTensorAxes ((g1,), (g2,))
41+ ft0 = FusionTensor {Float64} (undef, fta)
42+ @test ft0 isa FusionTensor
43+ @test space_isequal (codomain_axis (ft0), g1)
44+ @test space_isequal (domain_axis (ft0), g2)
45+
3846 # check dual convention when initializing data_matrix
39- ft0 = FusionTensor ( Float64, (g1,), (g2,))
47+ ft0 = FusionTensor { Float64} (undef , (g1,), (g2,))
4048 @test ft0 isa FusionTensor
4149 @test space_isequal (codomain_axis (ft0), g1)
4250 @test space_isequal (domain_axis (ft0), g2)
146154 g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
147155
148156 # one row axis
149- ft1 = FusionTensor ( Float64, (g1,), ())
157+ ft1 = FusionTensor { Float64} (undef , (g1,), ())
150158 @test ndims_codomain (ft1) == 1
151159 @test ndims_domain (ft1) == 0
152160 @test ndims (ft1) == 1
156164 @test sector_type (ft1) === sector_type (g1)
157165
158166 # one column axis
159- ft2 = FusionTensor ( Float64, (), (g1,))
167+ ft2 = FusionTensor { Float64} (undef , (), (g1,))
160168 @test ndims_codomain (ft2) == 0
161169 @test ndims_domain (ft2) == 1
162170 @test ndims (ft2) == 1
166174 @test sector_type (ft2) === sector_type (g1)
167175
168176 # zero axis
169- ft3 = FusionTensor ( Float64, (), ())
177+ ft3 = FusionTensor { Float64} (undef , (), ())
170178 @test ndims_codomain (ft3) == 0
171179 @test ndims_domain (ft3) == 0
172180 @test ndims (ft3) == 0
181189 g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
182190 g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
183191 g4 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 1 , U1 (1 ) => 1 ])
184- ft3 = FusionTensor ( Float64, (g1, g2), (g3, g4))
192+ ft3 = FusionTensor { Float64} (undef , (g1, g2), (g3, g4))
185193 @test isnothing (check_sanity (ft3))
186194
187195 ft4 = + ft3
@@ -260,19 +268,58 @@ end
260268 @test space_isequal (dual (g4), codomain_axes (ad)[2 ])
261269 @test isnothing (check_sanity (ad))
262270
263- ft7 = FusionTensor ( Float64, (g1,), (g2, g3, g4))
271+ ft7 = FusionTensor { Float64} (undef , (g1,), (g2, g3, g4))
264272 @test_throws DimensionMismatch ft7 + ft3
265273 @test_throws DimensionMismatch ft7 - ft3
266274 @test_throws DimensionMismatch ft7 * ft3
267275end
268276
277+ @testset " specific constructors" begin
278+ g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
279+ g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
280+ g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
281+ g4 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 1 , U1 (1 ) => 1 ])
282+
283+ fta = FusionTensorAxes ((g1,), (g2, g3))
284+ @test zeros (fta) isa FusionTensor{Float64,3 }
285+ @test zeros (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
286+
287+ rng = Random. default_rng ()
288+ ft1 = randn (rng, ComplexF64, fta)
289+ @test ft1 isa FusionTensor{ComplexF64,3 }
290+ @test all (!= (0 ), data_matrix (ft1)[Block (1 , 5 )])
291+ @test randn (rng, fta) isa FusionTensor{Float64,3 }
292+ @test randn (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
293+ @test randn (fta) isa FusionTensor{Float64,3 }
294+
295+ ft2 = FusionTensor (LinearAlgebra. I, (g1, g2))
296+ @test ft2 isa FusionTensor{Float64,4 }
297+ @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
298+ @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
299+ for i in 1 : 6
300+ m = data_matrix (ft2)[Block (i, i)]
301+ @test m == LinearAlgebra. I (size (m, 1 ))
302+ end
303+
304+ ft2 = FusionTensor (3 * LinearAlgebra. I, (g1, g2))
305+ @test ft2 isa FusionTensor{Float64,4 }
306+ @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
307+ @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
308+ for i in 1 : 6
309+ m = data_matrix (ft2)[Block (i, i)]
310+ @test m == 3 * LinearAlgebra. I (size (m, 1 ))
311+ end
312+
313+ @test FusionTensor {ComplexF64} (LinearAlgebra. I, (g1, g2)) isa FusionTensor{ComplexF64,4 }
314+ end
315+
269316@testset " missing SectorProduct" begin
270317 g1 = gradedrange ([SectorProduct (U1 (1 )) => 1 ])
271318 g2 = gradedrange ([SectorProduct (U1 (1 ), SU2 (1 // 2 )) => 1 ])
272319 g3 = gradedrange ([SectorProduct (U1 (1 ), SU2 (1 // 2 ), Z {2} (1 )) => 1 ])
273320 S = sector_type (g3)
274321
275- ft = FusionTensor ( Float64, (g1,), (dual (g2), dual (g3)))
322+ ft = FusionTensor { Float64} (undef , (g1,), (dual (g2), dual (g3)))
276323 @test sector_type (ft) === S
277324 gr = gradedrange ([SectorProduct (U1 (1 ), SU2 (0 ), Z {2} (0 )) => 1 ])
278325 @test space_isequal (codomain_axis (ft), gr)
287334 gABC = tensor_product (gA, gB, gC)
288335 S = sector_type (gABC)
289336
290- ft = FusionTensor ( Float64, (gA, gB), (dual (gA), dual (gB), gC))
337+ ft = FusionTensor { Float64} (undef , (gA, gB), (dual (gA), dual (gB), gC))
291338 @test sector_type (ft) === S
292339 @test space_isequal (codomain_axis (ft), gABC)
293340 @test space_isequal (domain_axis (ft), dual (gABC))
0 commit comments