[Scipy-svn] r4707 - in trunk/scipy: io/arff/tests linalg signal weave

scipy-svn@scip... scipy-svn@scip...
Tue Sep 9 09:17:05 CDT 2008


Author: alan.mcintyre
Date: 2008-09-09 09:16:57 -0500 (Tue, 09 Sep 2008)
New Revision: 4707

Modified:
   trunk/scipy/io/arff/tests/test_data.py
   trunk/scipy/linalg/matfuncs.py
   trunk/scipy/signal/wavelets.py
   trunk/scipy/weave/accelerate_tools.py
Log:
Standardize NumPy import as "import numpy as np".
Removed unused numpy import.


Modified: trunk/scipy/io/arff/tests/test_data.py
===================================================================
--- trunk/scipy/io/arff/tests/test_data.py	2008-09-09 13:55:11 UTC (rev 4706)
+++ trunk/scipy/io/arff/tests/test_data.py	2008-09-09 14:16:57 UTC (rev 4707)
@@ -2,7 +2,6 @@
 """Tests for parsing full arff files."""
 import os
 
-import numpy as N
 from numpy.testing import *
 
 from scipy.io.arff.arffread import loadarff

Modified: trunk/scipy/linalg/matfuncs.py
===================================================================
--- trunk/scipy/linalg/matfuncs.py	2008-09-09 13:55:11 UTC (rev 4706)
+++ trunk/scipy/linalg/matfuncs.py	2008-09-09 14:16:57 UTC (rev 4707)
@@ -12,12 +12,12 @@
      cast, log, ogrid, isfinite, imag, real, absolute, amax, sign, \
      isfinite, sqrt, identity, single
 from numpy import matrix as mat
-import numpy as sb
+import numpy as np
 from basic import solve, inv, norm, triu, all_mat
 from decomp import eig, schur, rsf2csf, orth, svd
 
-eps = sb.finfo(float).eps
-feps = sb.finfo(single).eps
+eps = np.finfo(float).eps
+feps = np.finfo(single).eps
 
 def expm(A,q=7):
     """Compute the matrix exponential using Pade approximation.
@@ -142,7 +142,7 @@
     if tol is None:
         tol = {0:feps*1e3, 1:eps*1e6}[_array_precision[arr.dtype.char]]
     if (arr.dtype.char in ['F', 'D','G']) and \
-       sb.allclose(arr.imag, 0.0, atol=tol):
+       np.allclose(arr.imag, 0.0, atol=tol):
         arr = arr.real
     return arr
 
@@ -455,11 +455,11 @@
     # Shifting to avoid zero eigenvalues. How to ensure that shifting does
     # not change the spectrum too much?
     vals = svd(a,compute_uv=0)
-    max_sv = sb.amax(vals)
+    max_sv = np.amax(vals)
     #min_nonzero_sv = vals[(vals>max_sv*errtol).tolist().count(1)-1]
     #c = 0.5/min_nonzero_sv
     c = 0.5/max_sv
-    S0 = a + c*sb.identity(a.shape[0])
+    S0 = a + c*np.identity(a.shape[0])
     prev_errest = errest
     for i in range(100):
         iS0 = inv(S0)
@@ -508,7 +508,7 @@
     T, Z = rsf2csf(T,Z)
     n,n = T.shape
 
-    R = sb.zeros((n,n),T.dtype.char)
+    R = np.zeros((n,n),T.dtype.char)
     for j in range(n):
         R[j,j] = sqrt(T[j,j])
         for i in range(j-1,-1,-1):
@@ -521,7 +521,7 @@
     X = (Z * R * Z.H)
 
     if disp:
-        nzeig = sb.any(sb.diag(T)==0)
+        nzeig = np.any(diag(T)==0)
         if nzeig:
             print "Matrix is singular and may not have a square root."
         return X.A

Modified: trunk/scipy/signal/wavelets.py
===================================================================
--- trunk/scipy/signal/wavelets.py	2008-09-09 13:55:11 UTC (rev 4706)
+++ trunk/scipy/signal/wavelets.py	2008-09-09 14:16:57 UTC (rev 4707)
@@ -1,6 +1,6 @@
 __all__ = ['daub','qmf','cascade','morlet']
 
-import numpy as sb
+import numpy as np
 from numpy.dual import eig
 from scipy.misc import comb
 from scipy import linspace, pi, exp, zeros
@@ -10,36 +10,36 @@
 
     p>=1 gives the order of the zero at f=1/2.  There are 2p filter coefficients.
     """
