Skip to content

Commit bc746a2

Browse files
authored
Fix subproblem detection. (#82)
* Fix subproblem detection. Closes #81 * Some debug info * Fix computation of first Givens rotation in SVD when n1>1.
1 parent 9f9b46f commit bc746a2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/svd.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function svdIter!(B::Bidiagonal{T}, n1, n2, shift, U = nothing, Vᴴ = nothing)
2424
d = B.dv
2525
e = B.ev
2626

27-
G, r = givens(d[n1] - abs2(shift)/d[n1], e[n1], 1, 2)
27+
G, r = givens(d[n1] - abs2(shift)/d[n1], e[n1], n1, n1 + 1)
2828
lmul!(G, Vᴴ)
2929

3030
ditmp = d[n1]
@@ -155,16 +155,16 @@ function __svd!(B::Bidiagonal{T}, U = nothing, Vᴴ = nothing; tol = 100eps(T),
155155

156156
# Search for largest sub-bidiagonal matrix ending at n2
157157
for _n1 = (n2 - 1):-1:1
158-
if abs(e[_n1]) < thresh
158+
if _n1 == 1
159159
n1 = _n1
160160
break
161-
elseif _n1 == 1
161+
elseif abs(e[_n1 - 1]) < thresh
162162
n1 = _n1
163163
break
164164
end
165165
end
166166

167-
debug && println("n1=", n1, ", n2=", n2, ", d[n1]=", d[n1], ", d[n2]=", d[n2], ", e[n1]=", e[n1], " e[n2]=", e[n2-1], " thresh=", thresh)
167+
debug && println("n1=", n1, ", n2=", n2, ", d[n1]=", d[n1], ", d[n2]=", d[n2], ", e[n1]=", e[n1], " e[n2-1]=", e[n2-1], " thresh=", thresh)
168168

169169

170170
# See LAWN 3 p 18 and

test/svd.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
1919

2020
F = svd(A)
2121
@test vals F.S
22+
@show norm(F.U'*A*F.V - Diagonal(F.S), Inf)
2223
@test F.U'*A*F.V Diagonal(F.S)
2324
end
2425

@@ -70,4 +71,9 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
7071
@test abs.(FA.V'*Float64.(FAb.V)) I
7172
@test abs.(FA.V'*Float64.(FAtb.U)) I
7273
end
74+
75+
@testset "Issue 81" begin
76+
m = [1 0 0 0; 0 2 1 0; 0 1 2 0; 0 0 0 -1]
77+
@test Float64.(svdvals(big.(m))) svdvals(m)
78+
end
7379
end

0 commit comments

Comments
 (0)