commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r321508 - in /jakarta/commons/proper/math/branches/MATH_1_1: ./ src/java/org/apache/commons/math/stat/descriptive/rank/ src/test/org/apache/commons/math/stat/ src/test/org/apache/commons/math/stat/descriptive/rank/ xdocs/
Date Sat, 15 Oct 2005 22:16:36 GMT
Author: psteitz
Date: Sat Oct 15 15:16:28 2005
New Revision: 321508

URL: http://svn.apache.org/viewcvs?rev=321508&view=rev
Log:
Fixed incorrect NaN handling in o.a.m.s.d.rank.Min, Max
PR# 37019
Reported by Mark Osborn
Patch provided by Mauro Talevi

Modified:
    jakarta/commons/proper/math/branches/MATH_1_1/project.xml
    jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Max.java
    jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Min.java
    jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
    jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MaxTest.java
    jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MinTest.java
    jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml

Modified: jakarta/commons/proper/math/branches/MATH_1_1/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/project.xml?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/project.xml (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/project.xml Sat Oct 15 15:16:28 2005
@@ -152,6 +152,9 @@
       <name>Christopher Schuck</name>
     </contributor>
     <contributor>
+      <name>Mauro Talevi</name>
+    </contributor>
+    <contributor>
       <name>Kim van der Linde</name>
     </contributor>
     <contributor>

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Max.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Max.java?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Max.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Max.java
Sat Oct 15 15:16:28 2005
@@ -112,7 +112,9 @@
         if (test(values, begin, length)) {
             max = values[begin];
             for (int i = begin; i < begin + length; i++) {
-                max = (max > values[i]) ? max : values[i];
+                if (!Double.isNaN(values[i])) {
+                    max = (max > values[i]) ? max : values[i];
+                }
             }
         }
         return max;

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Min.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Min.java?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Min.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/descriptive/rank/Min.java
Sat Oct 15 15:16:28 2005
@@ -114,7 +114,9 @@
         if (test(values, begin, length)) {
             min = values[begin];
             for (int i = begin; i < begin + length; i++) {
-                min = (min < values[i]) ? min : values[i];
+                if (!Double.isNaN(values[i])) {
+                    min = (min < values[i]) ? min : values[i];
+                }
             }
         }
         return min;

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
Sat Oct 15 15:16:28 2005
@@ -42,6 +42,7 @@
     private double skewness = 0;
     private double kurtosis = 0.5;
     private double tolerance = 10E-15;
+    private double nan = Double.NaN;
 
     public StatUtilsTest(String name) {
         super(name);
@@ -296,6 +297,22 @@
         // test many
         x = new double[] {one, two, two, three};
         TestUtils.assertEquals(three, StatUtils.max(x, 1, 3), tolerance);
+
+        // test first nan is ignored
+        x = new double[] {nan, two, three};
+        TestUtils.assertEquals(three, StatUtils.max(x), tolerance);
+
+        // test middle nan is ignored
+        x = new double[] {one, nan, three};
+        TestUtils.assertEquals(three, StatUtils.max(x), tolerance);
+        
+        // test last nan is ignored
+        x = new double[] {one, two, nan};
+        TestUtils.assertEquals(two, StatUtils.max(x), tolerance);
+
+        // test all nan returns nan
+        x = new double[] {nan, nan, nan};
+        TestUtils.assertEquals(nan, StatUtils.max(x), tolerance);
     }
     
     public void testMin() {
@@ -319,6 +336,22 @@
         // test many
         x = new double[] {one, two, two, three};
         TestUtils.assertEquals(two, StatUtils.min(x, 1, 3), tolerance);
+
+        // test first nan is ignored
+        x = new double[] {nan, two, three};
+        TestUtils.assertEquals(two, StatUtils.min(x), tolerance);
+
+        // test middle nan is ignored
+        x = new double[] {one, nan, three};
+        TestUtils.assertEquals(one, StatUtils.min(x), tolerance);
+        
+        // test last nan is ignored
+        x = new double[] {one, two, nan};
+        TestUtils.assertEquals(one, StatUtils.min(x), tolerance);
+
+        // test all nan returns nan
+        x = new double[] {nan, nan, nan};
+        TestUtils.assertEquals(nan, StatUtils.min(x), tolerance);
     }
     
     public void testPercentile() {

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MaxTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MaxTest.java?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MaxTest.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MaxTest.java
Sat Oct 15 15:16:28 2005
@@ -72,4 +72,13 @@
         assertEquals(Double.POSITIVE_INFINITY, max.evaluate(testArray), 0);     
     }
 
+    public void testNaNs() {
+        Max max = new Max();
+        double nan = Double.NaN;
+        assertEquals(3d, max.evaluate(new double[]{nan, 2d, 3d}), 0);     
+        assertEquals(3d, max.evaluate(new double[]{1d, nan, 3d}), 0);     
+        assertEquals(2d, max.evaluate(new double[]{1d, 2d, nan}), 0);     
+        assertTrue(Double.isNaN(max.evaluate(new double[]{nan, nan, nan})));     
+    }
+
 }

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MinTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MinTest.java?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MinTest.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/MinTest.java
Sat Oct 15 15:16:28 2005
@@ -72,4 +72,13 @@
         assertEquals(Double.NEGATIVE_INFINITY, min.evaluate(testArray), 0);     
     }
 
+    public void testNaNs() {
+        Min min = new Min();
+        double nan = Double.NaN;
+        assertEquals(2d, min.evaluate(new double[]{nan, 2d, 3d}), 0);     
+        assertEquals(1d, min.evaluate(new double[]{1d, nan, 3d}), 0);     
+        assertEquals(1d, min.evaluate(new double[]{1d, 2d, nan}), 0);     
+        assertTrue(Double.isNaN(min.evaluate(new double[]{nan, nan, nan})));     
+    }
+    
 }

Modified: jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml?rev=321508&r1=321507&r2=321508&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml Sat Oct 15 15:16:28 2005
@@ -45,6 +45,9 @@
        and numerical utilities, and a PRNG pluggability framework making it
        possible to replace the JDK-supplied random number generator in
        commons-math (and elsewhere) with alternative PRNG implementations.">
+      <action dev="psteitz" type="fix" issue="37019" due-to="Mauro Talevi">
+        Fixed incorrect NaN handling in o.a.m.s.d.rank.Min, Max
+      </action>
       <action dev="psteitz" type="fix" issue="36491">
        Changed RealMatrixImpl.equals to use Double.doubleToLongBits to compare
        corresponding matrix entries.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message