Skip to content

Commit 2ddab59

Browse files
committed
Fixes for enzyme + SVD
1 parent f99f9db commit 2ddab59

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/factorizations/pushforwards.jl‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function MAK.svd_vals_pushforward!(
4141
return MAK.svd_vals_pushforward!(Δt, t, (USVᴴ[1], MAK.diagonal(parent(USVᴴ[2])), USVᴴ[3]), ΔS, ind; kwargs...)
4242
end
4343

44-
for pushforward! in (:svd_pushforward!, :eig_pushforward!, :eigh_pushforward!)
44+
for pushforward! in (:eig_pushforward!, :eigh_pushforward!)
4545
@eval function MAK.$pushforward!(
4646
Δt::AbstractTensorMap, t, F, ΔF;
4747
kwargs...
@@ -55,3 +55,17 @@ for pushforward! in (:svd_pushforward!, :eig_pushforward!, :eigh_pushforward!)
5555
return Δt
5656
end
5757
end
58+
function MAK.svd_pushforward!(
59+
Δt::AbstractTensorMap, t, F, ΔF, inds = Colon();
60+
kwargs...
61+
)
62+
foreachblock(Δt, t) do c, (Δb, b)
63+
ind = (inds isa Colon) ? inds : get(inds, c, nothing)
64+
isnothing(ind) && return nothing
65+
Fc = nothing_or_block.(F, Ref(c))
66+
ΔFc = nothing_or_block.(ΔF, Ref(c))
67+
MAK.svd_pushforward!(Δb, b, Fc, ΔFc, ind; kwargs...)
68+
return nothing
69+
end
70+
return Δt
71+
end

‎test/enzyme/svd.jl‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ eltypes = (Float64, ComplexF64)
2323
ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)
2424
remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...)
2525
EnzymeTestUtils.test_reverse(svd_full, Duplicated, (t, Duplicated); output_tangent = ΔUSVᴴ, atol, rtol)
26-
EnzymeTestUtils.test_forward(svd_full, Duplicated, (t, Duplicated); atol, rtol)
26+
# finite differences check for the gauge-dependent extra columns/rows is unreliable
27+
if all(((c, b),) -> size(b, 1) == size(b, 2), blocks(t))
28+
EnzymeTestUtils.test_forward(svd_full, Duplicated, (t, Duplicated); atol, rtol)
29+
end
2730

2831
USVᴴ = svd_compact(t)
2932
ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)

0 commit comments

Comments
 (0)