[Scipy-svn] r6991 - in trunk/scipy/sparse/linalg/eigen/arpack: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Dec 4 14:25:44 CST 2010


Author: ptvirtan
Date: 2010-12-04 14:25:44 -0600 (Sat, 04 Dec 2010)
New Revision: 6991

Modified:
   trunk/scipy/sparse/linalg/eigen/arpack/arpack.py
   trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py
Log:
ENH: sparse/arpack: Rename routines eigen* -> eigs* to avoid conflict with module name

Modified: trunk/scipy/sparse/linalg/eigen/arpack/arpack.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/arpack.py	2010-12-04 20:25:34 UTC (rev 6990)
+++ trunk/scipy/sparse/linalg/eigen/arpack/arpack.py	2010-12-04 20:25:44 UTC (rev 6991)
@@ -12,11 +12,11 @@
 # The entry points to ARPACK are
 # - (s,d)seupd : single and double precision symmetric matrix
 # - (s,d,c,z)neupd: single,double,complex,double complex general matrix
-# This wrapper puts the *neupd (general matrix) interfaces in eigen()
-# and the *seupd (symmetric matrix) in eigen_symmetric().
+# This wrapper puts the *neupd (general matrix) interfaces in eigs()
+# and the *seupd (symmetric matrix) in eigsh().
 # There is no Hermetian complex/double complex interface.
 # To find eigenvalues of a Hermetian matrix you
-# must use eigen() and not eigen_symmetric()
+# must use eigs() and not eigsh()
 # It might be desirable to handle the Hermetian case differently
 # and, for example, return real eigenvalues.
 
@@ -39,7 +39,7 @@
 
 __docformat__ = "restructuredtext en"
 
-__all___=['eigen','eigen_symmetric', 'svd', 'ArpackNoConvergence']
+__all___=['eigs', 'eigsh', 'svds', 'ArpackNoConvergence']
 
 import _arpack
 import numpy as np
@@ -450,9 +450,9 @@
         else:
             return d
 
-def eigen(A, k=6, M=None, sigma=None, which='LM', v0=None,
-          ncv=None, maxiter=None, tol=0,
-          return_eigenvectors=True):
+def eigs(A, k=6, M=None, sigma=None, which='LM', v0=None,
+         ncv=None, maxiter=None, tol=0,
+         return_eigenvectors=True):
     """
     Find k eigenvalues and eigenvectors of the square matrix A.
 
@@ -521,14 +521,14 @@
 
     See Also
     --------
-    eigen_symmetric : eigenvalues and eigenvectors for symmetric matrix A
+    eigsh : eigenvalues and eigenvectors for symmetric matrix A
 
     Examples
     --------
     Find 6 eigenvectors of the identity matrix:
 
     >>> id = np.identity(13)
-    >>> vals, vecs = sp.sparse.linalg.eigen(id, k=6)
+    >>> vals, vecs = sp.sparse.linalg.eigs(id, k=6)
     >>> vals
     array([ 1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j])
     >>> vecs.shape
@@ -552,11 +552,11 @@
 
     return params.extract(return_eigenvectors)
 
-def eigen_symmetric(A, k=6, M=None, sigma=None, which='LM', v0=None,
-                    ncv=None, maxiter=None, tol=0,
-                    return_eigenvectors=True):
-    """Find k eigenvalues and eigenvectors of the real symmetric
-    square matrix A.
+def eigsh(A, k=6, M=None, sigma=None, which='LM', v0=None,
+          ncv=None, maxiter=None, tol=0,
+          return_eigenvectors=True):
+    """
+    Find k eigenvalues and eigenvectors of the real symmetric square matrix A.
 
     Solves A * x[i] = w[i] * x[i], the standard eigenvalue problem for
     w[i] eigenvalues with corresponding eigenvectors x[i].
@@ -570,7 +570,7 @@
         matrix formats in scipy.sparse are appropriate for A.
 
     k : integer
-        The number of eigenvalues and eigenvectors desired
+        The number of eigenvalues and eigenvectors desired.
 
     Returns
     -------
@@ -631,7 +631,7 @@
 
     See Also
     --------
-    eigen : eigenvalues and eigenvectors for a general (nonsymmetric) matrix A
+    eigs : eigenvalues and eigenvectors for a general (nonsymmetric) matrix A
 
     Notes
     -----
@@ -656,7 +656,7 @@
 
     return params.extract(return_eigenvectors)
 
-def svd(A, k=6):
+def svds(A, k=6):
     """Compute a few singular values/vectors for a sparse matrix using ARPACK.
 
     Parameters

Modified: trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py	2010-12-04 20:25:34 UTC (rev 6990)
+++ trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py	2010-12-04 20:25:44 UTC (rev 6991)
@@ -12,10 +12,10 @@
 
 from numpy import array, finfo, argsort, dot, round, conj, random
 from scipy.sparse import csc_matrix, isspmatrix
-from scipy.sparse.linalg.eigen.arpack import eigen_symmetric, eigen, svd, \
+from scipy.sparse.linalg.eigen.arpack import eigs, eigsh, svds, \
      ArpackNoConvergence
 
-from scipy.linalg import svd as dsvd
+from scipy.linalg import svd
 
 def assert_almost_equal_cc(actual,desired,decimal=7,err_msg='',verbose=True):
     # almost equal or complex conjugates almost equal
