[Scipy-svn] r2522 - in trunk/Lib/linsolve: . umfpack umfpack/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Jan 10 10:42:31 EST 2007


Author: rc
Date: 2007-01-10 09:42:24 -0600 (Wed, 10 Jan 2007)
New Revision: 2522

Modified:
   trunk/Lib/linsolve/info.py
   trunk/Lib/linsolve/linsolve.py
   trunk/Lib/linsolve/umfpack/tests/test_umfpack.py
   trunk/Lib/linsolve/umfpack/umfpack.py
Log:
assumeSortedIndices support for umfpack\n

Modified: trunk/Lib/linsolve/info.py
===================================================================
--- trunk/Lib/linsolve/info.py	2007-01-10 14:14:16 UTC (rev 2521)
+++ trunk/Lib/linsolve/info.py	2007-01-10 15:42:24 UTC (rev 2522)
@@ -6,8 +6,8 @@
 solve real or complex linear systems in both single and double precisions.  It
 is automatically replaced by UMFPACK, if available. Note that UMFPACK works in
 double precision only, so switch it off by
->>> use_solver( use = {'useUmfpack': False} )
-to solve in the single precision.
+>>> use_solver( useUmfpack = False )
+to solve in the single precision. See also use_solver documentation.
 
 Example session:
 
@@ -20,14 +20,14 @@
 >>> a = spdiags([[1, 2, 3, 4, 5], [6, 5, 8, 9, 10]], [0, 1], 5, 5)
 >>> b = array([1, 2, 3, 4, 5])
 >>> print "Solve: single precision complex:"
->>> use_solver( use = {'useUmfpack' : False} )
+>>> use_solver( useUmfpack = False )
 >>> a = a.astype('F')
 >>> x = spsolve(a, b)
 >>> print x
 >>> print "Error: ", a*x-b
 >>>
 >>> print "Solve: double precision complex:"
->>> use_solver( use = {'useUmfpack' : True} )
+>>> use_solver( useUmfpack = True )
 >>> a = a.astype('D')
 >>> x = spsolve(a, b)
 >>> print x
@@ -40,7 +40,7 @@
 >>> print "Error: ", a*x-b
 >>>
 >>> print "Solve: single precision:"
->>> use_solver( use = {'useUmfpack' : False} )
+>>> use_solver( useUmfpack = False )
 >>> a = a.astype('f')
 >>> x = spsolve(a, b.astype('f'))
 >>> print x

Modified: trunk/Lib/linsolve/linsolve.py
===================================================================
--- trunk/Lib/linsolve/linsolve.py	2007-01-10 14:14:16 UTC (rev 2521)
+++ trunk/Lib/linsolve/linsolve.py	2007-01-10 15:42:24 UTC (rev 2522)
@@ -10,15 +10,26 @@
     isUmfpack = False
 useUmfpack = True
 
-def use_solver( use ):
+def use_solver( **kwargs ):
     """
+    Valid keyword arguments with defaults (other ignored):
+      useUmfpack = True
+      assumeSortedIndices = False
+      
     The default sparse solver is umfpack when available. This can be changed by
-    passing "use = {'useUmfpack' : False}"
-    which then causes the always present SuperLU based solver to be used.
+    passing useUmfpack = False, which then causes the always present SuperLU
+    based solver to be used.
+    
+    Umfpack requires a CSR/CSC matrix to have sorted column/row indices. If
+    sure that the matrix fulfills this, pass assumeSortedIndices =
+    True to gain some speed.
     """
-    for key, val in use.iteritems():
-        globals()[key] = val
+    if kwargs.has_key( 'useUmfpack' ):
+        globals()['useUmfpack'] = kwargs['useUmfpack']
 
+    if isUmfpack:
+        umfpack.configure( **kwargs )
+
 def _toCS_superLU( A ):
     if hasattr(A, 'tocsc') and not isspmatrix_csr( A ):
         mat = A.tocsc()
@@ -71,7 +82,8 @@
 
         family = {'d' : 'di', 'D' : 'zi'}
         umf = umfpack.UmfpackContext( family[mat.dtype.char] )
-        return umf.linsolve( umfpack.UMFPACK_A, mat, b, autoTranspose = True )
+        return umf.linsolve( umfpack.UMFPACK_A, mat, b,
+                             autoTranspose = True )
 
     else:
         mat, csc = _toCS_superLU( A )
@@ -116,14 +128,14 @@
     a = spdiags([[1, 2, 3, 4, 5], [6, 5, 8, 9, 10]], [0, 1], 5, 5)
     b = array([1, 2, 3, 4, 5])
     print "Solve: single precision complex:"
