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

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Aug 5 14:02:37 EDT 2006


Author: oliphant
Date: 2006-08-05 13:02:33 -0500 (Sat, 05 Aug 2006)
New Revision: 2969

Modified:
   trunk/numpy/oldnumeric/alter_code1.py
   trunk/numpy/oldnumeric/compat.py
   trunk/numpy/oldnumeric/functions.py
   trunk/numpy/oldnumeric/misc.py
   trunk/numpy/oldnumeric/ufuncs.py
Log:
Un-deprecate some names in Numeric.

Modified: trunk/numpy/oldnumeric/alter_code1.py
===================================================================
--- trunk/numpy/oldnumeric/alter_code1.py	2006-08-05 17:00:03 UTC (rev 2968)
+++ trunk/numpy/oldnumeric/alter_code1.py	2006-08-05 18:02:33 UTC (rev 2969)
@@ -22,6 +22,11 @@
 
    and methods:
    astype --- only argument
+    -- converts uses of '1', 's', 'w', and 'u' to
+    -- 'b', 'h', 'H', and 'I'
+
+ * Converts uses of type(...) is <type>
+   isinstance(..., <type>)
 """
 __all__ = ['fromfile', 'fromstr']
 
@@ -36,7 +41,10 @@
 _func2 = ['ones', 'zeros', 'identity', 'fromstring', 'indices',
          'empty', 'array', 'asarray', 'arange', 'array_constructor']
 
+_chars = {'1':'b','s':'h','w':'H','u':'I'}
+
 func_re = {}
+meth_re = {}
 
 for name in _func2:
     _astr = r"""(%s\s*[(][^,]*?[,][^'"]*?['"])b(['"][^)]*?[)])"""%name
@@ -50,9 +58,15 @@
     _astr = r"""(.%s\s*[(][^'"]*?['"])b(['"][^)]*?[)])"""%name
     func_re[name] = re.compile(_astr, re.DOTALL)
 
+for char in _chars.keys():
+    _astr = r"""(.astype\s*[(][^'"]*?['"])%s(['"][^)]*?[)])"""%char
+    meth_re[char] = re.compile(_astr, re.DOTALL)
+
 def fixtypechars(fstr):
     for name in _func2 + _func4 + _meth1:
         fstr = func2_re[name].sub('\\1B\\2',fstr)
+    for char in _chars.keys():
+        fstr = meth_re[char].sub('\\1%s\\2'%_chars[char], fstr)
     return fstr
 
 flatindex_re = re.compile('([.]flat(\s*?[[=]))')
@@ -80,6 +94,17 @@
         ind += Nlen2 - Nlen
     return fstr, fromall
 
+istest_re = {}
+_types = ['float', 'int', 'complex', 'ArrayType', 'FloatType',
+          'IntType', 'ComplexType']
+for name in _types:
+    _astr = r'type\s*[(]([^)]*)[)]\s+(?:is|==)\s+(.*?%s)'%name
+    istest_re[name] = re.compile(_astr)
+def fixistesting(astr):
+    for name in _types:
+        astr = istest_re[name].sub('isinstance(\\1, \\2)', astr)
+    return astr
+
 def replaceattr(astr):
     astr = astr.replace(".typecode()",".dtype.char")
     astr = astr.replace(".iscontiguous()",".flags.contiguous")
@@ -106,6 +131,7 @@
 import datetime
 def fromstr(filestr):
     filestr = fixtypechars(filestr)
+    filestr = fixistesting(filestr)
     filestr, fromall1 = changeimports(filestr, 'Numeric', 'numpy.oldnumeric')
     filestr, fromall1 = changeimports(filestr, 'multiarray','numpy.oldnumeric')
     filestr, fromall1 = changeimports(filestr, 'umath', 'numpy.oldnumeric')

Modified: trunk/numpy/oldnumeric/compat.py
===================================================================
--- trunk/numpy/oldnumeric/compat.py	2006-08-05 17:00:03 UTC (rev 2968)
+++ trunk/numpy/oldnumeric/compat.py	2006-08-05 18:02:33 UTC (rev 2969)
@@ -2,11 +2,9 @@
 
 __all__ = ['NewAxis',
            'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',
-           'LittleEndian',
-           'sarray', 'arrayrange', 'cross_correlate',
-           'matrixmultiply', 'outerproduct', 'innerproduct',
-           'cross_product', 'array_constructor', 'pickle_array',
-           'DumpArray', 'LoadArray', 'multiarray', 'divide_safe',
+           'LittleEndian', 'arrayrange', 'matrixmultiply', 
+           'array_constructor', 'pickle_array',
+           'DumpArray', 'LoadArray', 'multiarray',
            # from cPickle
            'dump', 'dumps'
           ]
@@ -15,15 +13,13 @@
 import numpy.core.umath as um
 from numpy.core.numeric import array, correlate, outer, cross
 from numpy.core.umath import sign, absolute, multiply
+import functions
 import sys
 
 import types
 
 from cPickle import dump, dumps
 
-def sarray(a, dtype=None, copy=False):
-    return array(a, dtype, copy)
-
 mu = multiarray
 
 #Use this to add a new axis to an array
@@ -41,17 +37,11 @@
 from numpy import deprecate 
 
 # backward compatibility
-arrayrange = deprecate(mu.arange, 'arrayrange', 'arange')
-cross_correlate = deprecate(correlate, 'cross_correlate', 'correlate')
-cross_product = deprecate(cross, 'cross_product', 'cross')
-divide_safe = deprecate(um.divide, 'divide_safe', 'divide')
+arrayrange = deprecate(functions.arange, 'arrayrange', 'arange')
 
 # deprecated names
 matrixmultiply = deprecate(mu.dot, 'matrixmultiply', 'dot')
-outerproduct = deprecate(outer, 'outerproduct', 'outer')
-innerproduct = deprecate(mu.inner, 'innerproduct', 'inner')
 
-
 def DumpArray(m, fp):
     m.dump(fp)
 

Modified: trunk/numpy/oldnumeric/functions.py
===================================================================
--- trunk/numpy/oldnumeric/functions.py	2006-08-05 17:00:03 UTC (rev 2968)
+++ trunk/numpy/oldnumeric/functions.py	2006-08-05 18:02:33 UTC (rev 2969)
@@ -9,7 +9,7 @@
            'cumsum', 'cumproduct',
            'ones', 'empty', 'identity', 'zeros', 'array', 'asarray',
            'nonzero', 'reshape', 'arange', 'fromstring', 'ravel', 'trace',
-           'indices', 'where']
+           'indices', 'where','sarray','cross_product']
 
 def take(a, indicies, axis=0):
     return N.take(a, indicies, axis)
@@ -65,6 +65,10 @@
     dtype = convtypecode2(typecode, dtype)
     return mu.array(sequence, dtype, copy=copy)
 
+def sarray(a, typecode=None, copy=False, dtype=None):
+    dtype = convtypecode2(typecode, dtype)
+    return mu.array(a, dtype, copy)
+
 def asarray(a, typecode=None, dtype=None):
     dtype = convtypecode2(typecode, dtype)
     return mu.array(a, dtype, copy=0)
@@ -99,3 +103,6 @@
 
 def where(condition, x, y):
     return N.where(condition, x, y)
+
+def cross_product(a, b, axis1=-1, axis2=-1):
+    return N.cross(a, b, axis1, axis2)

Modified: trunk/numpy/oldnumeric/misc.py
===================================================================
--- trunk/numpy/oldnumeric/misc.py	2006-08-05 17:00:03 UTC (rev 2968)
+++ trunk/numpy/oldnumeric/misc.py	2006-08-05 18:02:33 UTC (rev 2969)
@@ -8,8 +8,8 @@
            'around', 'vdot', 'transpose', 'array2string', 'diagonal',
            'searchsorted', 'put', 'fromfunction', 'copy', 'resize',
            'array_repr', 'e', 'argmin', 'StringIO', 'pickle', 'average',
-           'argsort', 'convolve', 'loads',
-           'Pickler', 'dot']
+           'argsort', 'convolve', 'loads', 'cross_correlate',
+           'Pickler', 'dot', 'outerproduct', 'innerproduct']
 
 import types
 import StringIO
@@ -22,7 +22,8 @@
 from numpy import sort, clip, putmask, rank, sign, shape, allclose, size,\
      argmax, choose, swapaxes, array_str, array_repr, argmin, e, pi, \
      fromfunction, resize, around, compress, concatenate, vdot, transpose, \
-     diagonal, searchsorted, put, average, argsort, convolve, dot
+     diagonal, searchsorted, put, average, argsort, convolve, dot, \
+     outer as outerproduct, inner as innerproduct, correlate as cross_correlate
 
 from array_printer import array2string
 

Modified: trunk/numpy/oldnumeric/ufuncs.py
===================================================================
--- trunk/numpy/oldnumeric/ufuncs.py	2006-08-05 17:00:03 UTC (rev 2968)
+++ trunk/numpy/oldnumeric/ufuncs.py	2006-08-05 18:02:33 UTC (rev 2969)
@@ -6,7 +6,8 @@
            'not_equal', 'tanh', 'true_divide', 'maximum', 'arccosh',
            'logical_or', 'minimum', 'conjugate', 'tan', 'greater',
            'bitwise_xor', 'fabs', 'floor', 'sqrt', 'arctan', 'right_shift',
-           'absolute', 'sin', 'multiply', 'greater_equal', 'left_shift', 'exp']
+           'absolute', 'sin', 'multiply', 'greater_equal', 'left_shift',
+           'exp', 'divide_safe']
 
 from numpy import less, cosh, arcsinh, add, ceil, arctan2, floor_divide, \
      fmod, hypot, logical_and, power, sinh, remainder, cos, \
@@ -15,5 +16,5 @@
      arctanh, logical_not, not_equal, tanh, true_divide, maximum, \
      arccosh, logical_or, minimum, conjugate, tan, greater, bitwise_xor, \
      fabs, floor, sqrt, arctan, right_shift, absolute, sin, \
-     multiply, greater_equal, left_shift, exp
+     multiply, greater_equal, left_shift, exp, divide as divide_safe
  




More information about the Numpy-svn mailing list