@@ -109,7 +109,7 @@
         if v0 == None:
             v0 = d['v0']
         exact_eval=self.get_exact_eval(d,typ,k,which)
-        eval,evec=eigen_symmetric(a,k,which=which,v0=v0)
+        eval,evec=eigsh(a,k,which=which,v0=v0)
         # check eigenvalues
         assert_array_almost_equal(eval,exact_eval,decimal=_ndigits[typ])
         # check eigenvectors A*evec=eval*evec
@@ -138,7 +138,7 @@
         m = np.random.rand(30, 30)
         m = m + m.T
         try:
-            w, v = eigen_symmetric(m, 4, which='LM', v0=m[:,0], maxiter=5)
+            w, v = eigsh(m, 4, which='LM', v0=m[:,0], maxiter=5)
             raise AssertionError("Spurious no-error exit")
         except ArpackNoConvergence, err:
             k = len(err.eigenvalues)
@@ -171,7 +171,7 @@
         ind=self.sort_choose(exact_eval,typ,k,which)
         exact_eval=exact_eval[ind]
         # compute eigenvalues
-        eval,evec=eigen(a,k,which=which,v0=v0)
+        eval,evec=eigs(a,k,which=which,v0=v0)
         ind=self.sort_choose(eval,typ,k,which)
         eval=eval[ind]
         evec=evec[:,ind]
@@ -195,7 +195,7 @@
         np.random.seed(1234)
         m = np.random.rand(30, 30) + 1j*np.random.rand(30, 30)
         try:
-            w, v = eigen(m, 3, which='LM', v0=m[:,0], maxiter=30)
+            w, v = eigs(m, 3, which='LM', v0=m[:,0], maxiter=30)
             raise AssertionError("Spurious no-error exit")
         except ArpackNoConvergence, err:
             k = len(err.eigenvalues)
@@ -234,7 +234,7 @@
         ind=self.sort_choose(exact_eval,typ,k,which)
         exact_eval=exact_eval[ind]
         # compute eigenvalues
-        eval,evec=eigen(a,k,which=which,v0=v0)
+        eval,evec=eigs(a,k,which=which,v0=v0)
         ind=self.sort_choose(eval,typ,k,which)
         eval=eval[ind]
         evec=evec[:,ind]
@@ -268,7 +268,7 @@
         np.random.seed(1234)
         m = np.random.rand(30, 30)
         try:
-            w, v = eigen(m, 3, which='LM', v0=m[:,0], maxiter=30)
+            w, v = eigs(m, 3, which='LM', v0=m[:,0], maxiter=30)
             raise AssertionError("Spurious no-error exit")
         except ArpackNoConvergence, err:
             k = len(err.eigenvalues)
@@ -310,7 +310,7 @@
 
 
         # compute eigenvalues
-        eval,evec=eigen(a,k,which=which,v0=v0)
+        eval,evec=eigs(a,k,which=which,v0=v0)
         ind=self.sort_choose(eval,typ,k,which)
         eval=eval[ind]
         evec=evec[:,ind]
@@ -336,7 +336,7 @@
         np.random.seed(1234)
         m = np.random.rand(30, 30) + 1j*np.random.rand(30, 30)
         try:
-            w, v = eigen(m, 3, which='LM', v0=m[:,0], maxiter=30)
+            w, v = eigs(m, 3, which='LM', v0=m[:,0], maxiter=30)
             raise AssertionError("Spurious no-error exit")
         except ArpackNoConvergence, err:
             k = len(err.eigenvalues)
@@ -350,13 +350,13 @@
 def test_eigen_bad_shapes():
     # A is not square.
     A = csc_matrix(np.zeros((2,3)))
-    assert_raises(ValueError, eigen, A)
+    assert_raises(ValueError, eigs, A)
 
 
 def sorted_svd(m, k):
     """Compute svd of a dense matrix m, and return singular vectors/values
     sorted."""
-    u, s, vh = dsvd(m)
+    u, s, vh = svd(m)
     ii = np.argsort(s)[-k:]
 
     return u[:, ii], s[ii], vh[ii]
@@ -374,7 +374,7 @@
         for m in [x.T, x]:
             for k in range(1, 3):
                 u, s, vh = sorted_svd(m, k)
-                su, ss, svh = svd(m, k)
+                su, ss, svh = svds(m, k)
 
                 m_hat = svd_estimate(u, s, vh)
                 sm_hat = svd_estimate(su, ss, svh)
@@ -382,7 +382,7 @@
                 assert_array_almost_equal_nulp(m_hat, sm_hat, nulp=1000)
 
     @dec.knownfailureif(True, "Complex sparse SVD not implemented (depends on "
-                              "Hermitian support in eigen_symmetric")
+                              "Hermitian support in eigsh")
     def test_simple_complex(self):
         x = np.array([[1, 2, 3],
                       [3, 4, 3],
@@ -392,7 +392,7 @@
         for m in [x, x.T.conjugate()]:
             for k in range(1, 3):
                 u, s, vh = sorted_svd(m, k)
-                su, ss, svh = svd(m, k)
+                su, ss, svh = svds(m, k)
 
                 m_hat = svd_estimate(u, s, vh)
                 sm_hat = svd_estimate(su, ss, svh)



More information about the Scipy-svn mailing list