diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 7a7aea2deff3c..afe697a761e52 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -891,7 +891,6 @@ function pinv(A::StridedMatrix{T}) where T tol = eps(real(float(one(T))))*maximum(size(A)) return pinv(A, tol) end -pinv(a::StridedVector) = pinv(reshape(a, length(a), 1)) function pinv(x::Number) xi = inv(x) return ifelse(isfinite(xi), xi, zero(xi)) diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index 1666b8bf3f3d7..0da8517f8a536 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -795,6 +795,17 @@ function inv(A::AbstractMatrix{T}) where T A_ldiv_B!(factorize(convert(AbstractMatrix{S}, A)), eye(S0, checksquare(A))) end +function pinv(v::AbstractVector{T}, tol::Real=real(zero(T))) where T + res = similar(v, typeof(zero(T) / (abs2(one(T)) + abs2(one(T)))))' + den = sum(abs2, v) + if den <= tol^2 + fill!(res, zero(eltype(res))) + else + res .= v' ./ den + end + return res +end + """ \\(A, B)