diff --git a/src/factorizations/pushforwards.jl b/src/factorizations/pushforwards.jl index 38bcf2de9..6c07559cb 100644 --- a/src/factorizations/pushforwards.jl +++ b/src/factorizations/pushforwards.jl @@ -41,7 +41,7 @@ function MAK.svd_vals_pushforward!( return MAK.svd_vals_pushforward!(Δt, t, (USVᴴ[1], MAK.diagonal(parent(USVᴴ[2])), USVᴴ[3]), ΔS, ind; kwargs...) end -for pushforward! in (:svd_pushforward!, :eig_pushforward!, :eigh_pushforward!) +for pushforward! in (:eig_pushforward!, :eigh_pushforward!) @eval function MAK.$pushforward!( Δt::AbstractTensorMap, t, F, ΔF; kwargs... @@ -55,3 +55,17 @@ for pushforward! in (:svd_pushforward!, :eig_pushforward!, :eigh_pushforward!) return Δt end end +function MAK.svd_pushforward!( + Δt::AbstractTensorMap, t, F, ΔF, inds = Colon(); + kwargs... + ) + foreachblock(Δt, t) do c, (Δb, b) + ind = (inds isa Colon) ? inds : get(inds, c, nothing) + isnothing(ind) && return nothing + Fc = nothing_or_block.(F, Ref(c)) + ΔFc = nothing_or_block.(ΔF, Ref(c)) + MAK.svd_pushforward!(Δb, b, Fc, ΔFc, ind; kwargs...) + return nothing + end + return Δt +end diff --git a/test/enzyme/svd.jl b/test/enzyme/svd.jl index 482e93b73..e027f2cab 100644 --- a/test/enzyme/svd.jl +++ b/test/enzyme/svd.jl @@ -23,7 +23,10 @@ eltypes = (Float64, ComplexF64) ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ) remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...) EnzymeTestUtils.test_reverse(svd_full, Duplicated, (t, Duplicated); output_tangent = ΔUSVᴴ, atol, rtol) - EnzymeTestUtils.test_forward(svd_full, Duplicated, (t, Duplicated); atol, rtol) + # finite differences check for the gauge-dependent extra columns/rows is unreliable + if all(((c, b),) -> size(b, 1) == size(b, 2), blocks(t)) + EnzymeTestUtils.test_forward(svd_full, Duplicated, (t, Duplicated); atol, rtol) + end USVᴴ = svd_compact(t) ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)