Skip to content

Commit ec09e25

Browse files
authored
tolerate atol and rtol kwargs from LinearAlgebra 1.13 (#160)
* tolerate atol and rtol kwargs from LinearAlgebra 1.13 * imitate behaviour of LinearAlgebra
1 parent b87fd55 commit ec09e25

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/svd.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ function LinearAlgebra.svd!(
639639
# To avoid breaking on <Julia 1.3, the `alg` keyword doesn't do anything. Once we drop support for Julia 1.2
640640
# and below, we can make the keyword argument work correctly
641641
alg = nothing,
642+
atol = 0,
643+
rtol = 0
642644
) where {T}
643645

644646
m, n = size(A)
@@ -660,6 +662,13 @@ function LinearAlgebra.svd!(
660662
rmul!(Vᴴ, BF.rightQ')
661663

662664
s = F.S
665+
s[_count_svdvals(s, atol, rtol)+1:end] .= 0
663666

664667
return SVD(U, s, Vᴴ)
665668
end
669+
670+
function _count_svdvals(S, atol::Real, rtol::Real)
671+
isempty(S) && return 0
672+
tol = max(rtol * S[1], atol)
673+
return iszero(S[1]) ? 0 : searchsortedlast(S, tol, rev=true)
674+
end

0 commit comments

Comments
 (0)