Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd4fe80

Browse files
ZentrikNHDaly
authored andcommittedSep 20, 2023
Remove boxing in pinv (#51351)
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.
1 parent ec24d5d commit dd4fe80

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

‎stdlib/LinearAlgebra/src/dense.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,10 @@ function pinv(A::AbstractMatrix{T}; atol::Real = 0.0, rtol::Real = (eps(real(flo
14831483
return B
14841484
end
14851485
SVD = svd(A)
1486-
tol = max(rtol*maximum(SVD.S), atol)
1486+
tol2 = max(rtol*maximum(SVD.S), atol)
14871487
Stype = eltype(SVD.S)
14881488
Sinv = fill!(similar(A, Stype, length(SVD.S)), 0)
1489-
index = SVD.S .> tol
1489+
index = SVD.S .> tol2
14901490
Sinv[index] .= pinv.(view(SVD.S, index))
14911491
return SVD.Vt' * (Diagonal(Sinv) * SVD.U')
14921492
end

0 commit comments

Comments
 (0)
Please sign in to comment.