22
22
@test vec (reshape (permutedims (a, (2 , 1 , 3 )), 3 , :) * reshape (permutedims (b, (1 , 3 , 2 )), :, 5 )) ≈ vec (ab)
23
23
end
24
24
25
- @testset " MPO-MPO naive contraction" begin
25
+ @testset " MPO-MPO contraction" for f in [ nothing , x -> 2 * x], algorithm in [ " TCI " , " naive " ]
26
26
N = 4
27
27
bonddims_a = [1 , 2 , 3 , 2 , 1 ]
28
28
bonddims_b = [1 , 2 , 3 , 2 , 1 ]
39
39
for n = 1 : N
40
40
])
41
41
42
- ab = contract (a, b; algorithm= " naive" )
43
-
44
- @test _tomat (ab) ≈ _tomat (a) * _tomat (b)
45
- end
46
-
47
- @testset " MPO-MPO contraction" for f in [x -> x, x -> 2 * x]
48
- N = 4
49
- bonddims_a = [1 , 2 , 3 , 2 , 1 ]
50
- bonddims_b = [1 , 2 , 3 , 2 , 1 ]
51
- localdims1 = [2 , 2 , 2 , 2 ]
52
- localdims2 = [3 , 3 , 3 , 3 ]
53
- localdims3 = [2 , 2 , 2 , 2 ]
54
-
55
- a = TensorTrain {ComplexF64,4} ([
56
- rand (ComplexF64, bonddims_a[n], localdims1[n], localdims2[n], bonddims_a[n+ 1 ])
57
- for n = 1 : N
58
- ])
59
- b = TensorTrain {ComplexF64,4} ([
60
- rand (ComplexF64, bonddims_b[n], localdims2[n], localdims3[n], bonddims_b[n+ 1 ])
61
- for n = 1 : N
62
- ])
63
-
64
- ab = contract (a, b; f = f, algorithm= " TCI" )
65
- @test sitedims (ab) == [[localdims1[i], localdims3[i]] for i = 1 : N]
66
- @test _tomat (ab) ≈ f .(_tomat (a) * _tomat (b))
42
+ if f === nothing || algorithm != " naive"
43
+ ab = contract (a, b; f= f, algorithm= algorithm)
44
+ @test sitedims (ab) == [[localdims1[i], localdims3[i]] for i = 1 : N]
45
+ if f === nothing
46
+ @test _tomat (ab) ≈ _tomat (a) * _tomat (b)
47
+ else
48
+ @test _tomat (ab) ≈ f .(_tomat (a) * _tomat (b))
49
+ end
50
+ end
67
51
end
0 commit comments