@@ -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)
@@ -237,17 +283,27 @@ end
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
241- ft5 = 2.0im * ft3
288+ ft5 = ( 1.0 + 2.0im ) * ft3
242289 @test codomain_axes (ft5) === codomain_axes (ft3)
243290 @test domain_axes (ft5) === domain_axes (ft3)
244291 @test space_isequal (codomain_axis (ft5), codomain_axis (ft3))
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
249- ft4 = conj (ft3)
250- @test ft4 === ft3 # same object
297+ @test conj (ft3) === ft3 # same object
298+ @test real (ft3) === ft3
299+ @test norm (imag (ft3)) == 0
300+
301+ @test conj (ft5) isa FusionTensor{ComplexF64,4 }
302+ @test real (ft5) isa FusionTensor{Float64,4 }
303+ @test imag (ft3) isa FusionTensor{Float64,4 }
304+ @test conj (ft5) ≈ (1.0 - 2.0im ) * ft3
305+ @test real (ft5) ≈ ft3
306+ @test imag (ft5) ≈ 2 ft3
251307
252308 ft6 = conj (ft5)
253309 @test ft6 != = ft5 # different object
257313 @test space_isequal (codomain_axis (ft6), codomain_axis (ft5))
258314 @test space_isequal (domain_axis (ft6), domain_axis (ft5))
259315 @test eltype (ft6) == ComplexF64
316+ @test ft6 + ft5 ≈ 2 * real (ft5)
260317
261318 ad = adjoint (ft3)
262319 @test ad isa FusionTensor
274331 @test_throws ArgumentError ft7 * ft3
275332end
276333
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-
316334@testset " missing SectorProduct" begin
317335 g1 = gradedrange ([SectorProduct (U1 (1 )) => 1 ])
318336 g2 = gradedrange ([SectorProduct (U1 (1 ), SU2 (1 // 2 )) => 1 ])
0 commit comments