[Scipy-svn] r6732 - trunk/scipy/sparse/linalg/eigen/lobpcg

scipy-svn@scip... scipy-svn@scip...
Sat Sep 11 19:53:38 CDT 2010


Author: ptvirtan
Date: 2010-09-11 19:53:38 -0500 (Sat, 11 Sep 2010)
New Revision: 6732

Modified:
   trunk/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py
Log:
3K: sparse.linalg.eigen: inject __call__ in a Py3 compatible way

Modified: trunk/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py	2010-09-12 00:53:22 UTC (rev 6731)
+++ trunk/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py	2010-09-12 00:53:38 UTC (rev 6732)
@@ -10,6 +10,7 @@
 Examples in tests directory contributed by Nils Wagner.
 """
 
+import sys
 import numpy as np
 import scipy as sp
 
@@ -81,6 +82,10 @@
         aux.shape = (ar.shape[0], 1)
         return aux
 
+class CallableLinearOperator(LinearOperator):
+    def __call__(self, x):
+        return self.matmat(x)
+
 def makeOperator( operatorInput, expectedShape ):
     """Internal. Takes a dense numpy array or a sparse matrix or
     a function and makes an operator performing matrix * blockvector
@@ -103,7 +108,11 @@
     if operator.shape != expectedShape:
         raise ValueError('operator has invalid shape')
 
-    operator.__call__ = operator.matmat
+    if sys.version_info[0] >= 3:
+        # special methods are looked up on the class -- so make a new one
+        operator.__class__ = CallableLinearOperator
+    else:
+        operator.__call__ = operator.matmat
 
     return operator
 



More information about the Scipy-svn mailing list