Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 4 additions & 4 deletions src/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ function svd_rev(USV::SVD, Ū, s̄, V̄)
Ut = U'
FUᵀŪ = _mulsubtrans!!(Ut*Ū, F) # F .* (UᵀŪ - ŪᵀU)
FVᵀV̄ = _mulsubtrans!!(Vt*V̄, F) # F .* (VᵀV̄ - V̄ᵀV)
ImUUᵀ = _eyesubx!(U*Ut) # I - UUᵀ
ImVVᵀ = _eyesubx!(V*Vt) # I - VVᵀ

S = Diagonal(s)
S̄ = s̄ isa AbstractZero ? s̄ : Diagonal(s̄)

# TODO: consider using MuladdMacro here
Ā = add!!(U * FUᵀŪ * S, ImUUᵀ * (Ū / S)) * Vt
Ūs = Ū / S
V̄ts = S \ V̄'
Ā = add!!(U * FUᵀŪ * S, Ūs - U * (Ut * Ūs)) * Vt
Ā = add!!(Ā, U * S̄ * Vt)
Ā = add!!(Ā, U * add!!(S * FVᵀV̄ * Vt, (S \ V̄') * ImVVᵀ))
Ā = add!!(Ā, U * add!!(S * FVᵀV̄ * Vt, V̄ts - (V̄ts * V) * Vt))

return Ā
end
Expand Down
9 changes: 0 additions & 9 deletions src/rulesets/LinearAlgebra/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ _mulsubtrans!!(X::AbstractZero, F::AbstractZero) = X
_mulsubtrans!!(X::AbstractZero, F::AbstractMatrix{<:Real}) = X
_mulsubtrans!!(X::AbstractMatrix{<:Real}, F::AbstractZero) = F

# I - X, overwrites X
function _eyesubx!(X::AbstractMatrix)
n, m = size(X)
@inbounds for j = 1:m, i = 1:n
X[i,j] = (i == j) - X[i,j]
end
return X
end

_extract_imag(x) = complex(0, imag(x))

"""
Expand Down
1 change: 0 additions & 1 deletion test/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ end
X = randn(10, 10)
Y = randn(10, 10)
@test ChainRules._mulsubtrans!!(copy(X), Y) ≈ Y .* (X - X')
@test ChainRules._eyesubx!(copy(X)) ≈ I - X

Z = randn(Float32, 10, 10)
result = ChainRules._mulsubtrans!!(copy(Z), Y)
Expand Down