You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2014/09/13 17:46:38 UTC

svn commit: r1624756 - in /commons/proper/math/trunk: pom.xml src/changes/changes.xml src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java

Author: tn
Date: Sat Sep 13 15:46:38 2014
New Revision: 1624756

URL: http://svn.apache.org/r1624756
Log:
[MATH-1145] Fix integer overflows in MannWhitneyUTest. Thanks to Anders Conbere.

Modified:
    commons/proper/math/trunk/pom.xml
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java

Modified: commons/proper/math/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/pom.xml?rev=1624756&r1=1624755&r2=1624756&view=diff
==============================================================================
--- commons/proper/math/trunk/pom.xml (original)
+++ commons/proper/math/trunk/pom.xml Sat Sep 13 15:46:38 2014
@@ -177,6 +177,9 @@
       <name>Dan Checkoway</name>
     </contributor>
     <contributor>
+      <name>Anders Conbere</name>
+    </contributor>
+    <contributor>
       <name>Charles Cooper</name>
     </contributor>
     <contributor>

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1624756&r1=1624755&r2=1624756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Sat Sep 13 15:46:38 2014
@@ -73,6 +73,10 @@ Users are encouraged to upgrade to this 
   2. A few methods in the FastMath class are in fact slower that their
   counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
 ">
+      <action dev="tn" type="fix" issue="MATH-1145" due-to="Anders Conbere">
+        Fix potential integer overflows in "MannWhitneyUTest" when providing
+        large sample arrays.
+      </action>
       <action dev="tn" type="fix" issue="MATH-1149" due-to="M Kim">
         Fixed potential null pointer dereferencing in constructor of
         "DummyStepInterpolator(DummyStepInterpolator)".

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java?rev=1624756&r1=1624755&r2=1624756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java Sat Sep 13 15:46:38 2014
@@ -145,12 +145,12 @@ public class MannWhitneyUTest {
          * U1 = R1 - (n1 * (n1 + 1)) / 2 where R1 is sum of ranks for sample 1,
          * e.g. x, n1 is the number of observations in sample 1.
          */
-        final double U1 = sumRankX - (x.length * (x.length + 1)) / 2;
+        final double U1 = sumRankX - ((long) x.length * (x.length + 1)) / 2;
 
         /*
          * It can be shown that U1 + U2 = n1 * n2
          */
-        final double U2 = x.length * y.length - U1;
+        final double U2 = (long) x.length * y.length - U1;
 
         return FastMath.max(U1, U2);
     }
@@ -230,7 +230,7 @@ public class MannWhitneyUTest {
         /*
          * It can be shown that U1 + U2 = n1 * n2
          */
-        final double Umin = x.length * y.length - Umax;
+        final double Umin = (long) x.length * y.length - Umax;
 
         return calculateAsymptoticPValue(Umin, x.length, y.length);
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java?rev=1624756&r1=1624755&r2=1624756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java Sat Sep 13 15:46:38 2014
@@ -112,4 +112,17 @@ public class MannWhitneyUTestTest {
         double result = testStatistic.mannWhitneyUTest(d1, d2);
         Assert.assertTrue(result > 0.1);
     }
+    
+    @Test
+    public void testBigDataSetOverflow() {
+        // MATH-1145
+        double[] d1 = new double[110000];
+        double[] d2 = new double[110000];
+        for (int i = 0; i < 110000; i++) {
+            d1[i] = i;
+            d2[i] = i;
+        }
+        double result = testStatistic.mannWhitneyUTest(d1, d2);
+        Assert.assertTrue(result == 1.0);
+    }
 }