diff --git a/test/enzyme-indexmanipulations-flip-twist/flip.jl b/test/enzyme-indexmanipulations-flip-twist/flip.jl new file mode 100644 index 000000000..1349fbc62 --- /dev/null +++ b/test/enzyme-indexmanipulations-flip-twist/flip.jl @@ -0,0 +1,22 @@ +using Test, TestExtras +using TensorKit +using Enzyme, EnzymeTestUtils +using Random + +spacelist = ad_spacelist(fast_tests) +eltypes = (Float64, ComplexF64) + +@timedtestset "Enzyme - Index Manipulations (flip):" begin + @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) TA ($TA)" for V in spacelist, T in eltypes, TA in (Duplicated,) + atol = default_tol(T) + rtol = default_tol(T) + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), [1, 3]; atol, rtol, fkwargs = (inv = true,)) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), ([1, 3], Const); atol, rtol) + end + end +end diff --git a/test/enzyme-indexmanipulations-flip-twist/twist.jl b/test/enzyme-indexmanipulations-flip-twist/twist.jl new file mode 100644 index 000000000..ec8f9cb11 --- /dev/null +++ b/test/enzyme-indexmanipulations-flip-twist/twist.jl @@ -0,0 +1,24 @@ +using Test, TestExtras +using TensorKit +using TensorOperations +using VectorInterface: Zero, One +using Enzyme, EnzymeTestUtils +using Random + +spacelist = ad_spacelist(fast_tests) +eltypes = (Float64, ComplexF64) + +@timedtestset "Enzyme - Index Manipulations (twist):" begin + @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TA in (Duplicated,) + atol = default_tol(T) + rtol = default_tol(T) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding && !(T <: Real && !(sectorscalartype(sectortype(A)) <: Real)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), (1, Const); atol, rtol) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol) + end + end +end diff --git a/test/enzyme-indexmanipulations/braid.jl b/test/enzyme-indexmanipulations-transform/braid.jl similarity index 78% rename from test/enzyme-indexmanipulations/braid.jl rename to test/enzyme-indexmanipulations-transform/braid.jl index 28d1e52ba..ae5f055ad 100644 --- a/test/enzyme-indexmanipulations/braid.jl +++ b/test/enzyme-indexmanipulations-transform/braid.jl @@ -11,12 +11,12 @@ is_ci = get(ENV, "CI", "false") == "true" Tαs = is_ci ? (Active,) : (Active, Const) Tβs = is_ci ? (Active,) : (Active, Const) -@timedtestset "Enzyme - Index Manipulations (braid!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) Tα $Tα Tβ $Tβ" for V in spacelist, T in eltypes, Tα in Tαs, Tβ in Tβs - atol = default_tol(T) - rtol = default_tol(T) - Vstr = TensorKit.type_repr(sectortype(eltype(V))) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) +@timedtestset "Enzyme - Index Manipulations (braid!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T) Tα $Tα Tβ $Tβ" for V in spacelist, T in eltypes, Tα in Tαs, Tβ in Tβs + atol = default_tol(T) + rtol = default_tol(T) + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') α = randn(T) β = randn(T) p = randcircshift(numout(A), numin(A)) diff --git a/test/enzyme-indexmanipulations/permute.jl b/test/enzyme-indexmanipulations-transform/permute.jl similarity index 72% rename from test/enzyme-indexmanipulations/permute.jl rename to test/enzyme-indexmanipulations-transform/permute.jl index a7f6126d6..d78ec1e41 100644 --- a/test/enzyme-indexmanipulations/permute.jl +++ b/test/enzyme-indexmanipulations-transform/permute.jl @@ -11,14 +11,15 @@ is_ci = get(ENV, "CI", "false") == "true" Tαs = is_ci ? (Active,) : (Active, Const) Tβs = is_ci ? (Active,) : (Active, Const) -@timedtestset "Enzyme - Index Manipulations (permute!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes +if VERSION >= v"1.11.0-rc" # segfault issues on 1.10 + @timedtestset "Enzyme - Index Manipulations (permute!): $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + println(TensorKit.type_repr(sectortype(eltype(V)))) atol = default_tol(T) rtol = default_tol(T) symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding symmetricbraiding && @timedtestset "permute! Tα $Tα, Tβ $Tβ" for Tα in Tαs, Tβ in Tβs - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') α = randn(T) β = randn(T) p = randindextuple(numind(A)) diff --git a/test/enzyme-indexmanipulations-transform/transpose.jl b/test/enzyme-indexmanipulations-transform/transpose.jl new file mode 100644 index 000000000..9e6703eb1 --- /dev/null +++ b/test/enzyme-indexmanipulations-transform/transpose.jl @@ -0,0 +1,35 @@ +using Test, TestExtras +using TensorKit +using TensorOperations +using VectorInterface: Zero, One +using Enzyme, EnzymeTestUtils +using Random + +spacelist = ad_spacelist(fast_tests) +eltypes = (Float64, ComplexF64) + +is_ci = get(ENV, "CI", "false") == "true" + +Tαs = is_ci ? (Active,) : (Active, Const) +Tβs = is_ci ? (Active,) : (Active, Const) + +@timedtestset "Enzyme - Index Manipulations (transpose!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + atol = default_tol(T) + rtol = default_tol(T) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + α = randn(T) + β = randn(T) + + # repeat a couple times to get some distribution of arrows + p = randcircshift(numout(A), numin(A)) + C = randn!(transpose(A, p)) + !is_ci && EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) + @testset for Tα in Tαs, Tβ in Tβs + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + if !(T <: Real) && !is_ci + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) + end + end +end diff --git a/test/enzyme-indexmanipulations/insertunit.jl b/test/enzyme-indexmanipulations-unit/insertunit.jl similarity index 95% rename from test/enzyme-indexmanipulations/insertunit.jl rename to test/enzyme-indexmanipulations-unit/insertunit.jl index 15e02d22c..69c299b0e 100644 --- a/test/enzyme-indexmanipulations/insertunit.jl +++ b/test/enzyme-indexmanipulations-unit/insertunit.jl @@ -10,7 +10,7 @@ eltypes = (Float64, ComplexF64) @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TA in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') @testset for insertunit in (insertleftunit, insertrightunit) EnzymeTestUtils.test_reverse(insertunit, TA, (A, TA), (Val(1), Const); atol, rtol) EnzymeTestUtils.test_reverse(insertunit, TA, (A, TA), (Val(4), Const); atol, rtol) diff --git a/test/enzyme-indexmanipulations/removeunit.jl b/test/enzyme-indexmanipulations-unit/removeunit.jl similarity index 92% rename from test/enzyme-indexmanipulations/removeunit.jl rename to test/enzyme-indexmanipulations-unit/removeunit.jl index 2249483be..3e64cb2cd 100644 --- a/test/enzyme-indexmanipulations/removeunit.jl +++ b/test/enzyme-indexmanipulations-unit/removeunit.jl @@ -10,7 +10,7 @@ eltypes = (Float64, ComplexF64) @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TB in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') for i in 1:2 B = insertleftunit(A, i; dual = rand(Bool)) EnzymeTestUtils.test_reverse(removeunit, TB, (B, TB), (Val(i), Const); atol, rtol, fkwargs = (copy = false,)) diff --git a/test/enzyme-indexmanipulations/flip.jl b/test/enzyme-indexmanipulations/flip.jl deleted file mode 100644 index 8afe4e914..000000000 --- a/test/enzyme-indexmanipulations/flip.jl +++ /dev/null @@ -1,19 +0,0 @@ -using Test, TestExtras -using TensorKit -using Enzyme, EnzymeTestUtils -using Random - -spacelist = ad_spacelist(fast_tests) -eltypes = (Float64, ComplexF64) - -@timedtestset "Enzyme - Index Manipulations (flip):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) TA ($TA)" for V in spacelist, T in eltypes, TA in (Duplicated,) - atol = default_tol(T) - rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), [1, 3]; atol, rtol, fkwargs = (inv = true,)) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), ([1, 3], Const); atol, rtol) - end -end diff --git a/test/enzyme-indexmanipulations/transpose.jl b/test/enzyme-indexmanipulations/transpose.jl deleted file mode 100644 index bff2cb379..000000000 --- a/test/enzyme-indexmanipulations/transpose.jl +++ /dev/null @@ -1,37 +0,0 @@ -using Test, TestExtras -using TensorKit -using TensorOperations -using VectorInterface: Zero, One -using Enzyme, EnzymeTestUtils -using Random - -spacelist = ad_spacelist(fast_tests) -eltypes = (Float64, ComplexF64) - -is_ci = get(ENV, "CI", "false") == "true" - -Tαs = is_ci ? (Active,) : (Active, Const) -Tβs = is_ci ? (Active,) : (Active, Const) - -@timedtestset "Enzyme - Index Manipulations (transpose!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes - atol = default_tol(T) - rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) - α = randn(T) - β = randn(T) - - # repeat a couple times to get some distribution of arrows - p = randcircshift(numout(A), numin(A)) - C = randn!(transpose(A, p)) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) - @testset for Tα in Tαs, Tβ in Tβs - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) - if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) - end - end - end -end diff --git a/test/enzyme-indexmanipulations/twist.jl b/test/enzyme-indexmanipulations/twist.jl deleted file mode 100644 index c939c76d2..000000000 --- a/test/enzyme-indexmanipulations/twist.jl +++ /dev/null @@ -1,23 +0,0 @@ -using Test, TestExtras -using TensorKit -using TensorOperations -using VectorInterface: Zero, One -using Enzyme, EnzymeTestUtils -using Random - -spacelist = ad_spacelist(fast_tests) -eltypes = (Float64, ComplexF64) - -@timedtestset "Enzyme - Index Manipulations (twist):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TA in (Duplicated,) - atol = default_tol(T) - rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) - if !(T <: Real && !(sectorscalartype(sectortype(A)) <: Real)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), (1, Const); atol, rtol) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), ([1, 3], Const); atol, rtol) - end - end -end