@@ -56,5 +56,33 @@ TAs = is_ci ? (Duplicated,) : (Const, Duplicated)
5656 end
5757 end
5858 end
59+ @timedtestset " planartrace!" begin
60+ for _ in 1 : 5
61+ k1 = rand (0 : 2 )
62+ k2 = rand (0 : 1 )
63+ V1 = map (v -> rand (Bool) ? v' : v, rand (V, k1))
64+ V2 = map (v -> rand (Bool) ? v' : v, rand (V, k2))
65+ V3 = prod (x -> x ⊗ x' , V2[1 : k2]; init = one (V[1 ]))
66+ V4 = prod (x -> x ⊗ x' , V2[(k2 + 1 ): end ]; init = one (V[1 ]))
67+
68+ k′ = rand (0 : (k1 + 2 k2))
69+ (_p, _q) = randcircshift (k′, k1 + 2 k2 - k′, k1)
70+ p = _repartition (_p, rand (0 : k1))
71+ q = (tuple (_q[1 : 2 : end ]. .. ), tuple (_q[2 : 2 : end ]. .. ))
72+ if ! all (isempty, p) && ! all (isempty, q)
73+ α = randn (T)
74+ β = randn (T)
75+ ip = _repartition (invperm (linearize ((_p, _q))), k′)
76+ A = randn (T, permute (prod (V1) ⊗ V3 ← V4, ip))
77+ C = randn! (TensorOperations. tensoralloc_add (T, A, p, false , Val (false )))
78+ for Tα in (Const, Active), Tβ in (Const, Active)
79+ EnzymeTestUtils. test_reverse (TensorKit. planartrace!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (q, Const), (α, Tα), (β, Tβ), (TensorOperations. DefaultBackend (), Const), (TensorOperations. DefaultAllocator (), Const); atol, rtol, testset_name = " planartrace reverse Tα $Tα Tβ $Tβ " )
80+ end
81+ for Tα in (Const, Duplicated), Tβ in (Const, Duplicated)
82+ EnzymeTestUtils. test_forward (TensorKit. planartrace!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (q, Const), (α, Tα), (β, Tβ), (TensorOperations. DefaultBackend (), Const), (TensorOperations. DefaultAllocator (), Const); atol, rtol, testset_name = " planartrace forward Tα $Tα Tβ $Tβ " )
83+ end
84+ end
85+ end
86+ end
5987 end
6088end
0 commit comments