Skip to content

Commit

Permalink
Fix inverse of SVD of complex matrix (#34872)
Browse files Browse the repository at this point in the history
Closes #34866
  • Loading branch information
carstenbauer authored Mar 2, 2020
1 parent 923d84b commit f709331
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function inv(F::SVD{T}) where T
@inbounds for i in eachindex(F.S)
iszero(F.S[i]) && throw(SingularException(i))
end
k = searchsortedlast(F.S, eps(T)*F.S[1], rev=true)
k = searchsortedlast(F.S, eps(real(T))*F.S[1], rev=true)
@views (F.S[1:k] .\ F.Vt[1:k, :])' * F.U[:,1:k]'
end

Expand Down
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/test/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, QRPivoted
@test inv(svd([1 2; 3 4])) [-2.0 1.0; 1.5 -0.5]
@test inv(svd([1 0 1; 0 1 0])) [0.5 0.0; 0.0 1.0; 0.5 0.0]
@test_throws SingularException inv(svd([0 0; 0 0]))
@test inv(svd([1+2im 3+4im; 5+6im 7+8im])) [-0.5 + 0.4375im 0.25 - 0.1875im; 0.375 - 0.3125im -0.125 + 0.0625im]
end

n = 10
Expand Down

0 comments on commit f709331

Please sign in to comment.