Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial svds support based on eigs #9425

Merged
merged 9 commits into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed extra spaces, added ritzvec param to svds
  • Loading branch information
jaak-s committed Dec 21, 2014
commit 8b061df9c4275fca72562d64f6b364e4376e473e
16 changes: 9 additions & 7 deletions base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ end
size(s::SvdX) = size(s.X, 2), size(s.X, 2)
issym(s::SvdX) = true

function svds(X; args...)
ex = eigs(SvdX(X), I; args...)
## calculating left-side singular vectors
left_sv = X * ex[2]
return left_sv ./ sqrt(sum(left_sv.^2, 1)), sqrt(ex[1]), ex[2], ex[3], ex[4], ex[5], ex[6]
end

function svds(X; ritzvec::Bool = true, args...)
ex = eigs(SvdX(X), I; ritzvec = ritzvec, args...)
if ! ritzvec
return sqrt(ex[1]), ex[2], ex[3], ex[4], ex[5]
end

## calculating left-side singular vectors
left_sv = X * ex[2]
return left_sv ./ sqrt(sum(left_sv.^2, 1)), sqrt(ex[1]), ex[2], ex[3], ex[4], ex[5], ex[6]
end
4 changes: 2 additions & 2 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ let # svds test
## singular values match:
@test_approx_eq S1[2] S2[2][1:2]

## 1st left singular vector
## 1st left singular vector
s1_left = sign(S1[1][3,1]) * S1[1][:,1]
s2_left = sign(S2[1][3,1]) * S2[1][:,1]
@test_approx_eq s1_left s2_left

## 1st right singular vector
## 1st right singular vector
s1_right = sign(S1[3][3,1]) * S1[3][:,1]
s2_right = sign(S2[3][3,1]) * S2[3][:,1]
@test_approx_eq s1_right s2_right
Expand Down