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

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Aug 4 20:21:04 CDT 2006


Author: oliphant
Date: 2006-08-04 20:20:56 -0500 (Fri, 04 Aug 2006)
New Revision: 2957

Added:
   trunk/numpy/oldnumeric/array_printer.py
   trunk/numpy/oldnumeric/functions.py
   trunk/numpy/oldnumeric/ma.py
   trunk/numpy/oldnumeric/matrix.py
   trunk/numpy/oldnumeric/misc.py
   trunk/numpy/oldnumeric/precision.py
   trunk/numpy/oldnumeric/typeconv.py
   trunk/numpy/oldnumeric/ufuncs.py
   trunk/numpy/oldnumeric/user_array.py
Removed:
   trunk/numpy/oldnumeric/olddefaults.py
Modified:
   trunk/numpy/oldnumeric/__init__.py
   trunk/numpy/oldnumeric/compat.py
Log:
More fixes to backward compatibility

Modified: trunk/numpy/oldnumeric/__init__.py
===================================================================
--- trunk/numpy/oldnumeric/__init__.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/__init__.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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 @@
 
 __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

Added: trunk/numpy/oldnumeric/array_printer.py
===================================================================
--- trunk/numpy/oldnumeric/array_printer.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/array_printer.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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)

Modified: trunk/numpy/oldnumeric/compat.py
===================================================================
--- trunk/numpy/oldnumeric/compat.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/compat.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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 @@
            '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 @@
 
 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

Added: trunk/numpy/oldnumeric/functions.py
===================================================================
--- trunk/numpy/oldnumeric/functions.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/functions.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -0,0 +1,62 @@
+# 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
+    dimensions which is initialized to all ones.
+    """
+    dtype = convtypecode(typecode,dtype)
+    a = mu.empty(shape, dtype)
+    a.fill(1)
+    return a
+
+def zeros(shape, typecode='l', savespace=0, dtype=None):
+    """zeros(shape, dtype=int) returns an array of the given
+    dimensions which is initialized to all zeros
+    """
+    dtype = convtypecode(typecode,dtype)            
+    return mu.zeros(shape, dtype)
+
+def identity(n,typecode='l', dtype=None):
+    """identity(n) returns the identity 2-d array of shape n x n.
+    """
+    dtype = convtypecode(typecode, dtype)
+    return nn.identity(n, dtype)
+
+def empty(shape, typecode='l', dtype=None):
+    dtype = convtypecode(typecode, dtype)    
+    return mu.empty(shape, dtype, order)
+

Added: trunk/numpy/oldnumeric/ma.py
===================================================================
--- trunk/numpy/oldnumeric/ma.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/ma.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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

Added: trunk/numpy/oldnumeric/matrix.py
===================================================================
--- trunk/numpy/oldnumeric/matrix.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/matrix.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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:]

Added: trunk/numpy/oldnumeric/misc.py
===================================================================
--- trunk/numpy/oldnumeric/misc.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/misc.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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']

Deleted: trunk/numpy/oldnumeric/olddefaults.py
===================================================================
--- trunk/numpy/oldnumeric/olddefaults.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/olddefaults.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -1,32 +0,0 @@
-__all__ = ['ones', 'empty', 'identity', 'zeros']
-
-import numpy.core.multiarray as mu
-import numpy.core.numeric as nn
-from typeconv import convtypecode
-    
-def ones(shape, typecode='l', savespace=0, dtype=None):
-    """ones(shape, dtype=int) returns an array of the given
-    dimensions which is initialized to all ones.
-    """
-    dtype = convtypecode(typecode,dtype)
-    a = mu.empty(shape, dtype)
-    a.fill(1)
-    return a
-
-def zeros(shape, typecode='l', savespace=0, dtype=None):
-    """zeros(shape, dtype=int) returns an array of the given
-    dimensions which is initialized to all zeros
-    """
-    dtype = convtypecode(typecode,dtype)            
-    return mu.zeros(shape, dtype)
-
-def identity(n,typecode='l', dtype=None):
-    """identity(n) returns the identity 2-d array of shape n x n.
-    """
-    dtype = convtypecode(typecode, dtype)
-    return nn.identity(n, dtype)
-
-def empty(shape, typecode='l', dtype=None):
-    dtype = convtypecode(typecode, dtype)    
-    return mu.empty(shape, dtype, order)
-

Added: trunk/numpy/oldnumeric/precision.py
===================================================================
--- trunk/numpy/oldnumeric/precision.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/precision.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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'

Added: trunk/numpy/oldnumeric/typeconv.py
===================================================================
--- trunk/numpy/oldnumeric/typeconv.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/typeconv.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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

Added: trunk/numpy/oldnumeric/ufuncs.py
===================================================================
--- trunk/numpy/oldnumeric/ufuncs.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/ufuncs.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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
+ 

Added: trunk/numpy/oldnumeric/user_array.py
===================================================================
--- trunk/numpy/oldnumeric/user_array.py	2006-08-04 23:38:27 UTC (rev 2956)
+++ trunk/numpy/oldnumeric/user_array.py	2006-08-05 01:20:56 UTC (rev 2957)
@@ -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



More information about the Numpy-svn mailing list