Skip to content

Commit ba2e7e7

Browse files
committed
Move normalization inside doubling iteration
1 parent b562618 commit ba2e7e7

3 files changed

Lines changed: 4 additions & 11 deletions

File tree

‎src/common/pullbacks.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Solve `X = B + G * X * Diagonal(w)` by summing the Neumann series
4545
for at most `maxiter` steps.
4646
4747
On entry, `X` contains `B`, and it is overwritten with the result. `Xₙ` is used as a buffer,
48-
and `G` and `w` are overwritten. It is assumed that `w` is normalized such that
49-
`maximum(abs, w) == 1`, so that squaring it can only shrink it.
48+
and `G` and `w` are overwritten. `w` is normalized such that `maximum(abs, w) == 1`, so that
49+
squaring it can only shrink it; `G` is scaled by the inverse factor to compensate.
5050
5151
Reference: https://doi.org/10.1016/j.aml.2009.01.012.
5252
"""

‎src/pullbacks/eigh.jl‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ function eigh_trunc_pullback!(
153153
if !iszerotangent(ΔV₊)
154154
X₀ = rdiv!(ΔV₊, Diagonal(D))
155155
AP = mul!(copy(A), V * Dmat, V', -1, 1)
156-
# Normalize by the smallest retained |eigenvalue|, as `svd_trunc_pullback!` does
157-
# with `S[end]`. That caps `max|D⁻¹|` at 1, so squaring can only shrink it.
158-
dabsmin = minimum(abs, D)
159-
AP ./= dabsmin
160-
D⁻¹ = dabsmin ./ D
161-
X = accelerative_smith_iteration!(X₀, similar(X₀), AP, D⁻¹, degeneracy_atol, maxiter)
156+
X = accelerative_smith_iteration!(X₀, similar(X₀), AP, inv.(D), degeneracy_atol, maxiter)
162157
Z .+= X
163158
# we cannot directly multiply Z * V' into ΔA, because we have to
164159
# take the Hermitian part, and cannot apply project_hermitian! to

‎src/pullbacks/svd.jl‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ function svd_trunc_pullback!(
247247
Y₀ᴴ = iszerotangent(ΔV₊ᴴ) ? zero(Vᴴ) : ldiv!(Diagonal(S), ΔV₊ᴴ)
248248
US = mul!(ΔAV, U, Smat) # recycle ΔAV
249249
AP = mul!(copy(A), US, Vᴴ, -1, 1)
250-
minS = @view S[end:end]
251-
AP ./= minS
252-
S⁻¹ = minS ./ S
250+
S⁻¹ = inv.(S)
253251
# sum the series on the smaller side only, the other side follows from
254252
# Yᴴ = Y₀ᴴ + S⁻¹ X' AP (m ≤ n) or X = X₀ + AP Y S⁻¹ (m > n)
255253
if m ≤ n

0 commit comments

Comments
 (0)