@@ -244,36 +244,34 @@ function svd_trunc_pullback!(
244244 minS = @view S[end : end ]
245245 AP ./= minS
246246 S⁻¹ = minS ./ S
247+ # sum the series on the smaller side only, the other side follows from Yᴴ = Y₀ᴴ + S⁻¹ X' AP;
248+ # for m > n, work with the adjoint problem, which swaps X and Yᴴ
249+ m > n && ((AP, X₀, Y₀ᴴ) = (AP' , Y₀ᴴ' , X₀' ))
247250 X₁ = rmul! (AP * Y₀ᴴ' , Diagonal (S⁻¹))
248251 X₁ .+ = X₀
249- Y₁ᴴ = lmul! (Diagonal (S⁻¹), X₀' * AP)
250- Y₁ᴴ .+ = Y₀ᴴ
251- Xₖ, Xₖ₊₁ = X₁, X₀
252- Yₖᴴ, Yₖ₊₁ᴴ = Y₁ᴴ, Y₀ᴴ
253- APAᴴₖ, AᴴPAₖ = AP * AP' , AP' * AP
254- APAᴴₖ₊₁, AᴴPAₖ₊₁ = zero (APAᴴₖ), zero (AᴴPAₖ)
255- S⁻¹ₖ, S⁻¹ₖ₊₁ = S⁻¹ .^ 2 , S⁻¹
252+ Xₖ, Xₖ₊₁ = X₁, zero (X₁)
253+ APAᴴₖ = AP * AP'
254+ APAᴴₖ₊₁ = zero (APAᴴₖ)
255+ S⁻¹ₖ, S⁻¹ₖ₊₁ = S⁻¹ .^ 2 , zero (S⁻¹)
256256 for k in 1 : maxiter
257257 Xₖ₊₁ = rmul! (mul! (Xₖ₊₁, APAᴴₖ, Xₖ), Diagonal (S⁻¹ₖ))
258- Yₖ₊₁ᴴ = lmul! (Diagonal (S⁻¹ₖ), mul! (Yₖ₊₁ᴴ, Yₖᴴ, AᴴPAₖ))
259- if norm (Xₖ₊₁, Inf ) < degeneracy_atol && norm (Yₖ₊₁ᴴ, Inf ) < degeneracy_atol
258+ if norm (Xₖ₊₁, Inf ) < degeneracy_atol
260259 break
261260 end
262261 Xₖ₊₁ .+ = Xₖ
263- Yₖ₊₁ᴴ .+ = Yₖᴴ
264262 if k == maxiter
265- @warn " Sylvester iteration did not converge after $k iterations, final norms of X: $(norm (Xₖ₊₁, Inf )) , Yᴴ: $( norm (Yₖ₊₁ᴴ , Inf )) )"
263+ @warn " Sylvester iteration did not converge after $k iterations, final norm of X: $(norm (Xₖ₊₁, Inf )) )"
266264 break
267265 end
268266 S⁻¹ₖ₊₁ .= S⁻¹ₖ .^ 2
269267 APAᴴₖ₊₁ = mul! (APAᴴₖ₊₁, APAᴴₖ, APAᴴₖ)
270- AᴴPAₖ₊₁ = mul! (AᴴPAₖ₊₁, AᴴPAₖ, AᴴPAₖ)
271268 Xₖ, Xₖ₊₁ = Xₖ₊₁, Xₖ
272- Yₖᴴ, Yₖ₊₁ᴴ = Yₖ₊₁ᴴ, Yₖᴴ
273269 APAᴴₖ, APAᴴₖ₊₁ = APAᴴₖ₊₁, APAᴴₖ
274- AᴴPAₖ, AᴴPAₖ₊₁ = AᴴPAₖ₊₁, AᴴPAₖ
275270 S⁻¹ₖ, S⁻¹ₖ₊₁ = S⁻¹ₖ₊₁, S⁻¹ₖ
276271 end
272+ Yₖᴴ = lmul! (Diagonal (S⁻¹), Xₖ' * AP)
273+ Yₖᴴ .+ = Y₀ᴴ
274+ m > n && ((Xₖ, Yₖᴴ) = (Yₖᴴ' , Xₖ' ))
277275 ΔA = mul! (ΔA, Xₖ, Vᴴ, 1 , 1 )
278276 ΔA = mul! (ΔA, U, Yₖᴴ, 1 , 1 )
279277 end
0 commit comments