Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient projection in svd pullback #755

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Re-write svd_rev to avoid a matrix multiplication
perrutquist committed Dec 4, 2023
commit ef235e15fd6d3c61248a7bd3581033c193c313a5
15 changes: 6 additions & 9 deletions src/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
@@ -263,15 +263,12 @@ function svd_rev(USV::SVD, Ū, s̄, V̄t)
S = Diagonal(s)
S̄ = s̄ isa AbstractZero ? s̄ : Diagonal(s̄)

Ā = U * (FUᵀŪS + S̄ + SFVᵀV̄) * Vt

# TODO: consider using MuladdMacro here
if size(U,1) > size(U,2)
Ā = add!!(Ā, ((Ū .- U * UtŪ) / S) * Vt)
end

if size(Vt,2) > size(Vt,1)
Ā = add!!(Ā, U * (S \ (V̄t .- V̄tV * Vt)))
if size(Vt,1) == size(Vt,2)
# V is square, VVᵀ = I and therefore V̄ᵀ - V̄ᵀVVᵀ = 0
Ā = (U * (FUᵀŪS + S̄ + SFVᵀV̄) + ((Ū .- U * UtŪ) / S)) * Vt
else
# If V is not square then U is, so UUᵀ == I and Ū - UUᵀŪ = 0
Ā = U * ((FUᵀŪS + S̄ + SFVᵀV̄) * Vt + (S \ (V̄t .- V̄tV * Vt)))
end

return Ā