@@ -3,11 +3,12 @@ using TensorOperationsTBLIS
3
3
using Test
4
4
using LinearAlgebra: norm
5
5
6
+ const tblisbackend = tblisBackend ()
6
7
@testset " elementary operations" verbose = true begin
7
8
@testset " tensorcopy" begin
8
9
A = randn (Float32, (3 , 5 , 4 , 6 ))
9
10
@tensor C1[4 , 1 , 3 , 2 ] := A[1 , 2 , 3 , 4 ]
10
- @tensor backend = tblis C2[4 , 1 , 3 , 2 ] := A[1 , 2 , 3 , 4 ]
11
+ @tensor backend = tblisbackend C2[4 , 1 , 3 , 2 ] := A[1 , 2 , 3 , 4 ]
11
12
@test C2 ≈ C1
12
13
end
13
14
@@ -16,49 +17,50 @@ using LinearAlgebra: norm
16
17
B = randn (Float32, (5 , 6 , 3 , 4 ))
17
18
α = randn (Float32)
18
19
@tensor C1[a, b, c, d] := A[a, b, c, d] + α * B[a, b, c, d]
19
- @tensor backend = tblis C2[a, b, c, d] := A[a, b, c, d] + α * B[a, b, c, d]
20
+ @tensor backend = tblisbackend C2[a, b, c, d] := A[a, b, c, d] + α * B[a, b, c, d]
20
21
@test collect (C2) ≈ C1
21
22
22
23
C = randn (ComplexF32, (5 , 6 , 3 , 4 ))
23
24
D = randn (ComplexF32, (5 , 3 , 4 , 6 ))
24
25
β = randn (ComplexF32)
25
26
@tensor E1[a, b, c, d] := C[a, b, c, d] + β * conj (D[a, c, d, b])
26
- @tensor backend = tblis E2[a, b, c, d] := C[a, b, c, d] + β * conj (D[a, c, d, b])
27
+ @tensor backend = tblisbackend E2[a, b, c, d] := C[a, b, c, d] +
28
+ β * conj (D[a, c, d, b])
27
29
@test collect (E2) ≈ E1
28
30
end
29
31
30
32
@testset " tensortrace" begin
31
33
A = randn (Float32, (5 , 10 , 10 ))
32
34
@tensor B1[a] := A[a, b′, b′]
33
- @tensor backend = tblis B2[a] := A[a, b′, b′]
35
+ @tensor backend = tblisbackend B2[a] := A[a, b′, b′]
34
36
@test B2 ≈ B1
35
37
36
38
C = randn (ComplexF32, (3 , 20 , 5 , 3 , 20 , 4 , 5 ))
37
39
@tensor D1[e, a, d] := C[a, b, c, d, b, e, c]
38
- @tensor backend = tblis D2[e, a, d] := C[a, b, c, d, b, e, c]
40
+ @tensor backend = tblisbackend D2[e, a, d] := C[a, b, c, d, b, e, c]
39
41
@test D2 ≈ D1
40
42
41
43
@tensor D3[a, e, d] := conj (C[a, b, c, d, b, e, c])
42
- @tensor backend = tblis D4[a, e, d] := conj (C[a, b, c, d, b, e, c])
44
+ @tensor backend = tblisbackend D4[a, e, d] := conj (C[a, b, c, d, b, e, c])
43
45
@test D4 ≈ D3
44
46
45
47
α = randn (ComplexF32)
46
48
@tensor D5[d, e, a] := α * C[a, b, c, d, b, e, c]
47
- @tensor backend = tblis D6[d, e, a] := α * C[a, b, c, d, b, e, c]
49
+ @tensor backend = tblisbackend D6[d, e, a] := α * C[a, b, c, d, b, e, c]
48
50
@test D6 ≈ D5
49
51
end
50
52
51
53
@testset " tensorcontract" begin
52
54
A = randn (Float32, (3 , 20 , 5 , 3 , 4 ))
53
55
B = randn (Float32, (5 , 6 , 20 , 3 ))
54
56
@tensor C1[a, g, e, d, f] := A[a, b, c, d, e] * B[c, f, b, g]
55
- @tensor backend = tblis C2[a, g, e, d, f] := A[a, b, c, d, e] * B[c, f, b, g]
57
+ @tensor backend = tblisbackend C2[a, g, e, d, f] := A[a, b, c, d, e] * B[c, f, b, g]
56
58
@test C2 ≈ C1
57
59
58
60
D = randn (ComplexF64, (3 , 3 , 3 ))
59
61
E = rand (ComplexF64, (3 , 3 , 3 ))
60
62
@tensor F1[a, b, c, d, e, f] := D[a, b, c] * conj (E[d, e, f])
61
- @tensor backend = tblis F2[a, b, c, d, e, f] := D[a, b, c] * conj (E[d, e, f])
63
+ @tensor backend = tblisbackend F2[a, b, c, d, e, f] := D[a, b, c] * conj (E[d, e, f])
62
64
@test F2 ≈ F1 atol = 1e-12
63
65
end
64
66
end
72
74
# α = 1
73
75
74
76
@tensor D1[d, f, h] := A[c, a, f, a, e, b, b, g] * B[c, h, g, e, d] + α * C[d, h, f]
75
- @tensor backend = tblis D2[d, f, h] := A[c, a, f, a, e, b, b, g] * B[c, h, g, e, d] +
76
- α * C[d, h, f]
77
+ @tensor backend = tblisbackend D2[d, f, h] := A[c, a, f, a, e, b, b, g] *
78
+ B[c, h, g, e, d] +
79
+ α * C[d, h, f]
77
80
@test D2 ≈ D1 rtol = 1e-8
78
81
79
82
@test norm (vec (D1)) ≈ sqrt (abs (@tensor D1[d, f, h] * conj (D1[d, f, h])))
80
- @test norm (D2) ≈ sqrt (abs (@tensor backend = tblis D2[d, f, h] * conj (D2[d, f, h])))
83
+ @test norm (D2) ≈
84
+ sqrt (abs (@tensor backend = tblisbackend D2[d, f, h] * conj (D2[d, f, h])))
81
85
82
86
@testset " readme example" begin
83
87
α = randn ()
90
94
D[a, b, c] = A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
91
95
E[a, b, c] := A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
92
96
end
93
- @tensor backend = tblis begin
97
+ @tensor backend = tblisbackend begin
94
98
D2[a, b, c] = A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
95
99
E2[a, b, c] := A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
96
100
end
113
117
HrA12[a, s1, s2, c] := ρₗ[a, a' ] * A1[a' , t1, b] * A2[b, t2, c' ] * ρᵣ[c' , c] *
114
118
H[s1, s2, t1, t2]
115
119
end
116
- @tensor backend = tblis begin
120
+ @tensor backend = tblisbackend begin
117
121
HrA12′[a, s1, s2, c] := ρₗ[a, a' ] * A1[a' , t1, b] * A2[b, t2, c' ] * ρᵣ[c' , c] *
118
122
H[s1, s2, t1, t2]
119
123
end
123
127
E1 = ρₗ[a' , a] * A1[a, s, b] * A2[b, s' , c] * ρᵣ[c, c' ] * H[t, t' , s, s' ] *
124
128
conj (A1[a' , t, b' ]) * conj (A2[b' , t' , c' ])
125
129
end
126
- @tensor backend = tblis begin
130
+ @tensor backend = tblisbackend begin
127
131
E2 = ρₗ[a' , a] * A1[a, s, b] * A2[b, s' , c] * ρᵣ[c, c' ] * H[t, t' , s, s' ] *
128
132
conj (A1[a' , t, b' ]) * conj (A2[b' , t' , c' ])
129
133
end
0 commit comments