-    use_solver( use = {'useUmfpack' : False} )
+    use_solver( useUmfpack = False )
     a = a.astype('F')
     x = spsolve(a, b)
     print x
     print "Error: ", a*x-b
 
     print "Solve: double precision complex:"
-    use_solver( use = {'useUmfpack' : True} )
+    use_solver( useUmfpack = True )
     a = a.astype('D')
     x = spsolve(a, b)
     print x
@@ -136,7 +148,7 @@
     print "Error: ", a*x-b
 
     print "Solve: single precision:"
-    use_solver( use = {'useUmfpack' : False} )
+    use_solver( useUmfpack = False )
     a = a.astype('f')
     x = spsolve(a, b.astype('f'))
     print x

Modified: trunk/Lib/linsolve/umfpack/tests/test_umfpack.py
===================================================================
--- trunk/Lib/linsolve/umfpack/tests/test_umfpack.py	2007-01-10 14:14:16 UTC (rev 2521)
+++ trunk/Lib/linsolve/umfpack/tests/test_umfpack.py	2007-01-10 15:42:24 UTC (rev 2522)
@@ -23,7 +23,7 @@
     
     def check_solve_complex_without_umfpack(self):
         """Solve: single precision complex"""
-        linsolve.use_solver( {'useUmfpack' :  False} )
+        linsolve.use_solver( useUmfpack = False )
         a = self.a.astype('F')
         b = self.b
         x = linsolve.spsolve(a, b)
@@ -34,7 +34,7 @@
         
     def check_solve_without_umfpack(self): 
         """Solve: single precision"""
-        linsolve.use_solver( {'useUmfpack' :  False} )
+        linsolve.use_solver( useUmfpack = False )
         a = self.a.astype('f')
         b = self.b
         x = linsolve.spsolve(a, b.astype('f'))
@@ -45,7 +45,7 @@
 
     def check_solve_complex_umfpack(self):
         """Solve with UMFPACK: double precision complex"""
-        linsolve.use_solver( {'useUmfpack' :  True} )
+        linsolve.use_solver( useUmfpack = True )
         a = self.a.astype('D')
         b = self.b
         x = linsolve.spsolve(a, b)
@@ -55,7 +55,7 @@
 
     def check_solve_umfpack(self):
         """Solve with UMFPACK: double precision"""
-        linsolve.use_solver( {'useUmfpack' :  True} )
+        linsolve.use_solver( useUmfpack = True )
         a = self.a.astype('d')
         b = self.b
         x = linsolve.spsolve(a, b)

Modified: trunk/Lib/linsolve/umfpack/umfpack.py
===================================================================
--- trunk/Lib/linsolve/umfpack/umfpack.py	2007-01-10 14:14:16 UTC (rev 2521)
+++ trunk/Lib/linsolve/umfpack/umfpack.py	2007-01-10 15:42:24 UTC (rev 2522)
@@ -15,7 +15,24 @@
 except:
     _um = None
 
+assumeSortedIndices = False
+
 ##
+# 10.01.2006, c
+def configure( **kwargs ):
+    """
+    Valid keyword arguments with defaults (other ignored):
+      assumeSortedIndices = False
+
+    Umfpack requires a CSR/CSC matrix to have sorted column/row indices. If
+    sure that the matrix fulfills this, pass assumeSortedIndices =
+    True to gain some speed.
+    """
+    if kwargs.has_key( 'assumeSortedIndices' ):
+        globals()['assumeSortedIndices'] = kwargs['assumeSortedIndices']
+    
+
+##
 # 30.11.2005, c
 def updateDictWithVars( adict, module, pattern, group = None ):
     match = re.compile( pattern ).match
@@ -330,15 +347,15 @@
 
     ##
     # 30.11.2005, c
-    # 01.12.2005
-    # 01.03.2006
+    # last revision: 10.01.2007
     def symbolic( self, mtx ):
         """Symbolic object (symbolic LU decomposition) computation for a given
         sparsity pattern."""
         self.free_symbolic()
 
-        #row/column indices cannot be assumed to be sorted
-        mtx.ensure_sorted_indices(inplace=True)
+        if not assumeSortedIndices:
+            # row/column indices cannot be assumed to be sorted
+            mtx.ensure_sorted_indices( inplace = True )
 
         indx = self._getIndx( mtx )
         if self.isReal:
@@ -373,9 +390,6 @@
 
         self.free_numeric()
 
-        #row/column indices cannot be assumed to be sorted
-        mtx.ensure_sorted_indices(inplace=True)
-
         if self._symbolic is None:
             self.symbolic( mtx )
 




More information about the Scipy-svn mailing list