@@ -244,36 +244,25 @@ 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₀' ))
250- X₁ = rmul! (AP * Y₀ᴴ' , Diagonal (S⁻¹))
251- X₁ .+ = X₀
252- Xₖ, Xₖ₊₁ = X₁, X₀
253- APAᴴₖ = AP * AP'
254- APAᴴₖ₊₁ = zero (APAᴴₖ)
255- S⁻¹ₖ, S⁻¹ₖ₊₁ = S⁻¹ .^ 2 , zero (S⁻¹)
256- for k in 1 : maxiter
257- Xₖ₊₁ = rmul! (mul! (Xₖ₊₁, APAᴴₖ, Xₖ), Diagonal (S⁻¹ₖ))
258- if norm (Xₖ₊₁, Inf ) < degeneracy_atol
259- break
260- end
261- Xₖ₊₁ .+ = Xₖ
262- if k == maxiter
263- @warn " Sylvester iteration did not converge after $k iterations, final norm of X: $(maximum (abs, Xₖ₊₁)) "
264- break
265- end
266- S⁻¹ₖ₊₁ .= S⁻¹ₖ .^ 2
267- APAᴴₖ₊₁ = mul! (APAᴴₖ₊₁, APAᴴₖ, APAᴴₖ)
268- Xₖ, Xₖ₊₁ = Xₖ₊₁, Xₖ
269- APAᴴₖ, APAᴴₖ₊₁ = APAᴴₖ₊₁, APAᴴₖ
270- S⁻¹ₖ, S⁻¹ₖ₊₁ = S⁻¹ₖ₊₁, S⁻¹ₖ
247+ # sum the series on the smaller side only, the other side follows from
248+ # Yᴴ = Y₀ᴴ + S⁻¹ X' AP (m ≤ n) or X = X₀ + AP Y S⁻¹ (m > n)
249+ if m ≤ n
250+ X = rmul! (AP * Y₀ᴴ' , Diagonal (S⁻¹))
251+ X .+ = X₀
252+ X = _smith_iteration! (X, X₀, AP * AP' , S⁻¹ .^ 2 , degeneracy_atol, maxiter) # recycle X₀
253+ Yᴴ = lmul! (Diagonal (S⁻¹), X' * AP)
254+ Yᴴ .+ = Y₀ᴴ
255+ ΔA = mul! (ΔA, X, Vᴴ, 1 , 1 )
256+ ΔA = mul! (ΔA, U, Yᴴ, 1 , 1 )
257+ else
258+ Y = rmul! (AP' * X₀, Diagonal (S⁻¹))
259+ Y .+ = Y₀ᴴ'
260+ Y = _smith_iteration! (Y, similar (Y), AP' * AP, S⁻¹ .^ 2 , degeneracy_atol, maxiter)
261+ X = rmul! (AP * Y, Diagonal (S⁻¹))
262+ X .+ = X₀
263+ ΔA = mul! (ΔA, X, Vᴴ, 1 , 1 )
264+ ΔA = mul! (ΔA, U, Y' , 1 , 1 )
271265 end
272- Yₖᴴ = lmul! (Diagonal (S⁻¹), Xₖ' * AP)
273- Yₖᴴ .+ = Y₀ᴴ
274- m > n && ((Xₖ, Yₖᴴ) = (Yₖᴴ' , Xₖ' ))
275- ΔA = mul! (ΔA, Xₖ, Vᴴ, 1 , 1 )
276- ΔA = mul! (ΔA, U, Yₖᴴ, 1 , 1 )
277266 end
278267 return ΔA
279268end
0 commit comments