diff options
Diffstat (limited to 'numpy/oldnumeric')
-rw-r--r-- | numpy/oldnumeric/alter_code1.py | 26 | ||||
-rw-r--r-- | numpy/oldnumeric/compat.py | 20 | ||||
-rw-r--r-- | numpy/oldnumeric/functions.py | 9 | ||||
-rw-r--r-- | numpy/oldnumeric/misc.py | 7 | ||||
-rw-r--r-- | numpy/oldnumeric/ufuncs.py | 5 |
5 files changed, 46 insertions, 21 deletions
diff --git a/numpy/oldnumeric/alter_code1.py b/numpy/oldnumeric/alter_code1.py index 72cc33acb..ab4ebc04e 100644 --- a/numpy/oldnumeric/alter_code1.py +++ b/numpy/oldnumeric/alter_code1.py @@ -22,6 +22,11 @@ Makes the following changes: 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 @@ _meth1 = ['astype'] _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 @@ for name in _meth1: _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 @@ def changeimports(fstr, name, newname): 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 @@ def replaceother(astr): 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') diff --git a/numpy/oldnumeric/compat.py b/numpy/oldnumeric/compat.py index 69941bb09..98a7f9259 100644 --- a/numpy/oldnumeric/compat.py +++ b/numpy/oldnumeric/compat.py @@ -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.multiarray as multiarray 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,16 +37,10 @@ LittleEndian = (sys.byteorder == 'little') 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) diff --git a/numpy/oldnumeric/functions.py b/numpy/oldnumeric/functions.py index 4c09dfa16..3041a6159 100644 --- a/numpy/oldnumeric/functions.py +++ b/numpy/oldnumeric/functions.py @@ -9,7 +9,7 @@ __all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue', '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 @@ def array(sequence, typecode=None, copy=1, savespace=0, dtype=None): 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 indices(dimensions, typecode=None, dtype=None): 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) diff --git a/numpy/oldnumeric/misc.py b/numpy/oldnumeric/misc.py index c0ccbc7ae..a9bd57264 100644 --- a/numpy/oldnumeric/misc.py +++ b/numpy/oldnumeric/misc.py @@ -8,8 +8,8 @@ __all__ = ['load', 'sort', 'copy_reg', 'clip', 'putmask', 'Unpickler', 'rank', '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 pickle import load, loads 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 diff --git a/numpy/oldnumeric/ufuncs.py b/numpy/oldnumeric/ufuncs.py index 083a5ed66..58fa473a6 100644 --- a/numpy/oldnumeric/ufuncs.py +++ b/numpy/oldnumeric/ufuncs.py @@ -6,7 +6,8 @@ __all__ = ['less', 'cosh', 'arcsinh', 'add', 'ceil', 'arctan2', 'floor_divide', '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 @@ from numpy import less, cosh, arcsinh, add, ceil, arctan2, floor_divide, \ 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 |