[Scipy-svn] r3367 - in trunk/scipy/ndimage: . src tests

scipy-svn@scip... scipy-svn@scip...
Mon Sep 24 09:34:07 CDT 2007


Author: stefan
Date: 2007-09-24 09:33:35 -0500 (Mon, 24 Sep 2007)
New Revision: 3367

Modified:
   trunk/scipy/ndimage/measurements.py
   trunk/scipy/ndimage/src/ni_measure.c
   trunk/scipy/ndimage/tests/test_ndimage.py
Log:
Some systems have DBL_MIN defined as 0.  Changed to use -DBL_MAX
instead.  Fixes ticket #501.


Modified: trunk/scipy/ndimage/measurements.py
===================================================================
--- trunk/scipy/ndimage/measurements.py	2007-09-23 19:17:48 UTC (rev 3366)
+++ trunk/scipy/ndimage/measurements.py	2007-09-24 14:33:35 UTC (rev 3367)
@@ -197,12 +197,13 @@
     return _nd_image.statistics(input, labels, index, 3)
 
 
-def maximum(input, labels = None, index = None):
-    """Calculate the maximum of the values of the array.
+def maximum(input, labels=None, index=None):
+    """Return the maximum input value.
 
     The index parameter is a single label number or a sequence of
     label numbers of the objects to be measured. If index is None, all
     values are used where labels is larger than zero.
+
     """
     input = numpy.asarray(input)
     if numpy.iscomplexobj(input):

Modified: trunk/scipy/ndimage/src/ni_measure.c
===================================================================
--- trunk/scipy/ndimage/src/ni_measure.c	2007-09-23 19:17:48 UTC (rev 3366)
+++ trunk/scipy/ndimage/src/ni_measure.c	2007-09-24 14:33:35 UTC (rev 3367)
@@ -545,7 +545,7 @@
     if (minimum)
       minimum[jj] = DBL_MAX;
     if (maximum)
-      maximum[jj] = DBL_MIN;
+      maximum[jj] = -DBL_MAX;
     if (min_pos)
       min_pos[jj] = 0;
     if (max_pos)
@@ -576,7 +576,7 @@
         if (min_pos)
           min_pos[idx] = jj;
       }
-      if (maximum && val > maximum[idx]) {
+      if (maximum && (val > maximum[idx])) {
         maximum[idx] = val;
         if (max_pos)
           max_pos[idx] = jj;
@@ -596,7 +596,7 @@
   }
   if (maximum) {
     for(jj = 0; jj < n_results; jj++) {
-      if (!(maximum[jj] > DBL_MIN))
+      if (!(maximum[jj] > -DBL_MAX))
         maximum[jj] = 0.0;
     }
   }

Modified: trunk/scipy/ndimage/tests/test_ndimage.py
===================================================================
--- trunk/scipy/ndimage/tests/test_ndimage.py	2007-09-23 19:17:48 UTC (rev 3366)
+++ trunk/scipy/ndimage/tests/test_ndimage.py	2007-09-24 14:33:35 UTC (rev 3367)
@@ -2933,6 +2933,11 @@
                                                index = [2, 3, 8])
             self.failUnless(output == [3.0, 4.0, 0.0])
 
+    def test_maximum05(self):
+        "Ticket #501"
+        x = numpy.array([-3,-2,-1])
+        assert_equal(ndimage.maximum(x),-1)
+
     def test_variance01(self):
         "variance 1"
         for type in self.types:



More information about the Scipy-svn mailing list