Skip to content

Commit dea46d6

Browse files
committed
Fix a bug in the eig pushfwd and enable more tests
1 parent c3cf149 commit dea46d6

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

‎src/pushforwards/eig.jl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function eig_pushforward!(
1212
if !iszerotangent(ΔV)
1313
∂K .*= inv_safe.(transpose(diagview(D)) .- diagview(D), degeneracy_atol)
1414
mul!(ΔV, V, ∂K)
15+
ΔV .-= V .* real.(sum(conj.(V) .* ΔV; dims = 1))
1516
if eltype(V) <: Complex # fix gauge for `gaugefix!` compatibility
1617
_, I = findmax(abs, V; dims = 1)
1718
infinitesimal_phases = imag.(ΔV[I] ./ V[I])

‎test/testsuite/enzyme/eig.jl‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ function test_enzyme_eig_full(
2727
alg = MatrixAlgebraKit.select_algorithm(eig_full, A)
2828
DV, ΔDV = ad_eig_full_setup(A)
2929
test_reverse(eig_full, RT, (A, TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
30-
test_reverse(call_and_zero!, RT, (eig_full!, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
31-
if eltype(T) <: Real && T <: Diagonal
32-
A = make_eig_matrix(T, sz)
33-
test_forward(eig_full, RT, (A, TA), (alg, Const); atol, rtol, fdm)
34-
test_forward(call_and_zero!, RT, (eig_full!, Const), (A, TA), (alg, Const); atol, rtol, fdm)
35-
end
30+
test_reverse(call_and_zero!, RT, (eig_full!, Const), (copy(A), TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
31+
test_forward(eig_full, RT, (A, TA), (alg, Const); atol, rtol, fdm)
32+
test_forward(call_and_zero!, RT, (eig_full!, Const), (copy(A), TA), (alg, Const); atol, rtol, fdm)
3633
end
3734
end
3835

@@ -51,12 +48,9 @@ function test_enzyme_eig_vals(
5148
alg = MatrixAlgebraKit.select_algorithm(eig_vals, A)
5249
D, ΔD = ad_eig_vals_setup(A)
5350
test_reverse(eig_vals, RT, (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
54-
test_reverse(call_and_zero!, RT, (eig_vals!, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
55-
if eltype(T) <: Real
56-
A = make_eig_matrix(T, sz)
57-
test_forward(eig_vals, RT, (A, TA), (alg, Const); atol, rtol, fdm)
58-
test_forward(call_and_zero!, RT, (eig_vals!, Const), (A, TA), (alg, Const); atol, rtol, fdm)
59-
end
51+
test_reverse(call_and_zero!, RT, (eig_vals!, Const), (copy(A), TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
52+
test_forward(eig_vals, RT, (A, TA), (alg, Const); atol, rtol, fdm)
53+
test_forward(call_and_zero!, RT, (eig_vals!, Const), (copy(A), TA), (alg, Const); atol, rtol, fdm)
6054
end
6155
end
6256

‎test/testsuite/enzyme/eigh.jl‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ function test_enzyme_eigh_full(
2727
alg = MatrixAlgebraKit.select_algorithm(eigh_full, A)
2828
DV, ΔDV = ad_eigh_full_setup(A)
2929
test_reverse(eigh_wrapper, RT, (eigh_full, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
30-
test_reverse(eigh!_wrapper, RT, (eigh_full!, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
31-
if eltype(T) <: Real
32-
A = make_eigh_matrix(T, sz)
33-
test_forward(eigh_wrapper, RT, (eigh_full, Const), (A, TA), (alg, Const); atol, rtol, fdm)
34-
test_forward(eigh!_wrapper, RT, (eigh_full!, Const), (A, TA), (alg, Const); atol, rtol, fdm)
35-
end
30+
test_reverse(eigh!_wrapper, RT, (eigh_full!, Const), (copy(A), TA), (alg, Const); atol, rtol, output_tangent = ΔDV, fdm)
31+
test_forward(eigh_wrapper, RT, (eigh_full, Const), (A, TA), (alg, Const); atol, rtol, fdm)
32+
test_forward(eigh!_wrapper, RT, (eigh_full!, Const), (copy(A), TA), (alg, Const); atol, rtol, fdm)
3633
end
3734
end
3835

@@ -51,10 +48,9 @@ function test_enzyme_eigh_vals(
5148
alg = MatrixAlgebraKit.select_algorithm(eigh_vals, A)
5249
D, ΔD = ad_eigh_vals_setup(A)
5350
test_reverse(eigh_wrapper, RT, (eigh_vals, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
54-
test_reverse(eigh!_wrapper, RT, (eigh_vals!, Const), (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
55-
A = make_eigh_matrix(T, sz)
51+
test_reverse(eigh!_wrapper, RT, (eigh_vals!, Const), (copy(A), TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
5652
test_forward(eigh_wrapper, RT, (eigh_vals, Const), (A, TA), (alg, Const); atol, rtol, fdm)
57-
test_forward(eigh!_wrapper, RT, (eigh_vals!, Const), (A, TA), (alg, Const); atol, rtol, fdm)
53+
test_forward(eigh!_wrapper, RT, (eigh_vals!, Const), (copy(A), TA), (alg, Const); atol, rtol, fdm)
5854
end
5955
end
6056

0 commit comments

Comments
 (0)