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

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Sep 15 21:09:03 CDT 2006


Author: oliphant
Date: 2006-09-15 21:08:59 -0500 (Fri, 15 Sep 2006)
New Revision: 3169

Modified:
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/lib/twodim_base.py
   trunk/numpy/lib/utils.py
   trunk/numpy/numarray/functions.py
Log:
Fix ticket #188 by returning the name of the dtype objects for data-type objects without fields or sub-arrays that are in correct byte-order

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-15 22:58:26 UTC (rev 3168)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-16 02:08:59 UTC (rev 3169)
@@ -11086,6 +11086,12 @@
                 PyObject *p;
                 PyObject *t = PyString_FromString("(");
                 p = arraydescr_str(self->subarray->base);
+                if (!self->subarray->base->names && !self->subarray->base->subarray) {
+                        PyObject *t=PyString_FromString("'");
+                        PyString_Concat(&p, t);
+                        PyString_ConcatAndDel(&t, p);
+                        p = t;
+                }
                 PyString_ConcatAndDel(&t, p);
                 PyString_ConcatAndDel(&t, PyString_FromString(","));
                 PyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));
@@ -11093,11 +11099,12 @@
                 sub = t;
         }
         else {
-                PyObject *t=PyString_FromString("'");
-                sub = arraydescr_protocol_typestr_get(self);
-                PyString_Concat(&sub, t);
-                PyString_ConcatAndDel(&t, sub);
-                sub = t;
+                if (!PyArray_ISNBO(self->byteorder)) {
+                        sub = arraydescr_protocol_typestr_get(self);
+                }
+                else {
+                        sub = arraydescr_typename_get(self);
+                }
         }
         return sub;
 }
@@ -11108,6 +11115,12 @@
         PyObject *sub, *s;
         s = PyString_FromString("dtype(");
         sub = arraydescr_str(self);
+        if (!self->names && !self->subarray) {
+                PyObject *t=PyString_FromString("'");
+                PyString_Concat(&sub, t);
+                PyString_ConcatAndDel(&t, sub);
+                sub = t;
+        }
         PyString_ConcatAndDel(&s, sub);
         sub = PyString_FromString(")");
         PyString_ConcatAndDel(&s, sub);

Modified: trunk/numpy/lib/twodim_base.py
===================================================================
--- trunk/numpy/lib/twodim_base.py	2006-09-15 22:58:26 UTC (rev 3168)
+++ trunk/numpy/lib/twodim_base.py	2006-09-16 02:08:59 UTC (rev 3169)
@@ -143,7 +143,7 @@
         X[:,i] = x**(N-i-1)
     return X
 
-def  histogram2d(x,y, bins=10, range=None, normed=False):
+def histogram2d(x,y, bins=10, range=None, normed=False):
     """histogram2d(x,y, bins=10, range=None, normed=False) -> H, xedges, yedges
     
     Compute the 2D histogram from samples x,y. 
@@ -159,7 +159,6 @@
     The histogram array is a count of the number of samples in each 
     two dimensional bin. 
     Setting normed to True returns a density rather than a bin count. 
-    Data falling outside of the edges are not counted.
     """
     import numpy as np
     try:

Modified: trunk/numpy/lib/utils.py
===================================================================
--- trunk/numpy/lib/utils.py	2006-09-15 22:58:26 UTC (rev 3168)
+++ trunk/numpy/lib/utils.py	2006-09-16 02:08:59 UTC (rev 3169)
@@ -238,7 +238,10 @@
 
     if object is None:
         info(info)
-    elif isinstance(object, types.StringType):
+    elif isinstance(object, ndarray):
+        import numpy.numarray as nn
+        nn.info(object, output=output, numpy=1)
+    elif isinstance(object, str):
         if _namedict is None:
             _namedict, _dictlist = _makenamedict(toplevel)
         numfound = 0

Modified: trunk/numpy/numarray/functions.py
===================================================================
--- trunk/numpy/numarray/functions.py	2006-09-15 22:58:26 UTC (rev 3168)
+++ trunk/numpy/numarray/functions.py	2006-09-16 02:08:59 UTC (rev 3169)
@@ -340,27 +340,57 @@
     dtype = type2dtype(typecode, type, dtype, True)
     return N.identity(n, dtype)
 
-def info(obj):
-    print "class: ", type(obj)
-    print "shape: ", obj.shape
-    print "strides: ", obj.strides
-    print "byteoffset: 0"
-    print "bytestride: ", obj.strides[0]
-    print "itemsize: ", obj.itemsize
-    print "aligned: ", obj.flags.aligned
-    print "contiguous: ", obj.flags.contiguous
-    print "buffer: ", repr(obj.data)
-    print "data pointer:", obj.ctypes._as_parameter_, "(DEBUG ONLY)"
-    print "byteorder: ",
+def info(obj, output=sys.stdout, numpy=0):
+    if numpy:
+        bp = lambda x: x
+    else:
+        bp = lambda x: int(x)
+    cls = getattr(obj, '__class__', type(obj))
+    if numpy:
+        nm = getattr(cls, '__name__', cls)
+    else:
+        nm = cls
+    print >> output, "class: ", nm
+    print >> output, "shape: ", obj.shape
+    strides = obj.strides
+    print >> output, "strides: ", strides
+    if not numpy:
+        print >> output, "byteoffset: 0"
+        if len(strides) > 0:
+            bs = obj.strides[0]
+        else:
+            bs = obj.itemsize
+        print >> output, "bytestride: ", bs
+    print >> output, "itemsize: ", obj.itemsize
+    print >> output, "aligned: ", bp(obj.flags.aligned)
+    print >> output, "contiguous: ", bp(obj.flags.contiguous)
+    if numpy:
+        print >> output, "fortran: ", obj.flags.fortran
+    if not numpy:
+        print >> output, "buffer: ", repr(obj.data)
+    if not numpy:
+        extra = " (DEBUG ONLY)"
+        tic = "'"
+    else:
+        extra = ""
+        tic = ""
+    print >> output, "data pointer: %s%s" % (hex(obj.ctypes._as_parameter_), extra)
+    print >> output, "byteorder: ",
     endian = obj.dtype.byteorder
     if endian in ['|','=']:
-        print sys.byteorder
+        print >> output, "%s%s%s" % (tic, sys.byteorder, tic)
+        byteswap = False
     elif endian == '>':
-        print "big"
+        print >> output, "%sbig%s" % (tic, tic)
+        byteswap = sys.byteorder != "big"
     else:
-        print "little"
-    print "byteswap: ", not obj.dtype.isnative
-    print "type: ", typefrom(obj).name
+        print >> output, "%slittle%s" % (tic, tic)
+        byteswap = sys.byteorder != "little"
+    print >> output, "byteswap: ", bp(byteswap)
+    if not numpy:
+        print >> output, "type: ", typefrom(obj).name
+    else:
+        print >> output, "type: %s" % obj.dtype
 
 #clipmode is ignored if axis is not 0 and array is not 1d
 def put(array, indices, values, axis=0, clipmode=RAISE):



More information about the Numpy-svn mailing list