[Numpy-svn] r2975 - in trunk/numpy: core/src numarray

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Aug 8 02:49:16 CDT 2006


Author: oliphant
Date: 2006-08-08 02:49:10 -0500 (Tue, 08 Aug 2006)
New Revision: 2975

Added:
   trunk/numpy/numarray/compat.py
   trunk/numpy/numarray/functions.py
   trunk/numpy/numarray/ufuncs.py
Removed:
   trunk/numpy/numarray/numclass.py
Modified:
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/numarray/__init__.py
   trunk/numpy/numarray/alter_code1.py
   trunk/numpy/numarray/numerictypes.py
Log:
Add numarray compatibility.

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-08-08 07:49:10 UTC (rev 2975)
@@ -4377,12 +4377,13 @@
 		}
 		return PY_SUCCEED;
 	}
-        else goto fail; /*{
+	else if (PyArray_Check(obj)) goto fail;
+        else /* goto fail;*/ {
 		*at = _arraydescr_fromobj(obj);
 		if (*at) return PY_SUCCEED;
 		if (PyErr_Occurred()) return PY_FAIL;
 		goto fail;
-		} */
+	}
 	if (PyErr_Occurred()) goto fail;
 
 	/*

Modified: trunk/numpy/numarray/__init__.py
===================================================================
--- trunk/numpy/numarray/__init__.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/__init__.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -1,5 +1,22 @@
 from util import *
-from numclass import *
+from numerictypes import *
+from functions import *
+from ufuncs import *
 
+import util
+import numerictypes
+import functions
+import ufuncs
+import compat
+
 __all__ = util.__all__
-__all__ += numclass.__all__
+__all__ += numerictypes.__all__
+__all__ += functions.__all__
+__all__ += ufuncs.__all__
+__all__ += compat.__all__
+
+del util
+del numerictypes
+del functions
+del ufuncs
+del compat

Modified: trunk/numpy/numarray/alter_code1.py
===================================================================
--- trunk/numpy/numarray/alter_code1.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/alter_code1.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -28,7 +28,7 @@
    - self.new(type) --> empty(self.shape, type)
    - .repeat(r) --> .repeat(r, axis=0)
    - .size() --> .size
-   - .type() -- numarray.type(self.dtype)
+   - .type() -- numarray.typefrom(self)
    - .typecode() --> .dtype.char
    - .stddev() --> .std()
    - .togglebyteorder() --> self.dtype=self.dtype.newbyteorder()

Added: trunk/numpy/numarray/compat.py
===================================================================
--- trunk/numpy/numarray/compat.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/compat.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -0,0 +1,6 @@
+
+__all__ = ['NewAxis']
+
+from numpy import newaxis
+
+NewAxis = newaxis

Added: trunk/numpy/numarray/functions.py
===================================================================
--- trunk/numpy/numarray/functions.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/functions.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -0,0 +1,86 @@
+
+# missing Numarray defined names (in from numarray import *)
+##__all__ = ['ArrayType', 'CLIP', 'ClassicUnpickler', 'Complex32_fromtype',
+##           'Complex64_fromtype', 'ComplexArray', 'EarlyEOFError', 'Error',
+##           'FileSeekWarning', 'MAX_ALIGN', 'MAX_INT_SIZE', 'MAX_LINE_WIDTH',
+##           'MathDomainError', 'NDArray', 'NewArray', 'NewAxis', 'NumArray',
+##           'NumError', 'NumOverflowError', 'PRECISION', 'Py2NumType',
+##           'PyINT_TYPES', 'PyLevel2Type', 'PyNUMERIC_TYPES', 'PyREAL_TYPES',
+##           'RAISE', 'SLOPPY', 'STRICT', 'SUPPRESS_SMALL', 'SizeMismatchError',
+##           'SizeMismatchWarning', 'SuitableBuffer', 'USING_BLAS',
+##           'UnderflowError', 'UsesOpPriority', 'WARN', 'WRAP', 'all',
+##           'allclose', 'alltrue', 'and_', 'any', 'arange', 'argmax',
+##           'argmin', 'argsort', 'around', 'array2list', 'array_equal',
+##           'array_equiv', 'array_repr', 'array_str', 'arrayprint',
+##           'arrayrange', 'average', 'choose', 'clip',
+##           'codegenerator', 'compress', 'concatenate', 'conjugate',
+##           'copy', 'copy_reg', 'diagonal', 'divide_remainder',
+##           'dotblas', 'e', 'explicit_type', 'flush_caches', 'fromfile',
+##           'fromfunction', 'fromlist', 'fromstring', 'generic',
+##           'genericCoercions', 'genericPromotionExclusions', 'genericTypeRank',
+##           'getShape', 'getTypeObject', 'handleError', 'identity', 'indices',
+##           'info', 'innerproduct', 'inputarray', 'isBigEndian',
+##           'kroneckerproduct', 'lexsort', 'libnumarray', 'libnumeric',
+##           'load', 'make_ufuncs', 'math', 'memory',
+##           'numarrayall', 'numarraycore', 'numerictypes', 'numinclude',
+##           'operator', 'os', 'outerproduct', 'pi', 'put', 'putmask',
+##           'pythonTypeMap', 'pythonTypeRank', 'rank', 'repeat',
+##           'reshape', 'resize', 'round', 'safethread', 'save', 'scalarTypeMap',
+##           'scalarTypes', 'searchsorted', 'session', 'shape', 'sign', 'size',
+##           'sometrue', 'sort', 'swapaxes', 'sys', 'take', 'tcode',
+##           'tensormultiply', 'tname', 'trace', 'transpose', 'typeDict',
+##           'typecode', 'typecodes', 'typeconv', 'types', 'ufunc',
+##           'ufuncFactory', 'value', ]
+
+
+__all__ = ['asarray', 'ones', 'zeros', 'array', 'where']
+__all__ += ['vdot', 'dot', 'matrixmultiply', 'ravel', 'indices',
+            'arange', 'concatenate']
+
+from numpy import dot as matrixmultiply, dot, vdot, ravel
+
+def array(sequence=None, typecode=None, copy=1, savespace=0,
+          type=None, shape=None, dtype=None):
+    dtype = type2dtype(typecode, type, dtype)
+    if sequence is None:
+        if shape is None:
+            return None
+        if dtype is None:
+            dtype = 'l'
+        return N.empty(shape, dtype)
+    arr = N.array(sequence, dtype, copy=copy)
+    if shape is not None:
+        arr.shape = shape
+    return arr
+
+def asarray(seq, type=None, typecode=None, dtype=None):
+    if seq is None:
+        return None
+    dtype = type2dtype(typecode, type, dtype)
+    return N.array(seq, dtype, copy=0)
+
+def ones(shape, type=None, typecode=None, dtype=None):
+    dtype = type2dtype(typecode, type, dtype)
+    return N.ones(shape, dtype)
+
+def zeros(shape, type=None, typecode=None, dtype=None):
+    dtype = type2dtype(typecode, type, dtype)
+    return N.zeros(shape, dtype)
+
+def where(condition, x=None, y=None, out=None):
+    if x is None and y is None:
+        arr = N.where(condition)
+    else:
+        arr = N.where(condition, x, y)
+    if out is not None:
+        out[...] = arr
+        return out
+    return arr
+    
+def indices(shape, type=None):
+    return N.indices(shape, type)
+
+def arange(a1, a2=None, stride=1, type=None, shape=None,
+           typecode=None, dtype=None):
+    dtype = type2dtype(typecode, type, dtype)
+    return N.arange(a1, a2, stride, dtype)

Deleted: trunk/numpy/numarray/numclass.py
===================================================================
--- trunk/numpy/numarray/numclass.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/numclass.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -1,133 +0,0 @@
-from numpy.core.multiarray import ndarray
-import numerictypes as _nt
-import numpy as N
-import sys as _sys
-
-__all__ = ['NumArray']
-
-class NumArray(ndarray):
-    def __new__(klass, shape=None, type=None, buffer=None,
-                byteoffset=0, bytestride=None, byteorder=_sys.byteorder,
-                aligned=1, real=None, imag=None):
-
-        type = _nt.getType(type)
-        dtype = N.dtype(type._dtype)
-        if byteorder in ['little', 'big']:
-            if byteorder is not _sys.byteorder:
-                dtype = dtype.newbyteorder()
-        else:
-            raise ValueError("byteorder must be 'little' or 'big'")
-
-        if buffer is None:
-            self = ndarray.__new__(klass, shape, dtype)
-        else:
-            self = ndarray.__new__(klass, shape, dtype, buffer=buffer,
-                                   offset=byteoffset, strides=bytestride)
-            
-        self._type = type
-
-        if real is not None:
-            self.real = real
-
-        if imag is not None:
-            self.imag = imag
-
-        self._byteorder = byteorder
-
-        return self
-
-    def argmax(self, axis=-1):
-        return ndarray.argmax(self, axis)
-
-    def argmin(self, axis=-1):
-        return ndarray.argmax(self, axis)
-
-    def argsort(self, axis=-1, kind='quicksort'):
-        return ndarray.argmax(self, axis, kind)
-
-    def astype(self, type=None):
-        return self.astype(_getdtype(type))
-
-    def byteswap(self):
-        ndarray.byteswap(self, True)
-
-    def byteswapped(self):
-        return ndarray.byteswap(self, False)
-
-    def getdtypechar(self):
-        return self.dtype.char
-
-    def getimag(self):
-        return self.imag
-
-    getimaginary = getimag
-
-    imaginary = property(getimaginary, None, "")
-
-    def getreal(self):
-        return self.real
-
-    def is_c_array(self):
-        return self.dtype.isnative and self.flags.carray
-
-    def is_f_array(self):
-        return self.dtype.isnative and self.flags.farray
-    
-    def is_fortran_contiguous(self):
-        return self.flags.contiguous
-
-    def new(self, type=None):
-        if type is not None:
-            dtype = _getdtype(type)
-            return N.empty(self.shape, dtype)
-        else:
-            return N.empty_like(self)
-
-    def setimag(self, value):
-        self.imag = value
-
-    setimaginary = setimag
-
-    def setreal(self, value):
-        self.real = value
-
-    def sinfo(self):
-        self.info()
-
-    def sort(self, axis=-1, kind='quicksort'):
-        ndarray.sort(self, axis, kind)
-
-    def spacesaver(self):
-        return False
-
-    def stddev(self):
-        return self.std()
-
-    def sum(self, type=None):
-        dtype = _getdtype(type)
-        return ndarray.sum(self, dtype=dtype)
-
-    def togglebyteorder(self):
-        self.dtype = self.dtype.newbyteorder()
-
-    def type(self):
-        return self._type
-
-    def typecode(self):
-        return _numtypecode[self.dtype.char]
-
-    dtypechar = property(getdtypechar, None, "")
-    
-    def info(self):
-        print "class: ", self.__class__
-        print "shape: ", self.shape
-        print "strides: ", self.strides
-        print "byteoffset: 0"
-        print "bytestride: ", self.strides[0]
-        print "itemsize: ", self.itemsize
-        print "aligned: ", self.flags.isaligned
-        print "contiguous: ", self.flags.contiguous
-        print "buffer: ", self.data
-        print "data pointer:", self._as_paramater_
-        print "byteorder: ", self._byteorder
-        print "byteswap: ", not self.dtype.isnative

Modified: trunk/numpy/numarray/numerictypes.py
===================================================================
--- trunk/numpy/numarray/numerictypes.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/numerictypes.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -27,13 +27,25 @@
 $Id: numerictypes.py,v 1.55 2005/12/01 16:22:03 jaytmiller Exp $
 """
 
+__all__ = ['NumericType','HasUInt64','typeDict','IsType',
+           'BooleanType', 'SignedType', 'UnsignedType', 'IntegralType',
+           'SignedIntegralType', 'UnsignedIntegralType', 'FloatingType',
+           'ComplexType', 'AnyType', 'ObjectType', 'Any', 'Object',
+           'Bool', 'Int8', 'Int16', 'Int32', 'Int64', 'Float32',
+           'Float64', 'UInt8', 'UInt16', 'UInt32', 'UInt64',
+           'Complex32', 'Complex64', 'Byte', 'Short', 'Int','Long',
+           'Float', 'Complex', 'genericTypeRank', 'pythonTypeRank',
+           'pythonTypeMap', 'scalarTypeMap', 'genericCoercions',
+           'typecodes', 'genericPromotionExclusions','MaximumType',
+           'getType','scalarTypes', 'typefrom']
+
 MAX_ALIGN = 8
 MAX_INT_SIZE = 8
 
 import numpy
 LP64 = numpy.intp(0).itemsize == 8
 
-HasUInt64 = 0
+HasUInt64 = 1
 try:
     numpy.int64(0)
 except:
@@ -182,6 +194,24 @@
 Complex32  = ComplexType("Complex32", 8,  complex(0.0), _tComplex32)
 Complex64  = ComplexType("Complex64", 16, complex(0.0), _tComplex64)
 
+Object.dtype = 'O'
+Bool.dtype = '?'
+Int8.dtype = 'i1'
+Int16.dtype = 'i2'
+Int32.dtype = 'i4'
+Int64.dtype = 'i8'
+
+UInt8.dtype = 'u1'
+UInt16.dtype = 'u2'
+UInt32.dtype = 'u4'
+UInt64.dtype = 'u8'
+
+Float32.dtype = 'f4'
+Float64.dtype = 'f8'
+
+Complex32.dtype = 'c8'
+Complex64.dtype = 'c16'
+
 # Aliases
 
 Byte = _register("Byte",   Int8)
@@ -192,10 +222,12 @@
     if HasUInt64:
         _register("ULong",  UInt64)
         MaybeLong = _register("MaybeLong", Int64)
+        __all__.append('MaybeLong')
 else:
     Long = _register("Long", Int32)
     _register("ULong", UInt32)
-    MaybeLong = _register("MaybeLong", Int32)    
+    MaybeLong = _register("MaybeLong", Int32)
+    __all__.append('MaybeLong')    
     
 
 _register("UByte",  UInt8)
@@ -280,10 +312,7 @@
                        'Int32', 'UInt32', 'Int64', 'UInt64',
                        'Float32','Float64', 'Complex32', 'Complex64', 'Object']
     
-if _sys.version_info >= (2,3,0):
-    pythonTypeRank = [ bool, int, long, float, complex ]
-else:
-    pythonTypeRank = [ int, long, float, complex ]
+pythonTypeRank = [ bool, int, long, float, complex ]
 
 # The next line is not platform independent XXX Needs to be generalized
 if not LP64:
@@ -311,9 +340,8 @@
         float:"Float64",
         complex:"Complex64"}
 
-if _sys.version_info >= (2,3,0):
-    pythonTypeMap.update({bool:("Bool","bool") })
-    scalarTypeMap.update({bool:"Bool"})
+pythonTypeMap.update({bool:("Bool","bool") })
+scalarTypeMap.update({bool:"Bool"})
 
 # Generate coercion matrix
 
@@ -481,10 +509,7 @@
     except KeyError:
         raise TypeError("Not a numeric type")
 
-if _sys.version_info >= (2,3):
-    scalarTypes = (bool,int,long,float,complex)
-else:
-    scalarTypes = (int,long,float,complex)
+scalarTypes = (bool,int,long,float,complex)
     
 _scipy_dtypechar = {
     Int8 : 'b',
@@ -505,4 +530,7 @@
 for key,value in _scipy_dtypechar.items():
     _scipy_dtypechar_inverse[value] = key
 
-    
+
+def typefrom(obj):
+    return _scipy_dtypechar_inverse[obj.dtype.char]
+

Added: trunk/numpy/numarray/ufuncs.py
===================================================================
--- trunk/numpy/numarray/ufuncs.py	2006-08-08 05:13:02 UTC (rev 2974)
+++ trunk/numpy/numarray/ufuncs.py	2006-08-08 07:49:10 UTC (rev 2975)
@@ -0,0 +1,21 @@
+
+__all__ = ['abs', 'absolute', 'add', 'arccos', 'arccosh', 'arcsin', 'arcsinh',
+           'arctan', 'arctan2', 'arctanh', 'bitwise_and', 'bitwise_not',
+           'bitwise_or', 'bitwise_xor', 'ceil', 'cos', 'cosh', 'cumproduct',
+           'cumsum', 'divide', 'equal', 'exp', 'fabs', 'floor', 'floor_divide',
+           'fmod', 'greater', 'greater_equal', 'hypot', 'ieeemask', 'isnan',
+           'less', 'less_equal', 'log', 'log10', 'logical_and', 'logical_not',
+           'logical_or', 'logical_xor', 'lshift', 'maximum', 'minimum',
+           'minus', 'multiply', 'negative', 'nonzero', 'not_equal',
+           'power', 'product', 'remainder', 'rshift', 'sin', 'sinh', 'sqrt',
+           'subtract', 'sum', 'tan', 'tanh', 'true_divide']
+
+from numpy import abs, absolute, add, arccos, arccosh, arcsin, arcsinh, \
+     arctan, arctan2, arctanh, bitwise_and, bitwise_not, bitwise_or, \
+     bitwise_xor, ceil, cos, cosh, cumproduct, cumsum, divide, equal, \
+     exp, fabs, floor, floor_divide, fmod, greater, greater_equal, hypot, \
+     ieeemask, isnan, less, less_equal, log, log10, logical_and, \
+     logical_not, logical_or, logical_xor, lshift, maximum, minimum, \
+     minus, multiply, negative, nonzero, not_equal, power, product, \
+     remainder, rshift, sin, sinh, sqrt, subtract, sum, tan, tanh, \
+     true_divide



More information about the Numpy-svn mailing list