1111
1212import numpy as np
1313
14- from numpy .testing import assert_allclose
15- from scipy ._lib .six import xrange
1614from scipy .linalg import inv , eigh , cho_factor , cho_solve , cholesky
1715from scipy .sparse .linalg import aslinearoperator , LinearOperator
1816
1917__all__ = ['lobpcg' ]
2018
2119
22- def pause ():
23- # Used only when verbosity level > 10.
24- input ()
25-
26-
2720def save (ar , fileName ):
2821 # Used only when verbosity level > 10.
2922 from numpy import savetxt
3023 savetxt (fileName , ar , precision = 8 )
3124
3225
33- def _assert_symmetric (M , rtol = 1e-5 , atol = 1e-8 ):
34- assert_allclose (M .T .conj (), M , rtol = rtol , atol = atol )
35-
36-
37- ##
38- # 21.05.2007, c
39-
40-
4126def as2d (ar ):
4227 """
4328 If the input array is 2D return it, if it is 1D, append a dimension,
@@ -271,8 +256,6 @@ def lobpcg(A, X,
271256 raise ValueError ('expected rank-2 array for argument X' )
272257
273258 n , sizeX = blockVectorX .shape
274- if sizeX > n :
275- raise ValueError ('X column dimension exceeds the row dimension' )
276259
277260 A = _makeOperator (A , (n , n ))
278261 B = _makeOperator (B , (n , n ))
@@ -336,8 +319,7 @@ def lobpcg(A, X,
336319 try :
337320 # gramYBY is a Cholesky factor from now on...
338321 gramYBY = cho_factor (gramYBY )
339- # E722 do not use bare except
340- except :
322+ except linearlyDependentConstraints :
341323 raise ValueError ('cannot handle linearly dependent constraints' )
342324
343325 _applyConstraints (blockVectorX , gramYBY , blockVectorBY , blockVectorY )
@@ -383,7 +365,9 @@ def lobpcg(A, X,
383365 blockVectorAP = None
384366 blockVectorBP = None
385367
386- for iterationNumber in xrange (maxIterations ):
368+ iterationNumber = - 1
369+ while iterationNumber < maxIterations :
370+ iterationNumber += 1
387371 if verbosityLevel > 0 :
388372 print ('iteration %d' % iterationNumber )
389373
@@ -505,9 +489,7 @@ def lobpcg(A, X,
505489
506490 if verbosityLevel > 10 :
507491 print (eigBlockVector )
508- pause ()
509492
510- ##
511493 # Compute Ritz vectors.
512494 if iterationNumber > 0 :
513495 eigBlockVectorX = eigBlockVector [:sizeX ]
@@ -534,7 +516,6 @@ def lobpcg(A, X,
534516 print (pp )
535517 print (app )
536518 print (bpp )
537- pause ()
538519
539520 blockVectorX = np .dot (blockVectorX , eigBlockVectorX ) + pp
540521 blockVectorAX = np .dot (blockVectorAX , eigBlockVectorX ) + app
0 commit comments