Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/factorizations/pushforwards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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
5 changes: 4 additions & 1 deletion test/enzyme/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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ᴴ)
Expand Down
Loading