@@ -9,131 +9,129 @@ is_ci = get(ENV, "CI", "false") == "true"
99spacelist = ad_spacelist (fast_tests)
1010eltypes = (Float64, ComplexF64)
1111
12- if ! (is_ci && Sys. iswindows () && VERSION < v " 1.11.0-rc" )
13- @timedtestset " Enzyme - TensorOperations" begin
14- @timedtestset verbose = true " $(TensorKit. type_repr (sectortype (eltype (V)))) ($T )" for V in spacelist, T in eltypes
15- atol = default_tol (T)
16- rtol = default_tol (T)
17- symmetricbraiding = BraidingStyle (sectortype (eltype (V))) isa SymmetricBraiding
18- symmetricbraiding && @timedtestset " tensorcontract!" begin
19- d = 0
20- local V1, V2, V3
21- # retry a couple times to make sure there are at least some nonzero elements
22- for _ in 1 : 10
23- k1 = rand (0 : 3 )
24- k2 = rand (0 : 2 )
25- k3 = rand (0 : 2 )
26- V1 = prod (v -> rand (Bool) ? v' : v, rand (V, k1); init = one (V[1 ]))
27- V2 = prod (v -> rand (Bool) ? v' : v, rand (V, k2); init = one (V[1 ]))
28- V3 = prod (v -> rand (Bool) ? v' : v, rand (V, k3); init = one (V[1 ]))
29- d = min (dim (V1 ← V2), dim (V1' ← V2), dim (V2 ← V3), dim (V2' ← V3))
30- d > 0 && break
31- end
32- ipA = randindextuple (length (V1) + length (V2))
33- pA = _repartition (invperm (linearize (ipA)), length (V1))
34- ipB = randindextuple (length (V2) + length (V3))
35- pB = _repartition (invperm (linearize (ipB)), length (V2))
36- pAB = randindextuple (length (V1) + length (V3))
12+ @timedtestset " Enzyme - TensorOperations" begin
13+ @timedtestset verbose = true " $(TensorKit. type_repr (sectortype (eltype (V)))) ($T )" for V in spacelist, T in eltypes
14+ atol = default_tol (T)
15+ rtol = default_tol (T)
16+ symmetricbraiding = BraidingStyle (sectortype (eltype (V))) isa SymmetricBraiding
17+ symmetricbraiding && @timedtestset " tensorcontract!" begin
18+ d = 0
19+ local V1, V2, V3
20+ # retry a couple times to make sure there are at least some nonzero elements
21+ for _ in 1 : 10
22+ k1 = rand (0 : 3 )
23+ k2 = rand (0 : 2 )
24+ k3 = rand (0 : 2 )
25+ V1 = prod (v -> rand (Bool) ? v' : v, rand (V, k1); init = one (V[1 ]))
26+ V2 = prod (v -> rand (Bool) ? v' : v, rand (V, k2); init = one (V[1 ]))
27+ V3 = prod (v -> rand (Bool) ? v' : v, rand (V, k3); init = one (V[1 ]))
28+ d = min (dim (V1 ← V2), dim (V1' ← V2), dim (V2 ← V3), dim (V2' ← V3))
29+ d > 0 && break
30+ end
31+ ipA = randindextuple (length (V1) + length (V2))
32+ pA = _repartition (invperm (linearize (ipA)), length (V1))
33+ ipB = randindextuple (length (V2) + length (V3))
34+ pB = _repartition (invperm (linearize (ipB)), length (V2))
35+ pAB = randindextuple (length (V1) + length (V3))
3736
38- α = randn (T)
39- β = randn (T)
40- V2_conj = prod (conj, V2; init = one (V[1 ]))
41- A = randn (T, permute (V1 ← V2, ipA))
42- B = randn (T, permute (V2 ← V3, ipB))
43- C = randn! (
44- TensorOperations. tensoralloc_contract (
45- T, A, pA, false , B, pB, false , pAB, Val (false )
46- )
37+ α = randn (T)
38+ β = randn (T)
39+ V2_conj = prod (conj, V2; init = one (V[1 ]))
40+ A = randn (T, permute (V1 ← V2, ipA))
41+ B = randn (T, permute (V2 ← V3, ipB))
42+ C = randn! (
43+ TensorOperations. tensoralloc_contract (
44+ T, A, pA, false , B, pB, false , pAB, Val (false )
4745 )
46+ )
4847
49- αβs = is_ci ? (((α, Active), (β, Active)),) : Iterators. product (((One (), Const), (α, Const), (α, Active)), ((Zero (), Const), (β, Const), (β, Active)))
50- for (α_, β_) in αβs
51- EnzymeTestUtils. test_reverse (
52- TensorKit. blas_contract!, Duplicated,
53- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
54- (B, Duplicated), (pB, Const), (pAB, Const),
55- α_, β_,
56- (TensorOperations. DefaultBackend (), Const),
57- (TensorOperations. DefaultAllocator (), Const);
58- atol, rtol,
59- testset_name = " blas_contract! reverse α $α_ β $β_ " ,
60- )
61- end
62- αβs = is_ci ? (((α, Duplicated), (β, Duplicated)),) : Iterators. product (((One (), Const), (α, Const), (α, Duplicated)), ((Zero (), Const), (β, Const), (β, Duplicated)))
63- for (α_, β_) in αβs
64- EnzymeTestUtils. test_forward (
65- TensorKit. blas_contract!, Duplicated,
66- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
67- (B, Duplicated), (pB, Const), (pAB, Const),
68- α_, β_,
69- (TensorOperations. DefaultBackend (), Const),
70- (TensorOperations. DefaultAllocator (), Const);
71- atol, rtol,
72- testset_name = " blas_contract! forward α $α_ β $β_ " ,
73- )
74- end
75- if ! (T <: Real ) && ! is_ci
76- EnzymeTestUtils. test_reverse (
77- TensorKit. blas_contract!, Duplicated,
78- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
79- (B, Duplicated), (pB, Const), (pAB, Const),
80- (real (α), Active), (real (β), Active),
81- (TensorOperations. DefaultBackend (), Const),
82- (TensorOperations. DefaultAllocator (), Const);
83- atol, rtol,
84- testset_name = " blas_contract! reverse real(α) real(β)" ,
85- )
86- EnzymeTestUtils. test_reverse (
87- TensorKit. blas_contract!, Duplicated,
88- (copy (C), Duplicated), (real (A), Duplicated), (pA, Const),
89- (B, Duplicated), (pB, Const), (pAB, Const),
90- (real (α), Active), (real (β), Active),
91- (TensorOperations. DefaultBackend (), Const),
92- (TensorOperations. DefaultAllocator (), Const);
93- atol, rtol,
94- testset_name = " blas_contract! reverse real(A) real(α) real(β)" ,
95- )
96- EnzymeTestUtils. test_reverse (
97- TensorKit. blas_contract!, Duplicated,
98- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
99- (real (B), Duplicated), (pB, Const), (pAB, Const),
100- (real (α), Active), (real (β), Active),
101- (TensorOperations. DefaultBackend (), Const),
102- (TensorOperations. DefaultAllocator (), Const);
103- atol, rtol,
104- testset_name = " blas_contract! reverse real(B) real(α) real(β)" ,
105- )
106- EnzymeTestUtils. test_forward (
107- TensorKit. blas_contract!, Duplicated,
108- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
109- (B, Duplicated), (pB, Const), (pAB, Const),
110- (real (α), Active), (real (β), Active),
111- (TensorOperations. DefaultBackend (), Const),
112- (TensorOperations. DefaultAllocator (), Const);
113- atol, rtol,
114- testset_name = " blas_contract! forward real(α) real(β)" ,
115- )
116- EnzymeTestUtils. test_forward (
117- TensorKit. blas_contract!, Duplicated,
118- (copy (C), Duplicated), (real (A), Duplicated), (pA, Const),
119- (B, Duplicated), (pB, Const), (pAB, Const),
120- (real (α), Active), (real (β), Active),
121- (TensorOperations. DefaultBackend (), Const),
122- (TensorOperations. DefaultAllocator (), Const);
123- atol, rtol,
124- testset_name = " blas_contract! forward real(A) real(α) real(β)" ,
125- )
126- EnzymeTestUtils. test_forward (
127- TensorKit. blas_contract!, Duplicated,
128- (copy (C), Duplicated), (A, Duplicated), (pA, Const),
129- (real (B), Duplicated), (pB, Const), (pAB, Const),
130- (real (α), Active), (real (β), Active),
131- (TensorOperations. DefaultBackend (), Const),
132- (TensorOperations. DefaultAllocator (), Const);
133- atol, rtol,
134- testset_name = " blas_contract! forward real(B) real(α) real(β)" ,
135- )
136- end
48+ αβs = is_ci ? (((α, Active), (β, Active)),) : Iterators. product (((One (), Const), (α, Const), (α, Active)), ((Zero (), Const), (β, Const), (β, Active)))
49+ for (α_, β_) in αβs
50+ EnzymeTestUtils. test_reverse (
51+ TensorKit. blas_contract!, Duplicated,
52+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
53+ (B, Duplicated), (pB, Const), (pAB, Const),
54+ α_, β_,
55+ (TensorOperations. DefaultBackend (), Const),
56+ (TensorOperations. DefaultAllocator (), Const);
57+ atol, rtol,
58+ testset_name = " blas_contract! reverse α $α_ β $β_ " ,
59+ )
60+ end
61+ αβs = is_ci ? (((α, Duplicated), (β, Duplicated)),) : Iterators. product (((One (), Const), (α, Const), (α, Duplicated)), ((Zero (), Const), (β, Const), (β, Duplicated)))
62+ for (α_, β_) in αβs
63+ EnzymeTestUtils. test_forward (
64+ TensorKit. blas_contract!, Duplicated,
65+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
66+ (B, Duplicated), (pB, Const), (pAB, Const),
67+ α_, β_,
68+ (TensorOperations. DefaultBackend (), Const),
69+ (TensorOperations. DefaultAllocator (), Const);
70+ atol, rtol,
71+ testset_name = " blas_contract! forward α $α_ β $β_ " ,
72+ )
73+ end
74+ if ! (T <: Real ) && ! is_ci
75+ EnzymeTestUtils. test_reverse (
76+ TensorKit. blas_contract!, Duplicated,
77+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
78+ (B, Duplicated), (pB, Const), (pAB, Const),
79+ (real (α), Active), (real (β), Active),
80+ (TensorOperations. DefaultBackend (), Const),
81+ (TensorOperations. DefaultAllocator (), Const);
82+ atol, rtol,
83+ testset_name = " blas_contract! reverse real(α) real(β)" ,
84+ )
85+ EnzymeTestUtils. test_reverse (
86+ TensorKit. blas_contract!, Duplicated,
87+ (copy (C), Duplicated), (real (A), Duplicated), (pA, Const),
88+ (B, Duplicated), (pB, Const), (pAB, Const),
89+ (real (α), Active), (real (β), Active),
90+ (TensorOperations. DefaultBackend (), Const),
91+ (TensorOperations. DefaultAllocator (), Const);
92+ atol, rtol,
93+ testset_name = " blas_contract! reverse real(A) real(α) real(β)" ,
94+ )
95+ EnzymeTestUtils. test_reverse (
96+ TensorKit. blas_contract!, Duplicated,
97+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
98+ (real (B), Duplicated), (pB, Const), (pAB, Const),
99+ (real (α), Active), (real (β), Active),
100+ (TensorOperations. DefaultBackend (), Const),
101+ (TensorOperations. DefaultAllocator (), Const);
102+ atol, rtol,
103+ testset_name = " blas_contract! reverse real(B) real(α) real(β)" ,
104+ )
105+ EnzymeTestUtils. test_forward (
106+ TensorKit. blas_contract!, Duplicated,
107+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
108+ (B, Duplicated), (pB, Const), (pAB, Const),
109+ (real (α), Active), (real (β), Active),
110+ (TensorOperations. DefaultBackend (), Const),
111+ (TensorOperations. DefaultAllocator (), Const);
112+ atol, rtol,
113+ testset_name = " blas_contract! forward real(α) real(β)" ,
114+ )
115+ EnzymeTestUtils. test_forward (
116+ TensorKit. blas_contract!, Duplicated,
117+ (copy (C), Duplicated), (real (A), Duplicated), (pA, Const),
118+ (B, Duplicated), (pB, Const), (pAB, Const),
119+ (real (α), Active), (real (β), Active),
120+ (TensorOperations. DefaultBackend (), Const),
121+ (TensorOperations. DefaultAllocator (), Const);
122+ atol, rtol,
123+ testset_name = " blas_contract! forward real(A) real(α) real(β)" ,
124+ )
125+ EnzymeTestUtils. test_forward (
126+ TensorKit. blas_contract!, Duplicated,
127+ (copy (C), Duplicated), (A, Duplicated), (pA, Const),
128+ (real (B), Duplicated), (pB, Const), (pAB, Const),
129+ (real (α), Active), (real (β), Active),
130+ (TensorOperations. DefaultBackend (), Const),
131+ (TensorOperations. DefaultAllocator (), Const);
132+ atol, rtol,
133+ testset_name = " blas_contract! forward real(B) real(α) real(β)" ,
134+ )
137135 end
138136 end
139137 end
0 commit comments