diff --git a/stdlib/LinearAlgebra/src/svd.jl b/stdlib/LinearAlgebra/src/svd.jl index 2a49512eeb2ec..61e12a1a5945f 100644 --- a/stdlib/LinearAlgebra/src/svd.jl +++ b/stdlib/LinearAlgebra/src/svd.jl @@ -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 diff --git a/stdlib/LinearAlgebra/test/svd.jl b/stdlib/LinearAlgebra/test/svd.jl index 4b475237e5b5e..c7586c89a77ae 100644 --- a/stdlib/LinearAlgebra/test/svd.jl +++ b/stdlib/LinearAlgebra/test/svd.jl @@ -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