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

Adding rtol and atol for pinv and nullspace #29998

Merged
merged 12 commits into from
Dec 11, 2018
Prev Previous commit
Next Next commit
add news.md item
  • Loading branch information
sam0410 committed Dec 7, 2018
commit 3e28425462524547705fb5760974a734f4b679f5
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Deprecated or removed
replaced with just the argument `T` ([#29739]).
* `peakflops` has been scheduled to move from `InteractiveUtils` to `LinearAlgebra`
but is already now available as `LinearAlgebra.peakflops` ([#29978]).
* Only keyword arguments `rtol`, `atol` will be accepted by `pinv`, `nullspace` and `rank` ([#29998], [#29926]).

<!--- generated by NEWS-update.jl: -->
[#21233]: https://github.com/JuliaLang/julia/issues/21233
Expand Down
14 changes: 2 additions & 12 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ factorize(A::Transpose) = transpose(factorize(parent(A)))

"""
pinv(M; atol::Real, rtol::Real)
pinv(M[, tol::Real]) = pinv(M, rtol=tol)
pinv(M, rtol::Real) = pinv(M; rtol=rtol) # to be deprecated in Julia 2.0

Computes the Moore-Penrose pseudoinverse.

Expand Down Expand Up @@ -1312,7 +1312,6 @@ function pinv(A::AbstractMatrix{T}; atol::Real = 0.0, rtol::Real = (eps(real(flo
Sinv[findall(.!isfinite.(Sinv))] .= zero(Stype)
return SVD.Vt' * (Diagonal(Sinv) * SVD.U')
end
pinv(A::AbstractMatrix{T}, tol::Real) where T = pinv(A, rtol=tol) # TODO: deprecate tol in 2.0
function pinv(x::Number)
xi = inv(x)
return ifelse(isfinite(xi), xi, zero(xi))
Expand All @@ -1322,7 +1321,7 @@ end

"""
nullspace(M; atol::Real, rtol::Real)
nullspace(M[, tol::Real]) = nullspace(M, rtol=tol)
nullspace(M, rtol::Real) = nullspace(M; rtol=rtol) # to be deprecated in Julia 2.0

Computes a basis for the nullspace of `M` by including the singular
vectors of A whose singular have magnitude are greater than `max(atol, rtol*σ₁)`,
Expand All @@ -1344,12 +1343,6 @@ julia> nullspace(M)
0.0
1.0

julia> nullspace(M, 2)
3×3 Array{Float64,2}:
0.0 1.0 0.0
1.0 0.0 0.0
0.0 0.0 1.0

julia> nullspace(M, rtol=3)
3×3 Array{Float64,2}:
0.0 1.0 0.0
Expand All @@ -1371,12 +1364,9 @@ function nullspace(A::AbstractMatrix; atol::Real = 0.0, rtol::Real = (min(size(A
indstart = sum(s -> s .> tol, SVD.S) + 1
return copy(SVD.Vt[indstart:end,:]')
end
nullspace(A::AbstractMatrix, tol::Real) = nullspace(A, rtol=tol) # TODO: deprecate tol in 2.0

nullspace(A::AbstractVector; atol::Real = 0.0, rtol::Real = (min(size(A)...)*eps(real(float(one(eltype(A))))))*iszero(atol)) = nullspace(reshape(A, length(A), 1), rtol= rtol, atol= atol)

nullspace(A::AbstractVector, tol::Real) = nullspace(reshape(A, length(A), 1), rtol= tol) # TODO: deprecate tol in 2.0

"""
cond(M, p::Real=2)

Expand Down
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# To be deprecated in 2.0
rank(A::AbstractMatrix, tol::Real) = rank(A,rtol=tol)
nullspace(A::AbstractVector, tol::Real) = nullspace(reshape(A, length(A), 1), rtol= tol)
nullspace(A::AbstractMatrix, tol::Real) = nullspace(A, rtol=tol)
pinv(A::AbstractMatrix{T}, tol::Real) where T = pinv(A, rtol=tol)