|
| 1 | +using Test, TestExtras |
| 2 | +using TensorKit, Enzyme, EnzymeTestUtils |
| 3 | +using TensorOperations |
| 4 | +using Random |
| 5 | + |
| 6 | +#spacelist = ad_spacelist(fast_tests) |
| 7 | +spacelist = [ad_spacelist(fast_tests)[1]] |
| 8 | +eltypes = (Float64, ComplexF64) |
| 9 | + |
| 10 | +@testset "Enzyme - VectorInterface (add!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes |
| 11 | + atol = default_tol(T) |
| 12 | + rtol = default_tol(T) |
| 13 | + |
| 14 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 15 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 16 | + α = randn(T) |
| 17 | + β = randn(T) |
| 18 | + |
| 19 | + for TC in (Duplicated,), TA in (Duplicated,) |
| 20 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 21 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 22 | + EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA); atol, rtol, testset_name = "add! reverse TC $TC TA $TA no α no β") |
| 23 | + EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA); atol, rtol, testset_name = "add! forward TC $TC TA $TA no α no β") |
| 24 | + for Tα in (Active, Const) |
| 25 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 26 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 27 | + EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA), (α, Tα); atol, rtol, testset_name = "add! reverse TC $TC TA $TA Tα $Tα no β") |
| 28 | + for Tβ in (Active, Const) |
| 29 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 30 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 31 | + EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA), (α, Tα), (β, Tβ); atol, rtol, testset_name = "add! reverse TC $TC TA $TA Tα $Tα Tβ $Tβ") |
| 32 | + end |
| 33 | + end |
| 34 | + for Tα in (Duplicated, Const) |
| 35 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 36 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 37 | + EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA), (α, Tα); atol, rtol, testset_name = "add! forward TC $TC TA $TA Tα $Tα no β") |
| 38 | + for Tβ in (Duplicated, Const) |
| 39 | + C = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 40 | + A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5]) |
| 41 | + EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA), (α, Tα), (β, Tβ); atol, rtol, testset_name = "add! forward TC $TC TA $TA Tα $Tα Tβ $Tβ") |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | +end |
0 commit comments