Skip to content

Commit

Permalink
Remove boxing in pinv (#51351)
Browse files Browse the repository at this point in the history
As discussed in
https://discourse.julialang.org/t/pinv-not-type-stable/103885/14, the
`tol` variable is captured which leads to it being boxed, as suggested
can be fixed by having two separate variables.
  • Loading branch information
Zentrik committed Sep 18, 2023
1 parent 106e867 commit 8e21b21
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1483,10 +1483,10 @@ function pinv(A::AbstractMatrix{T}; atol::Real = 0.0, rtol::Real = (eps(real(flo
return B
end
SVD = svd(A)
tol = max(rtol*maximum(SVD.S), atol)
tol2 = max(rtol*maximum(SVD.S), atol)
Stype = eltype(SVD.S)
Sinv = fill!(similar(A, Stype, length(SVD.S)), 0)
index = SVD.S .> tol
index = SVD.S .> tol2
Sinv[index] .= pinv.(view(SVD.S, index))
return SVD.Vt' * (Diagonal(Sinv) * SVD.U')
end
Expand Down

0 comments on commit 8e21b21

Please sign in to comment.