|
| 1 | +""" |
| 2 | + test_enzyme_projections(T, sz; kwargs...) |
| 3 | +
|
| 4 | +Run all Enzyme AD tests for hermitian and anti-hermitian projections of element type `T` |
| 5 | +and size `sz`. |
| 6 | +""" |
| 7 | +function test_enzyme_projections(T::Type, sz; kwargs...) |
| 8 | + summary_str = testargs_summary(T, sz) |
| 9 | + return @testset "Enzyme projection $summary_str" begin |
| 10 | + test_enzyme_project_hermitian(T, sz; kwargs...) |
| 11 | + test_enzyme_project_antihermitian(T, sz; kwargs...) |
| 12 | + end |
| 13 | +end |
| 14 | + |
| 15 | +""" |
| 16 | + test_enzyme_project_hermitian(T, sz; rng, atol, rtol) |
| 17 | +
|
| 18 | +Test the Enzyme reverse-mode AD rule for `project_hermitian` and its in-place variant. |
| 19 | +""" |
| 20 | +function test_enzyme_project_hermitian( |
| 21 | + T, sz; |
| 22 | + rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T), |
| 23 | + fdm = enzyme_fdm(T) |
| 24 | + ) |
| 25 | + return @testset "project_hermitian" begin |
| 26 | + A = instantiate_matrix(T, sz) |
| 27 | + B = instantiate_matrix(T, sz) |
| 28 | + alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) |
| 29 | + test_reverse(project_hermitian, RT, (A, TA), (alg, Const); atol, rtol, fdm) |
| 30 | + test_reverse(project_hermitian!, RT, (A, TA), (A, TA), (alg, Const); atol, rtol, fdm) |
| 31 | + test_reverse(project_hermitian!, RT, (A, TA), (B, TA), (alg, Const); atol, rtol, fdm) |
| 32 | + end |
| 33 | +end |
| 34 | + |
| 35 | +""" |
| 36 | + test_enzyme_project_antihermitian(T, sz; rng, atol, rtol) |
| 37 | +
|
| 38 | +Test the Enzyme reverse-mode AD rule for `project_antihermitian` and its in-place variant. |
| 39 | +""" |
| 40 | +function test_enzyme_project_antihermitian( |
| 41 | + T, sz; |
| 42 | + rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T), |
| 43 | + fdm = enzyme_fdm(T) |
| 44 | + ) |
| 45 | + return @testset "project_antihermitian" begin |
| 46 | + A = instantiate_matrix(T, sz) |
| 47 | + B = instantiate_matrix(T, sz) |
| 48 | + alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) |
| 49 | + test_reverse(project_antihermitian, RT, (A, TA), (alg, Const); atol, rtol, fdm) |
| 50 | + test_reverse(project_antihermitian!, RT, (A, TA), (A, TA), (alg, Const); atol, rtol, fdm) |
| 51 | + test_reverse(project_antihermitian!, RT, (A, TA), (B, TA), (alg, Const); atol, rtol, fdm) |
| 52 | + end |
| 53 | +end |
0 commit comments