[Numpy-svn] r5822 - trunk/numpy/oldnumeric

numpy-svn@scip... numpy-svn@scip...
Sat Sep 13 13:10:51 CDT 2008


Author: alan.mcintyre
Date: 2008-09-13 13:10:48 -0500 (Sat, 13 Sep 2008)
New Revision: 5822

Modified:
   trunk/numpy/oldnumeric/arrayfns.py
   trunk/numpy/oldnumeric/compat.py
   trunk/numpy/oldnumeric/mlab.py
   trunk/numpy/oldnumeric/rng.py
Log:
Rewrapped __all__ definition to conform to PEP8.
Standardize NumPy import as "import numpy as np".
Removed unused imports.
Fixed undefined reference to ndarray (should be np.ndarray).
Fixed undefined references to exp (should be math.exp).


Modified: trunk/numpy/oldnumeric/arrayfns.py
===================================================================
--- trunk/numpy/oldnumeric/arrayfns.py	2008-09-13 18:04:57 UTC (rev 5821)
+++ trunk/numpy/oldnumeric/arrayfns.py	2008-09-13 18:10:48 UTC (rev 5822)
@@ -1,10 +1,11 @@
 """Backward compatible with arrayfns from Numeric
 """
 
-__all__ = ['array_set', 'construct3', 'digitize', 'error', 'find_mask', 'histogram', 'index_sort',
-           'interp', 'nz', 'reverse', 'span', 'to_corners', 'zmin_zmax']
+__all__ = ['array_set', 'construct3', 'digitize', 'error', 'find_mask', 
+           'histogram', 'index_sort', 'interp', 'nz', 'reverse', 'span', 
+           'to_corners', 'zmin_zmax']
 
-import numpy as nx
+import numpy as np
 from numpy import asarray
 
 class error(Exception):
@@ -14,7 +15,7 @@
     indices = asarray(indices)
     if indices.ndim != 1:
         raise ValueError, "index array must be 1-d"
-    if not isinstance(vals1, ndarray):
+    if not isinstance(vals1, np.ndarray):
         raise TypeError, "vals1 must be an ndarray"
     vals1 = asarray(vals1)
     vals2 = asarray(vals2)
@@ -31,7 +32,7 @@
 def interp(y, x, z, typ=None):
     """y(z) interpolated by treating y(x) as piecewise function
     """
-    res = numpy.interp(z, x, y)
+    res = np.interp(z, x, y)
     if typ is None or typ == 'd':
         return res
     if typ == 'f':
@@ -40,17 +41,17 @@
     raise error, "incompatible typecode"
 
 def nz(x):
-    x = asarray(x,dtype=nx.ubyte)
+    x = asarray(x,dtype=np.ubyte)
     if x.ndim != 1:
         raise TypeError, "intput must have 1 dimension."
-    indxs = nx.flatnonzero(x != 0)
+    indxs = np.flatnonzero(x != 0)
     return indxs[-1].item()+1
 
 def reverse(x, n):
     x = asarray(x,dtype='d')
     if x.ndim != 2:
         raise ValueError, "input must be 2-d"
-    y = nx.empty_like(x)
+    y = np.empty_like(x)
     if n == 0:
         y[...] = x[::-1,:]
     elif n == 1:
@@ -58,11 +59,11 @@
     return y
 
 def span(lo, hi, num, d2=0):
-    x = linspace(lo, hi, num)
+    x = np.linspace(lo, hi, num)
     if d2 <= 0:
         return x
     else:
-        ret = empty((d2,num),x.dtype)
+        ret = np.empty((d2,num),x.dtype)
         ret[...] = x
         return ret
 
@@ -71,15 +72,15 @@
     ireg = asarray(ireg, dtype=int)
     if z.shape != ireg.shape or z.ndim != 2:
         raise ValueError, "z and ireg must be the same shape and 2-d"
-    ix, iy = nx.nonzero(ireg)
+    ix, iy = np.nonzero(ireg)
     # Now, add more indices
     x1m = ix - 1
     y1m = iy-1
     i1 = x1m>=0
     i2 = y1m>=0
     i3 = i1 & i2
-    nix = nx.r_[ix, x1m[i1], x1m[i1], ix[i2] ]
-    niy = nx.r_[iy, iy[i1],  y1m[i3], y1m[i2]]
+    nix = np.r_[ix, x1m[i1], x1m[i1], ix[i2] ]
+    niy = np.r_[iy, iy[i1],  y1m[i3], y1m[i2]]
     # remove any negative indices
     zres = z[nix,niy]
     return zres.min().item(), zres.max().item()

Modified: trunk/numpy/oldnumeric/compat.py
===================================================================
--- trunk/numpy/oldnumeric/compat.py	2008-09-13 18:04:57 UTC (rev 5821)
+++ trunk/numpy/oldnumeric/compat.py	2008-09-13 18:10:48 UTC (rev 5822)
@@ -12,7 +12,7 @@
 
 import numpy.core.multiarray as multiarray
 import numpy.core.umath as um
