@@ -5,7 +5,7 @@ function approximate_spectral_radius(A, tol = 0.01,
55 symmetric = false
66
77 # Initial guess
8- v0 = rand (eltype (A), size (A,1 ))
8+ v0 = rand (eltype (A), size (A,2 ))
99 maxiter = min (size (A, 1 ), maxiter)
1010 ev = zeros (eltype (A), maxiter)
1111 max_index = 0
@@ -21,7 +21,7 @@ function approximate_spectral_radius(A, tol = 0.01,
2121 # m, max_index = findmax(abs.(ev))
2222 m, max_index = findmaxabs (ev)
2323 error = H[nvecs, nvecs- 1 ] * evect[end , max_index]
24- if abs (error) / abs (ev[max_index]) < tol || flag
24+ if ( abs (error) / abs (ev[max_index]) < tol) || flag
2525 # v0 = X * evect[:, max_index]
2626 A_mul_B! (v0, X, evect[:, max_index])
2727 break
@@ -63,6 +63,7 @@ function approximate_eigenvalues(A, tol, maxiter, symmetric, v0)
6363 # V = Vector{Vector{eltype(A)}}(maxiter + 1)
6464 # V = zeros(size(A,1), maxiter)
6565 # V[1] = v0
66+ breakdown = find_breakdown (eltype (A))
6667 flag = false
6768
6869 for j = 1 : maxiter
@@ -73,11 +74,11 @@ function approximate_eigenvalues(A, tol, maxiter, symmetric, v0)
7374 for (i,v) in enumerate (V)
7475 # for i = 1:j
7576 v = V[i]
76- H[i,j] = dot (v , w)
77+ H[i,j] = dot (conj .(v) , w)
7778 BLAS. axpy! (- H[i,j], v, w)
7879 end
7980 H[j+ 1 ,j] = norm (w)
80- if H[j+ 1 , j] < eps ()
81+ if H[j+ 1 , j] < breakdown
8182 flag = true
8283 if H[j+ 1 ,j] != 0
8384 scale! (w, 1 / H[j+ 1 ,j])
@@ -94,3 +95,6 @@ function approximate_eigenvalues(A, tol, maxiter, symmetric, v0)
9495
9596 Vects, Eigs, H, V, flag
9697end
98+
99+ find_breakdown (:: Type{Float64} ) = eps (Float64) * 10 ^ 6
100+ find_breakdown (:: Type{Float32} ) = eps (Float64) * 10 ^ 3
0 commit comments