@@ -19,7 +19,7 @@ Test the Enzyme foward- and reverse-mode AD rule for `eig_full` and its in-place
1919"""
2020function test_enzyme_eig_full (
2121 T, sz;
22- rng = Random . default_rng () , atol:: Real = 0 , rtol:: Real = precision (T),
22+ rng = TestSuite . rng , atol:: Real = 0 , rtol:: Real = precision (T),
2323 fdm = enzyme_fdm (T)
2424 )
2525 return @testset " eig_full: RT $RT , TA $TA " for RT in (Duplicated,), TA in (Duplicated,)
@@ -40,17 +40,17 @@ Test the Enzyme forward- and reverse-mode AD rule for `eig_vals` and its in-plac
4040"""
4141function test_enzyme_eig_vals (
4242 T, sz;
43- rng = Random . default_rng () , atol:: Real = 0 , rtol:: Real = precision (T),
43+ rng = TestSuite . rng , atol:: Real = 0 , rtol:: Real = precision (T),
4444 fdm = enzyme_fdm (T)
4545 )
4646 return @testset " eig_vals: RT $RT , TA $TA " for RT in (Duplicated,), TA in (Duplicated,)
4747 A = make_eig_matrix (T, sz)
4848 alg = MatrixAlgebraKit. select_algorithm (eig_vals, A)
4949 D, ΔD = ad_eig_vals_setup (A)
50- test_reverse (eig_vals , RT, (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
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)
50+ test_reverse (eig_vals_wrapper , RT, (eig_vals, Const) , (A, TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
51+ test_reverse (eig_vals!_wrapper , RT, (eig_vals!, Const), (copy (A), TA), (alg, Const); atol, rtol, output_tangent = ΔD, fdm)
52+ test_forward (eig_vals_wrapper , RT, (eig_vals, Const) , (A, TA), (alg, Const); atol, rtol, fdm)
53+ test_forward (eig_vals!_wrapper , RT, (eig_vals!, Const), (copy (A), TA), (alg, Const); atol, rtol, fdm)
5454 end
5555end
5656
@@ -62,7 +62,7 @@ in-place variants, over a range of truncation ranks and a tolerance-based trunca
6262"""
6363function test_enzyme_eig_trunc (
6464 T, sz;
65- rng = Random . default_rng () , atol:: Real = 0 , rtol:: Real = precision (T),
65+ rng = TestSuite . rng , atol:: Real = 0 , rtol:: Real = precision (T),
6666 fdm = enzyme_fdm (T)
6767 )
6868 return @testset " eig_trunc reverse: RT $RT , TA $TA " for RT in (Duplicated,), TA in (Duplicated,)
@@ -83,14 +83,16 @@ function test_enzyme_eig_trunc(
8383 @testset " trunctol" begin
8484 A = make_eig_matrix (T, sz)
8585 D = eig_vals (A)
86- trunc = trunctol (atol = maximum (abs, D) / 2 ; by = abs)
86+ trunc = trunctol (atol = midgap_tol (D) ; by = abs)
8787 truncalg = TruncatedAlgorithm (alg, trunc)
88- DV, _, ΔDV, ΔDVtrunc = ad_eig_trunc_setup (A, truncalg)
89- test_reverse (eig_trunc_no_error, RT, (A, TA), (truncalg, Const); atol, rtol, output_tangent = ΔDVtrunc, fdm)
90- test_reverse (call_and_zero!, RT, (eig_trunc_no_error!, Const), (copy (A), TA), (truncalg, Const); atol, rtol, output_tangent = ΔDVtrunc, fdm)
88+ DV, DVtrunc, ΔDV, ΔDVtrunc = ad_eig_trunc_setup (A, truncalg)
89+ # trunctol keeps LAPACK's eigenvalue ordering, so sort the outputs (and the tangent)
90+ ΔDVtrunc = permute_eigpairs (ΔDVtrunc, eigvals_sortperm (diagview (DVtrunc[1 ])))
91+ test_reverse (eig_trunc_wrapper, RT, (eig_trunc_no_error, Const), (A, TA), (truncalg, Const); atol, rtol, output_tangent = ΔDVtrunc, fdm)
92+ test_reverse (eig_trunc!_wrapper, RT, (eig_trunc_no_error!, Const), (copy (A), TA), (truncalg, Const); atol, rtol, output_tangent = ΔDVtrunc, fdm)
9193 # use max range here to try to dodge issues when the gap between eigenvalues is close to the FD perturbation
92- test_forward (eig_trunc_no_error , RT, (A, TA), (truncalg, Const); atol, rtol, fdm = EnzymeTestUtils. FiniteDifferences. central_fdm (5 , 1 , max_range = 1.0e-3 ))
93- test_forward (call_and_zero! , RT, (eig_trunc_no_error!, Const), (copy (A), TA), (truncalg, Const); atol, rtol, fdm = EnzymeTestUtils. FiniteDifferences. central_fdm (5 , 1 , max_range = 1.0e-3 ))
94+ test_forward (eig_trunc_wrapper , RT, (eig_trunc_no_error, Const) , (A, TA), (truncalg, Const); atol, rtol, fdm = EnzymeTestUtils. FiniteDifferences. central_fdm (5 , 1 , max_range = 1.0e-3 ))
95+ test_forward (eig_trunc!_wrapper , RT, (eig_trunc_no_error!, Const), (copy (A), TA), (truncalg, Const); atol, rtol, fdm = EnzymeTestUtils. FiniteDifferences. central_fdm (5 , 1 , max_range = 1.0e-3 ))
9496 end
9597 end
9698end
0 commit comments