Skip to content

Commit 219040e

Browse files
committed
simplify chainrules tests
1 parent 3e73c0c commit 219040e

2 files changed

Lines changed: 4 additions & 62 deletions

File tree

test/testsuite/ad_utils.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -537,27 +537,3 @@ function ad_right_null_setup(A)
537537
ΔNᴴ = randn!(similar(A, T, n - min(m, n), min(m, n))) * right_orth(A; alg = :lq)[2]
538538
return Nᴴ, ΔNᴴ
539539
end
540-
541-
function ad_project_hermitian_setup(A)
542-
m, n = size(A)
543-
T = eltype(A)
544-
Aₕ = project_hermitian(A)
545-
ΔAₕ = randn!(similar(A, T, m, n))
546-
return Aₕ, ΔAₕ
547-
end
548-
549-
function ad_project_antihermitian_setup(A)
550-
m, n = size(A)
551-
T = eltype(A)
552-
Aₐ = project_antihermitian(A)
553-
ΔAₐ = randn!(similar(A, T, m, n))
554-
return Aₐ, ΔAₐ
555-
end
556-
557-
function ad_project_isometric_setup(A)
558-
m, n = size(A)
559-
T = eltype(A)
560-
W = project_isometric(A)
561-
ΔW = randn!(similar(A, T, m, n))
562-
return W, ΔW
563-
end

test/testsuite/chainrules.jl

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ for f in
1010
:eig_trunc_no_error, :eigh_trunc_no_error,
1111
:svd_compact, :svd_trunc, :svd_trunc_no_error, :svd_vals,
1212
:left_polar, :right_polar,
13-
:project_hermitian, :project_antihermitian, :project_isometric,
1413
)
1514
copy_f = Symbol(:cr_copy_, f)
1615
f! = Symbol(f, '!')
@@ -599,47 +598,14 @@ function test_chainrules_projections(
599598
return @testset "Projections Chainrules AD rules $summary_str" begin
600599
A = instantiate_matrix(T, sz)
601600
m, n = size(A)
602-
config = Zygote.ZygoteRuleConfig()
603601
if m == n
604-
alg_h = MatrixAlgebraKit.default_hermitian_algorithm(A)
605602
@testset "project_hermitian" begin
606-
Aₕ, ΔAₕ = ad_project_hermitian_setup(A)
607-
test_rrule(
608-
cr_copy_project_hermitian, A, alg_h NoTangent();
609-
output_tangent = ΔAₕ, atol = atol, rtol = rtol
610-
)
611-
test_rrule(
612-
config, project_hermitian, A;
613-
output_tangent = ΔAₕ,
614-
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
615-
)
603+
alg = MatrixAlgebraKit.default_hermitian_algorithm(A)
604+
test_rrule(project_hermitian, A, alg; atol, rtol)
616605
end
617606
@testset "project_antihermitian" begin
618-
Aₐ, ΔAₐ = ad_project_antihermitian_setup(A)
619-
test_rrule(
620-
cr_copy_project_antihermitian, A, alg_h NoTangent();
621-
output_tangent = ΔAₐ, atol = atol, rtol = rtol
622-
)
623-
test_rrule(
624-
config, project_antihermitian, A;
625-
output_tangent = ΔAₐ,
626-
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
627-
)
628-
end
629-
end
630-
if m > n
631-
@testset "project_isometric" begin
632-
W, ΔW = ad_project_isometric_setup(A)
633-
alg_iso = MatrixAlgebraKit.default_polar_algorithm(A)
634-
test_rrule(
635-
cr_copy_project_isometric, A, alg_iso NoTangent();
636-
output_tangent = ΔW, atol = atol, rtol = rtol
637-
)
638-
test_rrule(
639-
config, project_isometric, A;
640-
output_tangent = ΔW,
641-
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
642-
)
607+
alg = MatrixAlgebraKit.default_hermitian_algorithm(A)
608+
test_rrule(project_antihermitian, A, alg; atol, rtol)
643609
end
644610
end
645611
end

0 commit comments

Comments
 (0)