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
replaced getOperatorType to eltype
  • Loading branch information
jaak-s committed Jan 3, 2015
commit f8edd41cfe951a90060e1136189f1ae0d5deac1a
19 changes: 1 addition & 18 deletions base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,8 @@ end
size(s::SVDOperator) = s.m + s.n, s.m + s.n
issym(s::SVDOperator) = true

function getOperatorType(X)
et = eltype(X)
if et <: Integer || et <: Float64
return Float64
end
if et <: Complex64
return Complex64
end
if et <: Complex
return Complex128
end
if et <: Float32
return Float32
end
error("Element type $et is not supported for 'svds'.")
end

function svds{S}(X::S; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxiter::Int = 1000)
otype = getOperatorType(X)
otype = eltype(X)
ex = eigs(SVDOperator{otype,S}(X), I; ritzvec = ritzvec, nev = 2*nsv, tol = tol, maxiter = maxiter)
ind = [1:2:nsv*2]
sval = abs(ex[1][ind])
Expand Down
19 changes: 0 additions & 19 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@ let # svds test
@test_approx_eq s1_right s2_right
end

let # svd test with boolean matrix
B = [true true false; false true false; true false true; false true true]
S1 = svds(B, nsv = 2)
S2 = svd(B)

## singular values match:
@test_approx_eq S1[2] S2[2][1:2]

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

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

let # complex svds test
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp(im*[2.0:2:10]))
S1 = svds(A, nsv = 2)
Expand Down