[Numpy-svn] r6128 - in branches/1.2.x/numpy/ma: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Dec 1 04:48:55 EST 2008


Author: pierregm
Date: 2008-12-01 03:48:53 -0600 (Mon, 01 Dec 2008)
New Revision: 6128

Modified:
   branches/1.2.x/numpy/ma/core.py
   branches/1.2.x/numpy/ma/tests/test_core.py
Log:
Backport of fix from 1.3.x (Fixed make_mask_descr for nested dtypes)

Modified: branches/1.2.x/numpy/ma/core.py
===================================================================
--- branches/1.2.x/numpy/ma/core.py	2008-12-01 09:45:51 UTC (rev 6127)
+++ branches/1.2.x/numpy/ma/core.py	2008-12-01 09:48:53 UTC (rev 6128)
@@ -797,22 +797,27 @@
     Each field is set to a bool.
 
     """
+    def _make_descr(datatype):
+        "Private function allowing recursion."
+        # Do we have some name fields ?
+        names = datatype.names
+        if names:
+            descr = []
+            for name in names:
+                (ndtype, _) = datatype.fields[name]
+                descr.append((name, _make_descr(ndtype)))
+            return descr
+        # Is this some kind of composite a la (np.float,2)
+        elif datatype.subdtype:
+            mdescr = list(datatype.subdtype)
+            mdescr[0] = np.dtype(bool)
+            return tuple(mdescr)
+        else:
+            return np.bool
     # Make sure we do have a dtype
     if not isinstance(ndtype, np.dtype):
         ndtype = np.dtype(ndtype)
-    # Do we have some name fields ?
-    if ndtype.names:
-        mdescr = [list(_) for _ in ndtype.descr]
-        for m in mdescr:
-            m[1] = '|b1'
-        return np.dtype([tuple(_) for _ in mdescr])
-    # Is this some kind of composite a la (np.float,2)
-    elif ndtype.subdtype:
-        mdescr = list(ndtype.subdtype)
-        mdescr[0] = np.dtype(bool)
-        return np.dtype(tuple(mdescr))
-    else:
-        return MaskType
+    return np.dtype(_make_descr(ndtype))
 
 def get_mask(a):
     """Return the mask of a, if any, or nomask.
@@ -3712,7 +3717,6 @@
 anomalies = anom = _frommethod('anom')
 any = _frommethod('any')
 compress = _frommethod('compress')
-conjugate = _frommethod('conjugate')
 cumprod = _frommethod('cumprod')
 cumsum = _frommethod('cumsum')
 copy = _frommethod('copy')
@@ -4211,6 +4215,17 @@
 round = round_
 
 def inner(a, b):
+    """
+    Returns the inner product of a and b for arrays of floating point types.
+
+    Like the generic NumPy equivalent the product sum is over the last dimension
+    of a and b. 
+    
+    Notes
+    -----
+    The first argument is not conjugated.
+
+    """
     fa = filled(a, 0)
     fb = filled(b, 0)
     if len(fa.shape) == 0:
@@ -4261,7 +4276,7 @@
 
 def allclose (a, b, masked_equal=True, rtol=1.e-5, atol=1.e-8, fill_value=None):
     """
-        Returns True if two arrays are element-wise equal within a tolerance.
+    Returns True if two arrays are element-wise equal within a tolerance.
 
     The tolerance values are positive, typically very small numbers.  The
     relative difference (`rtol` * `b`) and the absolute difference (`atol`)

Modified: branches/1.2.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.2.x/numpy/ma/tests/test_core.py	2008-12-01 09:45:51 UTC (rev 6127)
+++ branches/1.2.x/numpy/ma/tests/test_core.py	2008-12-01 09:48:53 UTC (rev 6128)
@@ -2339,8 +2339,18 @@
         ntype = np.float
         test = make_mask_descr(ntype)
         assert_equal(test, np.dtype(np.bool))
+        #
+        ntype = [('a', np.float), ('b', [('ba', np.float), ('bb', np.float)])]
+        test = make_mask_descr(ntype)
+        control = np.dtype([('a', 'b1'), ('b', [('ba', 'b1'), ('bb', 'b1')])])
+        assert_equal(test, control)
+        #
+        ntype = [('a', (np.float, 2))]
+        test = make_mask_descr(ntype)
+        assert_equal(test, np.dtype([('a', (np.bool, 2))]))
 
 
+
     def test_make_mask(self):
         "Test make_mask"
         # w/ a list as an input




More information about the Numpy-svn mailing list