Skip to content

Commit

Permalink
Fix orientation of right vectors in svds (#19974)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jan 13, 2017
1 parent fd14951 commit dd6ceff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,12 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite
# calculating singular vectors
left_sv = sqrt(2) * ex[2][ 1:size(X,1), ind ] .* sign(ex[1][ind]')
right_sv = sqrt(2) * ex[2][ size(X,1)+1:end, ind ]
return (SVD(left_sv, sval, right_sv), ex[3], ex[4], ex[5], ex[6])
return (SVD(left_sv, sval, right_sv'), ex[3], ex[4], ex[5], ex[6])
else
#The sort is necessary to work around #10329
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])
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])
end
end
4 changes: 2 additions & 2 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ end
@test s1_left s2_left

## 1st right singular vector
s1_right = sign(S1[1][:Vt][3,1]) * S1[1][:Vt][:,1]
s1_right = sign(S1[1][:V][3,1]) * S1[1][:V][:,1]
s2_right = sign(S2[3][3,1]) * S2[3][:,1]
@test s1_right s2_right
end
Expand Down Expand Up @@ -212,7 +212,7 @@ end
@test s1_left s2_left

## right singular vectors
s1_right = abs.(S1[1][:Vt][:,1:2])
s1_right = abs.(S1[1][:V][:,1:2])
s2_right = abs.(S2[3][:,1:2])
@test s1_right s2_right
end
Expand Down

0 comments on commit dd6ceff

Please sign in to comment.