Skip to content

Commit dd6ceff

Browse files
authored
Fix orientation of right vectors in svds (#19974)
1 parent fd14951 commit dd6ceff

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

base/linalg/arnoldi.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,12 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite
388388
# calculating singular vectors
389389
left_sv = sqrt(2) * ex[2][ 1:size(X,1), ind ] .* sign(ex[1][ind]')
390390
right_sv = sqrt(2) * ex[2][ size(X,1)+1:end, ind ]
391-
return (SVD(left_sv, sval, right_sv), ex[3], ex[4], ex[5], ex[6])
391+
return (SVD(left_sv, sval, right_sv'), ex[3], ex[4], ex[5], ex[6])
392392
else
393393
#The sort is necessary to work around #10329
394-
return (SVD(zeros(eltype(sval),n,0),sort!(sval, by=real, rev=true),zeros(eltype(sval),0,m)), ex[2], ex[3], ex[4], ex[5])
394+
return (SVD(zeros(eltype(sval), n, 0),
395+
sort!(sval, by=real, rev=true),
396+
zeros(eltype(sval), 0, m)),
397+
ex[2], ex[3], ex[4], ex[5])
395398
end
396399
end

test/linalg/arnoldi.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ end
167167
@test s1_left s2_left
168168

169169
## 1st right singular vector
170-
s1_right = sign(S1[1][:Vt][3,1]) * S1[1][:Vt][:,1]
170+
s1_right = sign(S1[1][:V][3,1]) * S1[1][:V][:,1]
171171
s2_right = sign(S2[3][3,1]) * S2[3][:,1]
172172
@test s1_right s2_right
173173
end
@@ -212,7 +212,7 @@ end
212212
@test s1_left s2_left
213213

214214
## right singular vectors
215-
s1_right = abs.(S1[1][:Vt][:,1:2])
215+
s1_right = abs.(S1[1][:V][:,1:2])
216216
s2_right = abs.(S2[3][:,1:2])
217217
@test s1_right s2_right
218218
end

0 commit comments

Comments
 (0)