Skip to content

Commit 19c08e1

Browse files
committed
Make user the initial vector defaults to a float type and avoid using
eltype(A) if possible. Fixes #9
1 parent 79baa0d commit 19c08e1

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/TSVD.jl

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Copyright 2015-2018 Andreas Noack
2+
3+
__precompile__()
4+
25
module TSVD
36

47
export tsvd

src/svd.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function biLanczosIterations(A, stepsize, αs, βs, U, V, μs, νs, τ, reorth_i
55
nReorth = 0
66
nReorthVecs = 0
77

8-
T = eltype(A)
8+
T = eltype(eltype(U))
99
Tr = real(T)
1010

1111
maxνs = Tr[]
@@ -112,7 +112,7 @@ end
112112
function _tsvd(A,
113113
nvals = 1;
114114
maxiter = 1000,
115-
initvec = convert(Vector{eltype(A)}, randn(size(A,1))),
115+
initvec = convert(Vector{float(eltype(A))}, randn(size(A,1))),
116116
tolconv = sqrt(eps(real(eltype(initvec)))),
117117
tolreorth = sqrt(eps(real(eltype(initvec)))),
118118
stepsize = max(1, div(nvals, 10)),
@@ -330,7 +330,7 @@ julia> s
330330
tsvd(A,
331331
nvals = 1;
332332
maxiter = 1000,
333-
initvec = convert(Vector{eltype(A)}, randn(size(A,1))),
333+
initvec = convert(Vector{float(eltype(A))}, randn(size(A,1))),
334334
tolconv = sqrt(eps(real(eltype(initvec)))),
335335
tolreorth = sqrt(eps(real(eltype(initvec)))),
336336
stepsize = max(1, div(nvals, 10)),
@@ -378,7 +378,7 @@ end
378378

379379
function tsvd2(A,
380380
nvals = 1;
381-
maxiter = minimum(size(A)),
381+
maxiter = min(size(A)...),
382382
initvec = convert(Vector{eltype(A)}, randn(size(A,2))),
383383
tolconv = sqrt(eps(real(eltype(A)))),
384384
stepsize = max(1, div(nvals, 10)),

test/runtests.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using TSVD
22
using Base.Test
33

4-
for (m, n, p) = ((10, 6, 0.8), (100, 60, 0.1))
4+
@testset "test tsvd with m = $m, n = $n, and p = $p" for (m, n, p) = ((10, 6, 0.8), (100, 60, 0.1))
55
mnp = round(Integer, m*n*p)
66

77
for A in (randn(m, n),
@@ -25,3 +25,8 @@ for (m, n, p) = ((10, 6, 0.8), (100, 60, 0.1))
2525
end
2626
end
2727
end
28+
29+
@testset "Issue 9" begin
30+
data = rand(1:100, 50, 50)
31+
TSVD.tsvd(data,2)
32+
end

0 commit comments

Comments
 (0)