@@ -28,7 +28,7 @@ using GradedArrays:
28
28
space_isequal
29
29
using TensorAlgebra: tuplemortar
30
30
using TensorProducts: tensor_product
31
- using LinearAlgebra: LinearAlgebra
31
+ using LinearAlgebra: LinearAlgebra, norm
32
32
using Random: Random
33
33
34
34
include (" setup.jl" )
@@ -184,12 +184,53 @@ end
184
184
@test sector_type (ft3) === TrivialSector
185
185
end
186
186
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
+
187
226
@testset " Base operations" begin
188
227
g1 = gradedrange ([U1 (0 ) => 1 , U1 (1 ) => 2 , U1 (2 ) => 3 ])
189
228
g2 = gradedrange ([U1 (0 ) => 2 , U1 (1 ) => 2 , U1 (3 ) => 1 ])
190
229
g3 = gradedrange ([U1 (- 1 ) => 1 , U1 (0 ) => 2 , U1 (1 ) => 1 ])
191
230
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
193
234
@test isnothing (check_sanity (ft3))
194
235
195
236
ft4 = + ft3
@@ -199,20 +240,24 @@ end
199
240
@test isnothing (check_sanity (ft4))
200
241
@test codomain_axes (ft4) === codomain_axes (ft3)
201
242
@test domain_axes (ft4) === domain_axes (ft3)
243
+ @test norm (ft4) ≈ norm (ft3)
244
+ @test norm (ft4 + ft3) ≈ 0.0
202
245
203
246
ft4 = ft3 + ft3
204
247
@test codomain_axes (ft4) === codomain_axes (ft3)
205
248
@test domain_axes (ft4) === domain_axes (ft3)
206
249
@test space_isequal (codomain_axis (ft4), codomain_axis (ft3))
207
250
@test space_isequal (domain_axis (ft4), domain_axis (ft3))
208
251
@test isnothing (check_sanity (ft4))
252
+ @test norm (ft4) ≈ 2 norm (ft3)
209
253
210
254
ft4 = ft3 - ft3
211
255
@test codomain_axes (ft4) === codomain_axes (ft3)
212
256
@test domain_axes (ft4) === domain_axes (ft3)
213
257
@test space_isequal (codomain_axis (ft4), codomain_axis (ft3))
214
258
@test space_isequal (domain_axis (ft4), domain_axis (ft3))
215
259
@test isnothing (check_sanity (ft4))
260
+ @test norm (ft4) ≈ 0.0
216
261
217
262
ft4 = 2 * ft3
218
263
@test codomain_axes (ft4) === codomain_axes (ft3)
221
266
@test space_isequal (domain_axis (ft4), domain_axis (ft3))
222
267
@test isnothing (check_sanity (ft4))
223
268
@test eltype (ft4) == Float64
269
+ @test norm (ft4) ≈ 2 norm (ft3)
224
270
225
271
ft4 = 2.0 * ft3
226
272
@test codomain_axes (ft4) === codomain_axes (ft3)
@@ -237,17 +283,27 @@ end
237
283
@test space_isequal (domain_axis (ft4), domain_axis (ft3))
238
284
@test isnothing (check_sanity (ft4))
239
285
@test eltype (ft4) == Float64
286
+ @test norm (ft4) ≈ norm (ft3) / 2.0
240
287
241
- ft5 = 2.0im * ft3
288
+ ft5 = ( 1.0 + 2.0im ) * ft3
242
289
@test codomain_axes (ft5) === codomain_axes (ft3)
243
290
@test domain_axes (ft5) === domain_axes (ft3)
244
291
@test space_isequal (codomain_axis (ft5), codomain_axis (ft3))
245
292
@test space_isequal (domain_axis (ft5), domain_axis (ft3))
246
293
@test isnothing (check_sanity (ft4))
247
294
@test eltype (ft5) == ComplexF64
295
+ @test norm (ft5) ≈ √ 5 * norm (ft3)
248
296
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
251
307
252
308
ft6 = conj (ft5)
253
309
@test ft6 != = ft5 # different object
257
313
@test space_isequal (codomain_axis (ft6), codomain_axis (ft5))
258
314
@test space_isequal (domain_axis (ft6), domain_axis (ft5))
259
315
@test eltype (ft6) == ComplexF64
316
+ @test ft6 + ft5 ≈ 2 * real (ft5)
260
317
261
318
ad = adjoint (ft3)
262
319
@test ad isa FusionTensor
274
331
@test_throws ArgumentError ft7 * ft3
275
332
end
276
333
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
-
316
334
@testset " missing SectorProduct" begin
317
335
g1 = gradedrange ([SectorProduct (U1 (1 )) => 1 ])
318
336
g2 = gradedrange ([SectorProduct (U1 (1 ), SU2 (1 // 2 )) => 1 ])
0 commit comments