|
| 1 | +""" |
| 2 | + test_mooncake_projections(T, sz; kwargs...) |
| 3 | +
|
| 4 | +Run all Mooncake AD tests for hermitian and anti-hermitian projections of element type `T` |
| 5 | +and size `sz`. |
| 6 | +""" |
| 7 | +function test_mooncake_projections(T::Type, sz; kwargs...) |
| 8 | + summary_str = testargs_summary(T, sz) |
| 9 | + return @testset "Mooncake projection $summary_str" begin |
| 10 | + test_mooncake_project_hermitian(T, sz; kwargs...) |
| 11 | + test_mooncake_project_antihermitian(T, sz; kwargs...) |
| 12 | + end |
| 13 | +end |
| 14 | + |
| 15 | +""" |
| 16 | + test_mooncake_project_hermitian(T, sz; rng, atol, rtol) |
| 17 | +
|
| 18 | +Test the Mooncake reverse-mode AD rule for `project_hermitian` and its in-place variant. |
| 19 | +""" |
| 20 | +function test_mooncake_project_hermitian( |
| 21 | + T, sz; |
| 22 | + rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T) |
| 23 | + ) |
| 24 | + return @testset "project_hermitian" begin |
| 25 | + A = instantiate_matrix(T, sz) |
| 26 | + B = instantiate_matrix(T, sz) |
| 27 | + alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) |
| 28 | + Mooncake.TestUtils.test_rule( |
| 29 | + rng, project_hermitian, A, alg; |
| 30 | + mode = Mooncake.ReverseMode, atol, rtol |
| 31 | + ) |
| 32 | + Mooncake.TestUtils.test_rule( |
| 33 | + rng, project_hermitian!, A, A, alg; |
| 34 | + mode = Mooncake.ReverseMode, atol, rtol |
| 35 | + ) |
| 36 | + Mooncake.TestUtils.test_rule( |
| 37 | + rng, project_hermitian!, A, B, alg; |
| 38 | + mode = Mooncake.ReverseMode, atol, rtol |
| 39 | + ) |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +""" |
| 44 | + test_mooncake_project_antihermitian(T, sz; rng, atol, rtol) |
| 45 | +
|
| 46 | +Test the Mooncake reverse-mode AD rule for `project_antihermitian` and its in-place variant. |
| 47 | +""" |
| 48 | +function test_mooncake_project_antihermitian( |
| 49 | + T, sz; |
| 50 | + rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T) |
| 51 | + ) |
| 52 | + return @testset "project_antihermitian" begin |
| 53 | + A = instantiate_matrix(T, sz) |
| 54 | + B = instantiate_matrix(T, sz) |
| 55 | + alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) |
| 56 | + Mooncake.TestUtils.test_rule( |
| 57 | + rng, project_antihermitian, A, alg; |
| 58 | + mode = Mooncake.ReverseMode, atol, rtol |
| 59 | + ) |
| 60 | + Mooncake.TestUtils.test_rule( |
| 61 | + rng, project_antihermitian!, A, A, alg; |
| 62 | + mode = Mooncake.ReverseMode, atol, rtol |
| 63 | + ) |
| 64 | + Mooncake.TestUtils.test_rule( |
| 65 | + rng, project_antihermitian!, A, B, alg; |
| 66 | + mode = Mooncake.ReverseMode, atol, rtol |
| 67 | + ) |
| 68 | + end |
| 69 | +end |
0 commit comments