Skip to content

Commit 4499295

Browse files
ZentrikKristofferC
authored andcommitted
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. (cherry picked from commit 8e21b21)
1 parent ddf7090 commit 4499295

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/LinearAlgebra/src/dense.jl

+2-2
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)