-    sqrt = sb.sqrt
+    sqrt = np.sqrt
     assert(p>=1)
     if p==1:
         c = 1/sqrt(2)
-        return sb.array([c,c])
+        return np.array([c,c])
     elif p==2:
         f = sqrt(2)/8
         c = sqrt(3)
-        return f*sb.array([1+c,3+c,3-c,1-c])
+        return f*np.array([1+c,3+c,3-c,1-c])
     elif p==3:
         tmp  = 12*sqrt(10)
         z1 = 1.5 + sqrt(15+tmp)/6 - 1j*(sqrt(15)+sqrt(tmp-15))/6
-        z1c = sb.conj(z1)
+        z1c = np.conj(z1)
         f = sqrt(2)/8
-        d0 = sb.real((1-z1)*(1-z1c))
-        a0 = sb.real(z1*z1c)
-        a1 = 2*sb.real(z1)
-        return f/d0*sb.array([a0, 3*a0-a1, 3*a0-3*a1+1, a0-3*a1+3, 3-a1, 1])
+        d0 = np.real((1-z1)*(1-z1c))
+        a0 = np.real(z1*z1c)
+        a1 = 2*np.real(z1)
+        return f/d0*np.array([a0, 3*a0-a1, 3*a0-3*a1+1, a0-3*a1+3, 3-a1, 1])
     elif p<35:
         # construct polynomial and factor it
         if p<35:
             P = [comb(p-1+k,k,exact=1) for k in range(p)][::-1]
-            yj = sb.roots(P)
+            yj = np.roots(P)
         else:  # try different polynomial --- needs work
             P = [comb(p-1+k,k,exact=1)/4.0**k for k in range(p)][::-1]
-            yj = sb.roots(P) / 4
+            yj = np.roots(P) / 4
         # for each root, compute two z roots, select the one with |z|>1
         # Build up final polynomial
-        c = sb.poly1d([1,1])**p
-        q = sb.poly1d([1])
+        c = np.poly1d([1,1])**p
+        q = np.poly1d([1])
         for k in range(p-1):
             yval = yj[k]
             part = 2*sqrt(yval*(yval-1))
@@ -49,9 +49,9 @@
                 z1 = const - part
             q = q * [1,-z1]
 
-        q = c * sb.real(q)
+        q = c * np.real(q)
         # Normalize result
-        q = q / sb.sum(q) * sqrt(2)
+        q = q / np.sum(q) * sqrt(2)
         return q.c[::-1]
     else:
         raise ValueError, "Polynomial factorization does not work "\
