Skip to content

Commit a74cf7b

Browse files
leburgelJutho
andcommitted
Update src/pullbacks/svd.jl
Co-authored-by: Jutho <Jutho@users.noreply.github.com>
1 parent 7022fb2 commit a74cf7b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎src/pullbacks/svd.jl‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@ function svd_pullback!(
178178

179179
# UᴴΔAV is nonzero only in its rows and columns ind′, which are UᴴΔAVₖ and UᴴΔAVʳ'. For k ≤ r / 2,
180180
# applying these two blocks directly, in O(m n k), is faster than forming UᴴΔAV.
181+
S′ = view(S, ind′)
182+
U′ = view(U, :, ind′)
183+
Vᴴ′ = view(Vᴴ, ind′, :) # this might be slightly confusion with adjoint
181184
if 2 * length(ind′) <= r
182185
UᴴΔAVʳ[ind′, :] .= zero(eltype(UᴴΔAVʳ)) # these entries are part of the columns ind′
183-
ΔA = mul!(ΔA, U₁ * UᴴΔAVₖ, Vᴴ[ind′, :], 1, 1)
184-
ΔA = mul!(ΔA, U[:, ind′], UᴴΔAVʳ' * V₁ᴴ, 1, 1)
186+
ΔA = mul!(ΔA, U₁ * UᴴΔAVₖ, Vᴴ′, 1, 1)
187+
ΔA = mul!(ΔA, U′, UᴴΔAVʳ' * V₁ᴴ, 1, 1)
185188
else
186189
if is_leading_index(ind′, r) # NOTE: all columns in order (e.g. `ind = Colon()`): the original path
187190
UᴴΔAV = UᴴΔAVₖ
@@ -195,12 +198,12 @@ function svd_pullback!(
195198

196199
# Add the remaining contributions
197200
if m > r && !iszerotangent(ΔU₊) # ΔU₁ is already orthogonal to U₁
198-
ΔU₊ ./= transpose(S[ind′])
199-
ΔA = mul!(ΔA, ΔU₊, Vᴴ[ind′, :], 1, 1)
201+
ΔU₊ ./= transpose(S′)
202+
ΔA = mul!(ΔA, ΔU₊, Vᴴ′, 1, 1)
200203
end
201204
if n > r && !iszerotangent(ΔV₊ᴴ) # ΔV₁ᴴ is already orthogonal to V₁ᴴ
202-
ΔV₊ᴴ .= S[ind′] .\ ΔV₊ᴴ
203-
ΔA = mul!(ΔA, U[:, ind′], ΔV₊ᴴ, 1, 1)
205+
ΔV₊ᴴ .= S′ .\ ΔV₊ᴴ
206+
ΔA = mul!(ΔA, U′, ΔV₊ᴴ, 1, 1)
204207
end
205208
return ΔA
206209
end

0 commit comments

Comments
 (0)