@@ -28,7 +28,7 @@ using GradedArrays:
2828 space_isequal
2929using TensorAlgebra: tuplemortar
3030using TensorProducts: tensor_product
31- using LinearAlgebra: LinearAlgebra
31+ using LinearAlgebra: LinearAlgebra, norm
3232using Random: Random
3333
3434include (" setup.jl" )
@@ -184,12 +184,53 @@ end
184184 @test sector_type (ft3) === TrivialSector
185185end
186186
187+ @testset " specific constructors" begin
188+ g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
189+ g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
190+ g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
191+ g4 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 1 , U1 (1 ) => 1 ])
192+
193+ fta = FusionTensorAxes ((g1,), (g2, g3))
194+ @test zeros (fta) isa FusionTensor{Float64,3 }
195+ @test zeros (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
196+
197+ rng = Random. default_rng ()
198+ ft1 = randn (rng, ComplexF64, fta)
199+ @test ft1 isa FusionTensor{ComplexF64,3 }
200+ @test all (!= (0 ), data_matrix (ft1)[Block (1 , 5 )])
201+ @test randn (rng, fta) isa FusionTensor{Float64,3 }
202+ @test randn (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
203+ @test randn (fta) isa FusionTensor{Float64,3 }
204+
205+ ft2 = FusionTensor (LinearAlgebra. I, (g1, g2))
206+ @test ft2 isa FusionTensor{Float64,4 }
207+ @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
208+ @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
209+ for i in 1 : 6
210+ m = data_matrix (ft2)[Block (i, i)]
211+ @test m == LinearAlgebra. I (size (m, 1 ))
212+ end
213+
214+ ft2 = FusionTensor (3 * LinearAlgebra. I, (g1, g2))
215+ @test ft2 isa FusionTensor{Float64,4 }
216+ @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
217+ @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
218+ for i in 1 : 6
219+ m = data_matrix (ft2)[Block (i, i)]
220+ @test m == 3 * LinearAlgebra. I (size (m, 1 ))
221+ end
222+
223+ @test FusionTensor {ComplexF64} (LinearAlgebra. I, (g1, g2)) isa FusionTensor{ComplexF64,4 }
224+ end
225+
187226@testset " Base operations" begin
188227 g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
189228 g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
190229 g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
191230 g4 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 1 , U1 (1 ) => 1 ])
192- ft3 = FusionTensor {Float64} (undef, (g1, g2), (g3, g4))
231+ ft3 = randn (FusionTensorAxes ((g1, g2), (g3, g4)))
232+ @test ft3 isa FusionTensor{Float64,4 }
233+ @test norm (ft3) ≉ 0
193234 @test isnothing (check_sanity (ft3))
194235
195236 ft4 = + ft3
@@ -199,20 +240,24 @@ end
199240 @test isnothing (check_sanity (ft4))
200241 @test codomain_axes (ft4) === codomain_axes (ft3)
201242 @test domain_axes (ft4) === domain_axes (ft3)
243+ @test norm (ft4) ≈ norm (ft3)
244+ @test norm (ft4 + ft3) ≈ 0.0
202245
203246 ft4 = ft3 + ft3
204247 @test codomain_axes (ft4) === codomain_axes (ft3)
205248 @test domain_axes (ft4) === domain_axes (ft3)
206249 @test space_isequal (codomain_axis (ft4), codomain_axis (ft3))
207250 @test space_isequal (domain_axis (ft4), domain_axis (ft3))
208251 @test isnothing (check_sanity (ft4))
252+ @test norm (ft4) ≈ 2 norm (ft3)
209253
210254 ft4 = ft3 - ft3
211255 @test codomain_axes (ft4) === codomain_axes (ft3)
212256 @test domain_axes (ft4) === domain_axes (ft3)
213257 @test space_isequal (codomain_axis (ft4), codomain_axis (ft3))
214258 @test space_isequal (domain_axis (ft4), domain_axis (ft3))
215259 @test isnothing (check_sanity (ft4))
260+ @test norm (ft4) ≈ 0.0
216261
217262 ft4 = 2 * ft3
218263 @test codomain_axes (ft4) === codomain_axes (ft3)
221266 @test space_isequal (domain_axis (ft4), domain_axis (ft3))
222267 @test isnothing (check_sanity (ft4))
223268 @test eltype (ft4) == Float64
269+ @test norm (ft4) ≈ 2 norm (ft3)
224270
225271 ft4 = 2.0 * ft3
226272 @test codomain_axes (ft4) === codomain_axes (ft3)
237283 @test space_isequal (domain_axis (ft4), domain_axis (ft3))
238284 @test isnothing (check_sanity (ft4))
239285 @test eltype (ft4) == Float64
286+ @test norm (ft4) ≈ norm (ft3) / 2.0
240287
241288 ft5 = (1.0 + 2.0im ) * ft3
242289 @test codomain_axes (ft5) === codomain_axes (ft3)
@@ -245,17 +292,18 @@ end
245292 @test space_isequal (domain_axis (ft5), domain_axis (ft3))
246293 @test isnothing (check_sanity (ft4))
247294 @test eltype (ft5) == ComplexF64
295+ @test norm (ft5) ≈ √ 5 * norm (ft3)
248296
249297 @test conj (ft3) === ft3 # same object
250298 @test real (ft3) === ft3
251- @test all ( == ( 0.0 ), data_matrix ( imag (ft3)))
299+ @test norm ( imag (ft3)) == 0
252300
253301 @test conj (ft5) isa FusionTensor{ComplexF64,4 }
254302 @test real (ft5) isa FusionTensor{Float64,4 }
255303 @test imag (ft3) isa FusionTensor{Float64,4 }
256304 @test conj (ft5) ≈ (1.0 - 2.0im ) * ft3
257305 @test real (ft5) ≈ ft3
258- @test imag (ft3 ) ≈ 2 ft3
306+ @test imag (ft5 ) ≈ 2 ft3
259307
260308 ft6 = conj (ft5)
261309 @test ft6 != = ft5 # different object
265313 @test space_isequal (codomain_axis (ft6), codomain_axis (ft5))
266314 @test space_isequal (domain_axis (ft6), domain_axis (ft5))
267315 @test eltype (ft6) == ComplexF64
316+ @test ft6 + ft5 ≈ 2 * real (ft5)
268317
269318 ad = adjoint (ft3)
270319 @test ad isa FusionTensor
282331 @test_throws ArgumentError ft7 * ft3
283332end
284333
285- @testset " specific constructors" begin
286- g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
287- g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
288- g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
289- g4 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 1 , U1 (1 ) => 1 ])
290-
291- fta = FusionTensorAxes ((g1,), (g2, g3))
292- @test zeros (fta) isa FusionTensor{Float64,3 }
293- @test zeros (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
294-
295- rng = Random. default_rng ()
296- ft1 = randn (rng, ComplexF64, fta)
297- @test ft1 isa FusionTensor{ComplexF64,3 }
298- @test all (!= (0 ), data_matrix (ft1)[Block (1 , 5 )])
299- @test randn (rng, fta) isa FusionTensor{Float64,3 }
300- @test randn (ComplexF64, fta) isa FusionTensor{ComplexF64,3 }
301- @test randn (fta) isa FusionTensor{Float64,3 }
302-
303- ft2 = FusionTensor (LinearAlgebra. I, (g1, g2))
304- @test ft2 isa FusionTensor{Float64,4 }
305- @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
306- @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
307- for i in 1 : 6
308- m = data_matrix (ft2)[Block (i, i)]
309- @test m == LinearAlgebra. I (size (m, 1 ))
310- end
311-
312- ft2 = FusionTensor (3 * LinearAlgebra. I, (g1, g2))
313- @test ft2 isa FusionTensor{Float64,4 }
314- @test axes (ft2) == FusionTensorAxes ((g1, g2), dual .((g1, g2)))
315- @test collect (eachblockstoredindex (data_matrix (ft2))) == map (i -> Block (i, i), 1 : 6 )
316- for i in 1 : 6
317- m = data_matrix (ft2)[Block (i, i)]
318- @test m == 3 * LinearAlgebra. I (size (m, 1 ))
319- end
320-
321- @test FusionTensor {ComplexF64} (LinearAlgebra. I, (g1, g2)) isa FusionTensor{ComplexF64,4 }
322- end
323-
324334@testset " missing SectorProduct" begin
325335 g1 = gradedrange ([SectorProduct (U1 (1 )) => 1 ])
326336 g2 = gradedrange ([SectorProduct (U1 (1 ), SU2 (1 // 2 )) => 1 ])
0 commit comments