@@ -62,7 +62,7 @@
     """
     N = len(hk)-1
     asgn = [{0:1,1:-1}[k%2] for k in range(N+1)]
-    return hk[::-1]*sb.array(asgn)
+    return hk[::-1]*np.array(asgn)
 
 def wavedec(amn,hk):
     gk = qmf(hk)
@@ -96,55 +96,55 @@
 
     N = len(hk)-1
 
-    if (J > 30 - sb.log2(N+1)):
+    if (J > 30 - np.log2(N+1)):
         raise ValueError, "Too many levels."
     if (J < 1):
         raise ValueError, "Too few levels."
 
 
     # construct matrices needed
-    nn,kk = sb.ogrid[:N,:N]
-    s2 = sb.sqrt(2)
+    nn,kk = np.ogrid[:N,:N]
+    s2 = np.sqrt(2)
     # append a zero so that take works
-    thk = sb.r_[hk,0]
+    thk = np.r_[hk,0]
     gk = qmf(hk)
-    tgk = sb.r_[gk,0]
+    tgk = np.r_[gk,0]
 
-    indx1 = sb.clip(2*nn-kk,-1,N+1)
-    indx2 = sb.clip(2*nn-kk+1,-1,N+1)
-    m = sb.zeros((2,2,N,N),'d')
-    m[0,0] = sb.take(thk,indx1,0)
-    m[0,1] = sb.take(thk,indx2,0)
-    m[1,0] = sb.take(tgk,indx1,0)
-    m[1,1] = sb.take(tgk,indx2,0)
+    indx1 = np.clip(2*nn-kk,-1,N+1)
+    indx2 = np.clip(2*nn-kk+1,-1,N+1)
+    m = np.zeros((2,2,N,N),'d')
+    m[0,0] = np.take(thk,indx1,0)
+    m[0,1] = np.take(thk,indx2,0)
+    m[1,0] = np.take(tgk,indx1,0)
+    m[1,1] = np.take(tgk,indx2,0)
     m *= s2
 
     # construct the grid of points
-    x = sb.arange(0,N*(1<<J),dtype=sb.float) / (1<<J)
+    x = np.arange(0,N*(1<<J),dtype=np.float) / (1<<J)
     phi = 0*x
 
     psi = 0*x
 
     # find phi0, and phi1
     lam, v = eig(m[0,0])
-    ind = sb.argmin(sb.absolute(lam-1))
+    ind = np.argmin(np.absolute(lam-1))
     # a dictionary with a binary representation of the
     #   evaluation points x < 1 -- i.e. position is 0.xxxx
-    v = sb.real(v[:,ind])
+    v = np.real(v[:,ind])
     # need scaling function to integrate to 1 so find
     #  eigenvector normalized to sum(v,axis=0)=1
-    sm = sb.sum(v)
+    sm = np.sum(v)
     if sm < 0:  # need scaling function to integrate to 1
         v = -v
         sm = -sm
     bitdic = {}
     bitdic['0'] = v / sm
-    bitdic['1'] = sb.dot(m[0,1],bitdic['0'])
+    bitdic['1'] = np.dot(m[0,1],bitdic['0'])
     step = 1<<J
     phi[::step] = bitdic['0']
     phi[(1<<(J-1))::step] = bitdic['1']
-    psi[::step] = sb.dot(m[1,0],bitdic['0'])
-    psi[(1<<(J-1))::step] = sb.dot(m[1,1],bitdic['0'])
+    psi[::step] = np.dot(m[1,0],bitdic['0'])
+    psi[(1<<(J-1))::step] = np.dot(m[1,1],bitdic['0'])
     # descend down the levels inserting more and more values
     #  into bitdic -- store the values in the correct location once we
     #  have computed them -- stored in the dictionary
@@ -161,10 +161,10 @@
                     num += (1<<(level-1-pos))
             pastphi = bitdic[key[1:]]
             ii = int(key[0])
-            temp = sb.dot(m[0,ii],pastphi)
+            temp = np.dot(m[0,ii],pastphi)
             bitdic[key] = temp
             phi[num*fac::step] = temp
-            psi[num*fac::step] = sb.dot(m[1,ii],pastphi)
+            psi[num*fac::step] = np.dot(m[1,ii],pastphi)
         prevkeys = newkeys
 
     return x, phi, psi

Modified: trunk/scipy/weave/accelerate_tools.py
===================================================================
--- trunk/scipy/weave/accelerate_tools.py	2008-09-09 13:55:11 UTC (rev 4706)
+++ trunk/scipy/weave/accelerate_tools.py	2008-09-09 14:16:57 UTC (rev 4707)
@@ -109,7 +109,7 @@
 Double = Double()
 String = String()
 
-import numpy as nx
+import numpy as np
 
 class Vector(Type_Descriptor):
     cxxtype = 'PyArrayObject*'
@@ -214,12 +214,12 @@
     int : Integer,
     float : Double,
     str: String,
-    (nx.ndarray,1,int): IntegerVector,
-    (nx.ndarray,2,int): Integermatrix,
-    (nx.ndarray,1,nx.long): LongVector,
-    (nx.ndarray,2,nx.long): Longmatrix,
-    (nx.ndarray,1,float): DoubleVector,
-    (nx.ndarray,2,float): Doublematrix,
+    (np.ndarray,1,int): IntegerVector,
+    (np.ndarray,2,int): Integermatrix,
+    (np.ndarray,1,np.long): LongVector,
+    (np.ndarray,2,np.long): Longmatrix,
+    (np.ndarray,1,float): DoubleVector,
+    (np.ndarray,2,float): Doublematrix,
     XRangeType : XRange,
     }
 
@@ -260,7 +260,7 @@
     try:
         return typedefs[T]
     except:
-        if isinstance(T,nx.ndarray):
+        if isinstance(T,np.ndarray):
             return typedefs[(T,len(x.shape),x.dtype.char)]
         elif issubclass(T, InstanceType):
             return Instance(x)



More information about the Scipy-svn mailing list