diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-05 01:20:56 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-05 01:20:56 +0000 |
commit | 9d8e2024ff9014fa2fd9a29812cec615dff6feb9 (patch) | |
tree | e6353aeb1f9f90e6011ad830a5f3b140b1120435 /numpy/oldnumeric | |
parent | 9d98d9d5e3668d3b8da3bb3019a28d6e945d6fad (diff) | |
download | numpy-9d8e2024ff9014fa2fd9a29812cec615dff6feb9.tar.gz |
More fixes to backward compatibility
Diffstat (limited to 'numpy/oldnumeric')
-rw-r--r-- | numpy/oldnumeric/__init__.py | 24 | ||||
-rw-r--r-- | numpy/oldnumeric/array_printer.py | 16 | ||||
-rw-r--r-- | numpy/oldnumeric/compat.py | 102 | ||||
-rw-r--r-- | numpy/oldnumeric/functions.py (renamed from numpy/oldnumeric/olddefaults.py) | 32 | ||||
-rw-r--r-- | numpy/oldnumeric/ma.py | 11 | ||||
-rw-r--r-- | numpy/oldnumeric/matrix.py | 70 | ||||
-rw-r--r-- | numpy/oldnumeric/misc.py | 3 | ||||
-rw-r--r-- | numpy/oldnumeric/precision.py | 167 | ||||
-rw-r--r-- | numpy/oldnumeric/typeconv.py | 28 | ||||
-rw-r--r-- | numpy/oldnumeric/ufuncs.py | 18 | ||||
-rw-r--r-- | numpy/oldnumeric/user_array.py | 9 |
11 files changed, 377 insertions, 103 deletions
diff --git a/numpy/oldnumeric/__init__.py b/numpy/oldnumeric/__init__.py index 14895910f..ced329913 100644 --- a/numpy/oldnumeric/__init__.py +++ b/numpy/oldnumeric/__init__.py @@ -2,14 +2,26 @@ # Don't add these to the __all__ variable from numpy import * +def _move_axis_to_0(a, axis): + if axis == 0: + return a + n = len(a.shape) + if axis < 0: + axis += n + axes = range(1, axis+1) + [0,] + range(axis+1, n) + return transpose(a, axes) + # Add these from compat import * -from olddefaults import * from functions import * +from precision import * +from ufuncs import * import compat -import olddefaults +import precision import functions +import misc +import ufuncs import numpy __version__ = numpy.__version__ @@ -17,9 +29,13 @@ del numpy __all__ = ['__version__'] __all__ += compat.__all__ -__all__ += olddefaults.__all__ +__all__ += precision.__all__ __all__ += functions.__all__ +__all__ += ufuncs.__all__ +__all__ += misc.__all__ del compat -del olddefaults del functions +del precision +del ufuncs +del misc diff --git a/numpy/oldnumeric/array_printer.py b/numpy/oldnumeric/array_printer.py new file mode 100644 index 000000000..95f3f42c7 --- /dev/null +++ b/numpy/oldnumeric/array_printer.py @@ -0,0 +1,16 @@ + +__all__ = ['array2string'] + +from numpy import array2string as _array2string + +def array2string(a, max_line_width=None, precision=None, + suppress_small=None, separator=' ', + array_output=0): + if array_output: + prefix="array(" + style=repr + else: + prefix = "" + style=str + return _array2string(a, max_line_width, precision, + suppress_small, separator, prefix, style) diff --git a/numpy/oldnumeric/compat.py b/numpy/oldnumeric/compat.py index fa6ea94c4..ebc978fee 100644 --- a/numpy/oldnumeric/compat.py +++ b/numpy/oldnumeric/compat.py @@ -2,15 +2,7 @@ __all__ = ['NewAxis', 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype', - 'LittleEndian', 'Bool', - 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt', 'UInt', - 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger', - # UnsignedInt64 and Unsigned128 added below if possible - # same for Int64 and Int128, Float128, and Complex128 - 'Int8', 'Int16', 'Int32', - 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex', - 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8', - 'Complex32', 'Complex64', 'Complex8', 'Complex16', + 'LittleEndian', 'sarray', 'arrayrange', 'cross_correlate', 'matrixmultiply', 'outerproduct', 'innerproduct', 'cross_product', 'array_constructor', @@ -19,26 +11,20 @@ __all__ = ['NewAxis', 'dump', 'dumps' ] - -import numpy.core.multiarray as mu +import numpy.core.multiarray as multiarray import numpy.core.umath as um -import numpy.core.numerictypes as nt -from numpy.core.numeric import asarray, array, asanyarray, \ - correlate, outer, concatenate, cross +from numpy.core.numeric import array, correlate, outer, cross from numpy.core.umath import sign, absolute, multiply -import numpy.core.numeric as _nx import sys -_dt_ = nt.sctype2char import types from cPickle import dump, dumps -multiarray = mu - def sarray(a, dtype=None, copy=False): return array(a, dtype, copy) +mu = multiarray #Use this to add a new axis to an array #compatibility only @@ -52,86 +38,6 @@ arraytype = mu.ndarray LittleEndian = (sys.byteorder == 'little') -# backward compatible names from old Precision.py - -Character = 'c' -UnsignedInt8 = _dt_(nt.uint8) -UInt8 = UnsignedInt8 -UnsignedInt16 = _dt_(nt.uint16) -UInt16 = UnsignedInt16 -UnsignedInt32 = _dt_(nt.uint32) -UInt32 = UnsignedInt32 -UnsignedInt = _dt_(nt.uint) -UInt = UnsignedInt - -try: - UnsignedInt64 = _dt_(nt.uint64) -except AttributeError: - pass -else: - UInt64 = UnsignedInt64 - __all__ += ['UnsignedInt64', 'UInt64'] -try: - UnsignedInt128 = _dt_(nt.uint128) -except AttributeError: - pass -else: - UInt128 = UnsignedInt128 - __all__ += ['UnsignedInt128','UInt128'] - -Int8 = _dt_(nt.int8) -Int16 = _dt_(nt.int16) -Int32 = _dt_(nt.int32) - -try: - Int64 = _dt_(nt.int64) -except AttributeError: - pass -else: - __all__ += ['Int64'] - -try: - Int128 = _dt_(nt.int128) -except AttributeError: - pass -else: - __all__ += ['Int128'] - -Bool = _dt_(bool) -Int0 = _dt_(int) -Int = _dt_(int) -Float0 = _dt_(float) -Float = _dt_(float) -Complex0 = _dt_(complex) -Complex = _dt_(complex) -PyObject = _dt_(nt.object_) -Float32 = _dt_(nt.float32) -Float64 = _dt_(nt.float64) - -Float16='f' -Float8='f' -UnsignedInteger='L' -Complex8='F' -Complex16='F' - -try: - Float128 = _dt_(nt.float128) -except AttributeError: - pass -else: - __all__ += ['Float128'] - -Complex32 = _dt_(nt.complex64) -Complex64 = _dt_(nt.complex128) - -try: - Complex128 = _dt_(nt.complex256) -except AttributeError: - pass -else: - __all__ += ['Complex128'] - - from numpy import deprecate # backward compatibility diff --git a/numpy/oldnumeric/olddefaults.py b/numpy/oldnumeric/functions.py index 384261437..a905aa9a7 100644 --- a/numpy/oldnumeric/olddefaults.py +++ b/numpy/oldnumeric/functions.py @@ -1,8 +1,38 @@ -__all__ = ['ones', 'empty', 'identity', 'zeros'] +# Functions that should behave the same as Numeric +import numpy as N import numpy.core.multiarray as mu import numpy.core.numeric as nn from typeconv import convtypecode + +__all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue', + 'cumsum', 'cumproduct'] +__all__ += ['ones', 'empty', 'identity', 'zeros'] + +def take(a, indicies, axis=0): + return N.take(a, indicies, axis) + +def repeat(a, repeats, axis=0): + return N.repeats(a, repeats, axis) + +def sum(x, axis=0): + return N.sum(x, axis) + +def product(x, axis=0): + return N.product(x, axis) + +def sometrue(x, axis=0): + return N.sometrue(x, axis) + +def alltrue(x, axis=0): + return N.alltrue(x, axis) + +def cumsum(x, axis=0): + return N.cumsum(x, axis) + +def cumproduct(x, axis=0): + return N.cumproduct(x, axis) + def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py new file mode 100644 index 000000000..15f23ff34 --- /dev/null +++ b/numpy/oldnumeric/ma.py @@ -0,0 +1,11 @@ + +from numpy.core.ma import getmask as _getmask, nomask as _nomask +from numpy.core.ma import * + +del getmask, nomask + +def getmask(a): + res = _getmask(a) + if res is _nomask: + return None + return res diff --git a/numpy/oldnumeric/matrix.py b/numpy/oldnumeric/matrix.py new file mode 100644 index 000000000..d0a3b888b --- /dev/null +++ b/numpy/oldnumeric/matrix.py @@ -0,0 +1,70 @@ +# This module is for compatibility only. + +__all__ = ['UserArray', 'squeeze', 'Matrix', 'asarray', 'dot', 'k', 'Numeric', 'LinearAlgebra', 'identity', 'multiply', 'types', 'string'] + +import string +import types +import numpy.oldnumeric as Numeric +from user_array import UserArray, asarray +from numpy.oldnumeric import dot, identity, multiply +from mlab import squeeze +import linear_algebra as LinearAlgebra + +from numpy import matrix as Matrix + +# Hidden names that will be the same. + +_table = [None]*256 +for k in range(256): + _table[k] = chr(k) +_table = ''.join(_table) + +_numchars = string.digits + ".-+jeEL" +_todelete = [] +for k in _table: + if k not in _numchars: + _todelete.append(k) +_todelete = ''.join(_todelete) + + +def _eval(astr): + return eval(astr.translate(_table,_todelete)) + +def _convert_from_string(data): + data.find + rows = data.split(';') + newdata = [] + count = 0 + for row in rows: + trow = row.split(',') + newrow = [] + for col in trow: + temp = col.split() + newrow.extend(map(_eval,temp)) + if count == 0: + Ncols = len(newrow) + elif len(newrow) != Ncols: + raise ValueError, "Rows not the same size." + count += 1 + newdata.append(newrow) + return newdata + + +_lkup = {'0':'000', + '1':'001', + '2':'010', + '3':'011', + '4':'100', + '5':'101', + '6':'110', + '7':'111'} + +def _binary(num): + ostr = oct(num) + bin = '' + for ch in ostr[1:]: + bin += _lkup[ch] + ind = 0 + while bin[ind] == '0': + ind += 1 + return bin[ind:] diff --git a/numpy/oldnumeric/misc.py b/numpy/oldnumeric/misc.py new file mode 100644 index 000000000..d6361ef4c --- /dev/null +++ b/numpy/oldnumeric/misc.py @@ -0,0 +1,3 @@ + + +__all__ = ['load', 'sort', 'copy_reg', 'clip', 'putmask', 'Unpickler', 'rank', 'sign', 'shape', 'types', 'array', 'allclose', 'size', 'nonzero', 'asarray', 'reshape', 'argmax', 'choose', 'swapaxes', 'array_str', 'pi', 'ravel', 'math', 'compress', 'concatenate', 'pickle_array', 'around', 'trace', 'vdot', 'transpose', 'array2string', 'diagonal', 'searchsorted', 'put', 'fromfunction', 'copy', 'resize', 'array_repr', 'e', 'argmin', 'StringIO', 'pickle', 'average', 'arange', 'argsort', 'convolve', 'fromstring', 'indices', 'loads', 'Pickler', 'where', 'dot'] diff --git a/numpy/oldnumeric/precision.py b/numpy/oldnumeric/precision.py new file mode 100644 index 000000000..82bcfe2e1 --- /dev/null +++ b/numpy/oldnumeric/precision.py @@ -0,0 +1,167 @@ +# Lifted from Precision.py. This is for compatibility only. Notice that the +# capitalized names have their old character strings + +__all__ = ['Character', 'Complex', 'Float', + 'PrecisionError', 'PyObject', 'Int', 'UInt', + 'UnsignedInteger', 'string', 'typecodes', 'zeros'] + +import string +from olddefaults import zeros + +typecodes = {'Character':'c', 'Integer':'1sil', 'UnsignedInteger':'bwu', 'Float':'fd', 'Complex':'FD'} + +def _get_precisions(typecodes): + lst = [] + for t in typecodes: + lst.append( (zeros( (1,), t ).itemsize*8, t) ) + return lst + +def _fill_table(typecodes, table={}): + for key, value in typecodes.items(): + table[key] = _get_precisions(value) + return table + +_code_table = _fill_table(typecodes) + +class PrecisionError(Exception): + pass + +def _lookup(table, key, required_bits): + lst = table[key] + for bits, typecode in lst: + if bits >= required_bits: + return typecode + raise PrecisionError, key+" of "+str(required_bits)+" bits not available on this system" + +Character = 'c' + +try: + UnsignedInt8 = _lookup(_code_table, "UnsignedInteger", 8) + UInt8 = UnsignedInt8 + __all__.extend(['UnsignedInt8', 'UInt8']) +except(PrecisionError): + pass +try: + UnsignedInt16 = _lookup(_code_table, "UnsignedInteger", 16) + UInt16 = UnsignedInt16 + __all__.extend(['UnsignedInt16', 'UInt16']) +except(PrecisionError): + pass +try: + UnsignedInt32 = _lookup(_code_table, "UnsignedInteger", 32) + UInt32 = UnsignedInt32 + __all__.extend(['UnsignedInt32', 'UInt32']) +except(PrecisionError): + pass +try: + UnsignedInt64 = _lookup(_code_table, "UnsignedInteger", 64) + UInt64 = UnsignedInt64 + __all__.extend(['UnsignedInt64', 'UInt64']) +except(PrecisionError): + pass +try: + UnsignedInt128 = _lookup(_code_table, "UnsignedInteger", 128) + UInt128 = UnsignedInt128 + __all__.extend(['UnsignedInt128', 'UInt128']) +except(PrecisionError): + pass +UnsignedInteger = 'u' +UInt = UnsignedInteger + +try: + Int0 = _lookup(_code_table, 'Integer', 0) + __all__.append('Int0') +except(PrecisionError): + pass +try: + Int8 = _lookup(_code_table, 'Integer', 8) + __all__.append('Int8') +except(PrecisionError): + pass +try: + Int16 = _lookup(_code_table, 'Integer', 16) + __all__.append('Int16') +except(PrecisionError): + pass +try: + Int32 = _lookup(_code_table, 'Integer', 32) + __all__.append('Int32') +except(PrecisionError): + pass +try: + Int64 = _lookup(_code_table, 'Integer', 64) + __all__.append('Int64') +except(PrecisionError): + pass +try: + Int128 = _lookup(_code_table, 'Integer', 128) + __all__.append('Int128') +except(PrecisionError): + pass +Int = 'l' + +try: + Float0 = _lookup(_code_table, 'Float', 0) + __all__.append('Float0') +except(PrecisionError): + pass +try: + Float8 = _lookup(_code_table, 'Float', 8) + __all__.append('Float8') +except(PrecisionError): + pass +try: + Float16 = _lookup(_code_table, 'Float', 16) + __all__.append('Float16') +except(PrecisionError): + pass +try: + Float32 = _lookup(_code_table, 'Float', 32) + __all__.append('Float32') +except(PrecisionError): + pass +try: + Float64 = _lookup(_code_table, 'Float', 64) + __all__.append('Float64') +except(PrecisionError): + pass +try: + Float128 = _lookup(_code_table, 'Float', 128) + __all__.append('Float128') +except(PrecisionError): + pass +Float = 'd' + +try: + Complex0 = _lookup(_code_table, 'Complex', 0) + __all__.append('Complex0') +except(PrecisionError): + pass +try: + Complex8 = _lookup(_code_table, 'Complex', 16) + __all__.append('Complex8') +except(PrecisionError): + pass +try: + Complex16 = _lookup(_code_table, 'Complex', 32) + __all__.append('Complex16') +except(PrecisionError): + pass +try: + Complex32 = _lookup(_code_table, 'Complex', 64) + __all__.append('Complex32') +except(PrecisionError): + pass +try: + Complex64 = _lookup(_code_table, 'Complex', 128) + __all__.append('Complex64') +except(PrecisionError): + pass +try: + Complex128 = _lookup(_code_table, 'Complex', 256) + __all__.append('Complex128') +except(PrecisionError): + pass +Complex = 'D' + +PyObject = 'O' diff --git a/numpy/oldnumeric/typeconv.py b/numpy/oldnumeric/typeconv.py new file mode 100644 index 000000000..850ea621e --- /dev/null +++ b/numpy/oldnumeric/typeconv.py @@ -0,0 +1,28 @@ + +__all__ = ['oldtype2dtype', 'convtypecode'] + +import numpy as N + +oldtype2dtype = {'1': N.dtype(N.byte), + 's': N.dtype(N.short), + 'i': N.dtype(N.intc), + 'l': N.dtype(int), + 'b': N.dtype(N.ubyte), + 'w': N.dtype(N.ushort), + 'u': N.dtype(N.uintc), + 'f': N.dtype(N.single), + 'd': N.dtype(float), + 'F': N.dtype(N.csingle), + 'D': N.dtype(complex), + 'O': N.dtype(object), + 'c': N.dtype('c'), + None:N.dtype(int) + } + +def convtypecode(typecode, dtype=None): + if dtype is None: + try: + dtype = oldtype2dtype[typecode] + except: + dtype = N.dtype(typecode) + return dtype diff --git a/numpy/oldnumeric/ufuncs.py b/numpy/oldnumeric/ufuncs.py new file mode 100644 index 000000000..163be5260 --- /dev/null +++ b/numpy/oldnumeric/ufuncs.py @@ -0,0 +1,18 @@ +__all__ = ['less', 'cosh', 'arcsinh', 'add', 'ceil', 'arctan2', 'floor_divide', + 'fmod', 'hypot', 'logical_and', 'power', 'sinh', 'remainder', 'cos', + 'equal', 'arccos', 'less_equal', 'divide', 'bitwise_or', 'bitwise_and', + 'logical_xor', 'log', 'subtract', 'invert', 'negative', 'log10', 'arcsin', + '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'] + +from numpy import less, cosh, arcsinh, add, ceil, arctan2, floor_divide, \ + fmod, hypot, logical_and, power, sinh, remainder, cos, \ + equal, arccos, less_equal, divide, bitwise_or, bitwise_and, \ + logical_xor, log, subtract, invert, negative, log10, arcsin, \ + 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 + diff --git a/numpy/oldnumeric/user_array.py b/numpy/oldnumeric/user_array.py new file mode 100644 index 000000000..d7975d8a7 --- /dev/null +++ b/numpy/oldnumeric/user_array.py @@ -0,0 +1,9 @@ + + +from numpy.oldnumeric import * +from numpy.lib.user_array import container as UserArray + +import numpy.oldnumeric as nold +__all__ = nold.__all__ +__all__ += ['UserArray'] +del nold |