-from numpy.core.numeric import array, correlate
+from numpy.core.numeric import array
 import functions
 import sys
 

Modified: trunk/numpy/oldnumeric/mlab.py
===================================================================
--- trunk/numpy/oldnumeric/mlab.py	2008-09-13 18:04:57 UTC (rev 5821)
+++ trunk/numpy/oldnumeric/mlab.py	2008-09-13 18:10:48 UTC (rev 5822)
@@ -1,6 +1,10 @@
 # This module is for compatibility only.  All functions are defined elsewhere.
 
-__all__ = ['rand', 'tril', 'trapz', 'hanning', 'rot90', 'triu', 'diff', 'angle', 'roots', 'ptp', 'kaiser', 'randn', 'cumprod', 'diag', 'msort', 'LinearAlgebra', 'RandomArray', 'prod', 'std', 'hamming', 'flipud', 'max', 'blackman', 'corrcoef', 'bartlett', 'eye', 'squeeze', 'sinc', 'tri', 'cov', 'svd', 'min', 'median', 'fliplr', 'eig', 'mean']
+__all__ = ['rand', 'tril', 'trapz', 'hanning', 'rot90', 'triu', 'diff', 'angle',
+           'roots', 'ptp', 'kaiser', 'randn', 'cumprod', 'diag', 'msort', 
+           'LinearAlgebra', 'RandomArray', 'prod', 'std', 'hamming', 'flipud',
+           'max', 'blackman', 'corrcoef', 'bartlett', 'eye', 'squeeze', 'sinc',
+           'tri', 'cov', 'svd', 'min', 'median', 'fliplr', 'eig', 'mean']
 
 import numpy.oldnumeric.linear_algebra as LinearAlgebra
 import numpy.oldnumeric.random_array as RandomArray
@@ -12,7 +16,7 @@
 
 from numpy.linalg import eig, svd
 from numpy.random import rand, randn
-import numpy as nn
+import numpy as np
 
 from typeconv import convtypecode
 
@@ -22,7 +26,7 @@
     """
     dtype = convtypecode(typecode, dtype)
     if M is None: M = N
-    m = nn.equal(nn.subtract.outer(nn.arange(N), nn.arange(M)),-k)
+    m = np.equal(np.subtract.outer(np.arange(N), np.arange(M)),-k)
     if m.dtype != dtype:
         return m.astype(dtype)
 
@@ -32,7 +36,7 @@
     """
     dtype = convtypecode(typecode, dtype)
     if M is None: M = N
-    m = nn.greater_equal(nn.subtract.outer(nn.arange(N), nn.arange(M)),-k)
+    m = np.greater_equal(np.subtract.outer(np.arange(N), np.arange(M)),-k)
     if m.dtype != dtype:
         return m.astype(dtype)
 

Modified: trunk/numpy/oldnumeric/rng.py
===================================================================
--- trunk/numpy/oldnumeric/rng.py	2008-09-13 18:04:57 UTC (rev 5821)
+++ trunk/numpy/oldnumeric/rng.py	2008-09-13 18:10:48 UTC (rev 5822)
@@ -4,9 +4,9 @@
 # It is for backwards compatibility only.
 
 
-__all__ = ['CreateGenerator','ExponentialDistribution','LogNormalDistribution','NormalDistribution',
-           'UniformDistribution', 'error', 'default_distribution', 'random_sample', 'ranf',
-           'standard_generator']
+__all__ = ['CreateGenerator','ExponentialDistribution','LogNormalDistribution',
+           'NormalDistribution', 'UniformDistribution', 'error', 'ranf', 
+           'default_distribution', 'random_sample', 'standard_generator']
 
 import numpy.random.mtrand as mt
 import math
@@ -44,7 +44,7 @@
             return 0.0
         else:
             lambda_ = self._args[0]
-            return lambda_*exp(-lambda_*x)
+            return lambda_*math.exp(-lambda_*x)
 
 class LogNormalDistribution(Distribution):
     def __init__(self, m, s):
@@ -61,7 +61,7 @@
     def density(x):
         m,s = self._args
         y = (math.log(x)-self._mn)/self._sn
-        return self._fac*exp(-0.5*y*y)/x
+        return self._fac*math.exp(-0.5*y*y)/x
 
 
 class NormalDistribution(Distribution):
@@ -76,7 +76,7 @@
     def density(x):
         m,s = self._args
         y = (x-m)/s
-        return self._fac*exp(-0.5*y*y)
+        return self._fac*math.exp(-0.5*y*y)
 
 class UniformDistribution(Distribution):
     def __init__(self, a, b):



More information about the Numpy-svn mailing list