@@ -689,11 +689,11 @@ function lobpcg(A, largest::Bool, nev::Int=1; kwargs...)
689689 lobpcg (A, nothing , largest, nev; kwargs... )
690690end
691691function lobpcg (A, B, largest:: Bool , nev:: Int = 1 ; kwargs... )
692- lobpcg (A, B, largest, rand (size (A, 1 ), nev); kwargs... )
692+ lobpcg (A, B, largest, rand (eltype (A), size (A, 1 ), nev); not_zeros = true , kwargs... )
693693end
694694function lobpcg (A, B, largest, X0;
695- log = false , P = nothing , C = nothing ,
696- tol= nothing , maxiter= 200 )
695+ not_zeros = false , log = false , P = nothing ,
696+ C = nothing , tol= nothing , maxiter= 200 )
697697
698698 X = copy (X0)
699699 T = eltype (X)
@@ -703,7 +703,7 @@ function lobpcg(A, B, largest, X0;
703703
704704 iterator = LOBPCGIterator (A, B, X, largest, P, C)
705705
706- return lobpcg! (iterator, log= log, tol= tol, maxiter= maxiter)
706+ return lobpcg! (iterator, log= log, tol= tol, maxiter= maxiter, not_zeros = not_zeros )
707707end
708708
709709"""
@@ -728,12 +728,14 @@ end
728728- `results`: a `LOBPCGResults` struct. `r.λ` and `r.X` store the eigenvalues and eigenvectors.
729729
730730"""
731- function lobpcg! (iterator:: LOBPCGIterator ; log= false , tol= nothing , maxiter= 200 )
731+ function lobpcg! (iterator:: LOBPCGIterator ; log= false , tol= nothing , maxiter= 200 , not_zeros = false )
732732 T = eltype (iterator. XBlocks. block)
733733 X = iterator. XBlocks. block
734+ if ! not_zeros
734735 for j in 1 : size (X,2 )
735736 if all (x -> x== 0 , view (X, :, j))
736- X[:,j] .= rand .()
737+ @inbounds X[:,j] .= rand .()
738+ end
737739 end
738740 end
739741 n = size (X, 1 )
0 commit comments