@@ -3,11 +3,12 @@ using TensorOperationsTBLIS
33using Test
44using LinearAlgebra: norm
55
6+ const tblisbackend = tblisBackend ()
67@testset " elementary operations" verbose = true begin
78 @testset " tensorcopy" begin
89 A = randn (Float32, (3 , 5 , 4 , 6 ))
910 @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 ]
1112 @test C2 ≈ C1
1213 end
1314
@@ -16,49 +17,50 @@ using LinearAlgebra: norm
1617 B = randn (Float32, (5 , 6 , 3 , 4 ))
1718 α = randn (Float32)
1819 @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]
2021 @test collect (C2) ≈ C1
2122
2223 C = randn (ComplexF32, (5 , 6 , 3 , 4 ))
2324 D = randn (ComplexF32, (5 , 3 , 4 , 6 ))
2425 β = randn (ComplexF32)
2526 @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])
2729 @test collect (E2) ≈ E1
2830 end
2931
3032 @testset " tensortrace" begin
3133 A = randn (Float32, (5 , 10 , 10 ))
3234 @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′]
3436 @test B2 ≈ B1
3537
3638 C = randn (ComplexF32, (3 , 20 , 5 , 3 , 20 , 4 , 5 ))
3739 @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]
3941 @test D2 ≈ D1
4042
4143 @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])
4345 @test D4 ≈ D3
4446
4547 α = randn (ComplexF32)
4648 @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]
4850 @test D6 ≈ D5
4951 end
5052
5153 @testset " tensorcontract" begin
5254 A = randn (Float32, (3 , 20 , 5 , 3 , 4 ))
5355 B = randn (Float32, (5 , 6 , 20 , 3 ))
5456 @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]
5658 @test C2 ≈ C1
5759
5860 D = randn (ComplexF64, (3 , 3 , 3 ))
5961 E = rand (ComplexF64, (3 , 3 , 3 ))
6062 @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])
6264 @test F2 ≈ F1 atol = 1e-12
6365 end
6466end
7274 # α = 1
7375
7476 @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]
7780 @test D2 ≈ D1 rtol = 1e-8
7881
7982 @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])))
8185
8286 @testset " readme example" begin
8387 α = randn ()
9094 D[a, b, c] = A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
9195 E[a, b, c] := A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
9296 end
93- @tensor backend = tblis begin
97+ @tensor backend = tblisbackend begin
9498 D2[a, b, c] = A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
9599 E2[a, b, c] := A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
96100 end
113117 HrA12[a, s1, s2, c] := ρₗ[a, a' ] * A1[a' , t1, b] * A2[b, t2, c' ] * ρᵣ[c' , c] *
114118 H[s1, s2, t1, t2]
115119 end
116- @tensor backend = tblis begin
120+ @tensor backend = tblisbackend begin
117121 HrA12′[a, s1, s2, c] := ρₗ[a, a' ] * A1[a' , t1, b] * A2[b, t2, c' ] * ρᵣ[c' , c] *
118122 H[s1, s2, t1, t2]
119123 end
123127 E1 = ρₗ[a' , a] * A1[a, s, b] * A2[b, s' , c] * ρᵣ[c, c' ] * H[t, t' , s, s' ] *
124128 conj (A1[a' , t, b' ]) * conj (A2[b' , t' , c' ])
125129 end
126- @tensor backend = tblis begin
130+ @tensor backend = tblisbackend begin
127131 E2 = ρₗ[a' , a] * A1[a, s, b] * A2[b, s' , c] * ρᵣ[c, c' ] * H[t, t' , s, s' ] *
128132 conj (A1[a' , t, b' ]) * conj (A2[b' , t' , c' ])
129133 end
0 commit comments