You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/10/12 01:10:47 UTC
svn commit: r1182137 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/descriptive/
main/java/org/apache/commons/math/util/
test/java/org/apache/commons/math/util/
Author: erans
Date: Tue Oct 11 23:10:46 2011
New Revision: 1182137
URL: http://svn.apache.org/viewvc?rev=1182137&view=rev
Log:
MATH-689
Moved array utilities from "MathUtils" to "MathArrays".
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathArrays.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathArraysTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java?rev=1182137&r1=1182136&r2=1182137&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java Tue Oct 11 23:10:46 2011
@@ -32,6 +32,7 @@ import org.apache.commons.math.stat.desc
import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.MathArrays;
import org.apache.commons.math.util.Precision;
import org.apache.commons.math.util.FastMath;
@@ -373,14 +374,14 @@ public class MultivariateSummaryStatisti
return false;
}
MultivariateSummaryStatistics stat = (MultivariateSummaryStatistics) object;
- return MathUtils.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
- MathUtils.equalsIncludingNaN(stat.getMax(), getMax()) &&
- MathUtils.equalsIncludingNaN(stat.getMean(), getMean()) &&
- MathUtils.equalsIncludingNaN(stat.getMin(), getMin()) &&
+ return MathArrays.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
+ MathArrays.equalsIncludingNaN(stat.getMax(), getMax()) &&
+ MathArrays.equalsIncludingNaN(stat.getMean(), getMean()) &&
+ MathArrays.equalsIncludingNaN(stat.getMin(), getMin()) &&
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
- MathUtils.equalsIncludingNaN(stat.getSum(), getSum()) &&
- MathUtils.equalsIncludingNaN(stat.getSumSq(), getSumSq()) &&
- MathUtils.equalsIncludingNaN(stat.getSumLog(), getSumLog()) &&
+ MathArrays.equalsIncludingNaN(stat.getSum(), getSum()) &&
+ MathArrays.equalsIncludingNaN(stat.getSumSq(), getSumSq()) &&
+ MathArrays.equalsIncludingNaN(stat.getSumLog(), getSumLog()) &&
stat.getCovariance().equals( getCovariance());
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathArrays.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathArrays.java?rev=1182137&r1=1182136&r2=1182137&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathArrays.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathArrays.java Tue Oct 11 23:10:46 2011
@@ -922,4 +922,106 @@ public class MathArrays {
return result;
}
+
+ /**
+ * Returns true iff both arguments are null or have same dimensions and all
+ * their elements are equal as defined by
+ * {@link Precision#equals(float,float)}.
+ *
+ * @param x first array
+ * @param y second array
+ * @return true if the values are both null or have same dimension
+ * and equal elements.
+ */
+ public static boolean equals(float[] x, float[] y) {
+ if ((x == null) || (y == null)) {
+ return !((x == null) ^ (y == null));
+ }
+ if (x.length != y.length) {
+ return false;
+ }
+ for (int i = 0; i < x.length; ++i) {
+ if (!Precision.equals(x[i], y[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns true iff both arguments are null or have same dimensions and all
+ * their elements are equal as defined by
+ * {@link Precision#equalsIncludingNaN(double,double) this method}.
+ *
+ * @param x first array
+ * @param y second array
+ * @return true if the values are both null or have same dimension and
+ * equal elements
+ * @since 2.2
+ */
+ public static boolean equalsIncludingNaN(float[] x, float[] y) {
+ if ((x == null) || (y == null)) {
+ return !((x == null) ^ (y == null));
+ }
+ if (x.length != y.length) {
+ return false;
+ }
+ for (int i = 0; i < x.length; ++i) {
+ if (!Precision.equalsIncludingNaN(x[i], y[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns {@code true} iff both arguments are {@code null} or have same
+ * dimensions and all their elements are equal as defined by
+ * {@link Precision#equals(double,double)}.
+ *
+ * @param x First array.
+ * @param y Second array.
+ * @return {@code true} if the values are both {@code null} or have same
+ * dimension and equal elements.
+ */
+ public static boolean equals(double[] x, double[] y) {
+ if ((x == null) || (y == null)) {
+ return !((x == null) ^ (y == null));
+ }
+ if (x.length != y.length) {
+ return false;
+ }
+ for (int i = 0; i < x.length; ++i) {
+ if (!Precision.equals(x[i], y[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns {@code true} iff both arguments are {@code null} or have same
+ * dimensions and all their elements are equal as defined by
+ * {@link Precision#equalsIncludingNaN(double,double) this method}.
+ *
+ * @param x First array.
+ * @param y Second array.
+ * @return {@code true} if the values are both {@code null} or have same
+ * dimension and equal elements.
+ * @since 2.2
+ */
+ public static boolean equalsIncludingNaN(double[] x, double[] y) {
+ if ((x == null) || (y == null)) {
+ return !((x == null) ^ (y == null));
+ }
+ if (x.length != y.length) {
+ return false;
+ }
+ for (int i = 0; i < x.length; ++i) {
+ if (!Precision.equalsIncludingNaN(x[i], y[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1182137&r1=1182136&r2=1182137&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Tue Oct 11 23:10:46 2011
@@ -384,108 +384,6 @@ public final class MathUtils {
}
/**
- * Returns true iff both arguments are null or have same dimensions and all
- * their elements are equal as defined by
- * {@link Precision#equals(float,float)}.
- *
- * @param x first array
- * @param y second array
- * @return true if the values are both null or have same dimension
- * and equal elements.
- */
- public static boolean equals(float[] x, float[] y) {
- if ((x == null) || (y == null)) {
- return !((x == null) ^ (y == null));
- }
- if (x.length != y.length) {
- return false;
- }
- for (int i = 0; i < x.length; ++i) {
- if (!Precision.equals(x[i], y[i])) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Returns true iff both arguments are null or have same dimensions and all
- * their elements are equal as defined by
- * {@link Precision#equalsIncludingNaN(double,double) this method}.
- *
- * @param x first array
- * @param y second array
- * @return true if the values are both null or have same dimension and
- * equal elements
- * @since 2.2
- */
- public static boolean equalsIncludingNaN(float[] x, float[] y) {
- if ((x == null) || (y == null)) {
- return !((x == null) ^ (y == null));
- }
- if (x.length != y.length) {
- return false;
- }
- for (int i = 0; i < x.length; ++i) {
- if (!Precision.equalsIncludingNaN(x[i], y[i])) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Returns {@code true} iff both arguments are {@code null} or have same
- * dimensions and all their elements are equal as defined by
- * {@link Precision#equals(double,double)}.
- *
- * @param x First array.
- * @param y Second array.
- * @return {@code true} if the values are both {@code null} or have same
- * dimension and equal elements.
- */
- public static boolean equals(double[] x, double[] y) {
- if ((x == null) || (y == null)) {
- return !((x == null) ^ (y == null));
- }
- if (x.length != y.length) {
- return false;
- }
- for (int i = 0; i < x.length; ++i) {
- if (!Precision.equals(x[i], y[i])) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Returns {@code true} iff both arguments are {@code null} or have same
- * dimensions and all their elements are equal as defined by
- * {@link Precision#equalsIncludingNaN(double,double) this method}.
- *
- * @param x First array.
- * @param y Second array.
- * @return {@code true} if the values are both {@code null} or have same
- * dimension and equal elements.
- * @since 2.2
- */
- public static boolean equalsIncludingNaN(double[] x, double[] y) {
- if ((x == null) || (y == null)) {
- return !((x == null) ^ (y == null));
- }
- if (x.length != y.length) {
- return false;
- }
- for (int i = 0; i < x.length; ++i) {
- if (!Precision.equalsIncludingNaN(x[i], y[i])) {
- return false;
- }
- }
- return true;
- }
-
- /**
* Returns n!. Shorthand for {@code n} <a
* href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the
* product of the numbers {@code 1,...,n}.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathArraysTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathArraysTest.java?rev=1182137&r1=1182136&r2=1182137&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathArraysTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathArraysTest.java Tue Oct 11 23:10:46 2011
@@ -547,4 +547,43 @@ public class MathArraysTest {
a[7][3], b[7][3])));
Assert.assertTrue(Double.isNaN(MathArrays.linearCombination(a[7], b[7])));
}
+
+ @Test
+ public void testArrayEquals() {
+ Assert.assertFalse(MathArrays.equals(new double[] { 1d }, null));
+ Assert.assertFalse(MathArrays.equals(null, new double[] { 1d }));
+ Assert.assertTrue(MathArrays.equals((double[]) null, (double[]) null));
+
+ Assert.assertFalse(MathArrays.equals(new double[] { 1d }, new double[0]));
+ Assert.assertTrue(MathArrays.equals(new double[] { 1d }, new double[] { 1d }));
+ Assert.assertTrue(MathArrays.equals(new double[] { Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY, 1d, 0d },
+ new double[] { Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY, 1d, 0d }));
+ Assert.assertFalse(MathArrays.equals(new double[] { Double.NaN },
+ new double[] { Double.NaN }));
+ Assert.assertFalse(MathArrays.equals(new double[] { Double.POSITIVE_INFINITY },
+ new double[] { Double.NEGATIVE_INFINITY }));
+ Assert.assertFalse(MathArrays.equals(new double[] { 1d },
+ new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
+
+ }
+
+ @Test
+ public void testArrayEqualsIncludingNaN() {
+ Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { 1d }, null));
+ Assert.assertFalse(MathArrays.equalsIncludingNaN(null, new double[] { 1d }));
+ Assert.assertTrue(MathArrays.equalsIncludingNaN((double[]) null, (double[]) null));
+
+ Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { 1d }, new double[0]));
+ Assert.assertTrue(MathArrays.equalsIncludingNaN(new double[] { 1d }, new double[] { 1d }));
+ Assert.assertTrue(MathArrays.equalsIncludingNaN(new double[] { Double.NaN, Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY, 1d, 0d },
+ new double[] { Double.NaN, Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY, 1d, 0d }));
+ Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { Double.POSITIVE_INFINITY },
+ new double[] { Double.NEGATIVE_INFINITY }));
+ Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { 1d },
+ new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
+ }
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1182137&r1=1182136&r2=1182137&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Tue Oct 11 23:10:46 2011
@@ -319,51 +319,6 @@ public final class MathUtilsTest {
}
@Test
- public void testArrayEquals() {
- Assert.assertFalse(MathUtils.equals(new double[] { 1d }, null));
- Assert.assertFalse(MathUtils.equals(null, new double[] { 1d }));
- Assert.assertTrue(MathUtils.equals((double[]) null, (double[]) null));
-
- Assert.assertFalse(MathUtils.equals(new double[] { 1d }, new double[0]));
- Assert.assertTrue(MathUtils.equals(new double[] { 1d }, new double[] { 1d }));
- Assert.assertTrue(MathUtils.equals(new double[] {
- Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY, 1d, 0d
- }, new double[] {
- Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY, 1d, 0d
- }));
- Assert.assertFalse(MathUtils.equals(new double[] { Double.NaN },
- new double[] { Double.NaN }));
- Assert.assertFalse(MathUtils.equals(new double[] { Double.POSITIVE_INFINITY },
- new double[] { Double.NEGATIVE_INFINITY }));
- Assert.assertFalse(MathUtils.equals(new double[] { 1d },
- new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
-
- }
-
- @Test
- public void testArrayEqualsIncludingNaN() {
- Assert.assertFalse(MathUtils.equalsIncludingNaN(new double[] { 1d }, null));
- Assert.assertFalse(MathUtils.equalsIncludingNaN(null, new double[] { 1d }));
- Assert.assertTrue(MathUtils.equalsIncludingNaN((double[]) null, (double[]) null));
-
- Assert.assertFalse(MathUtils.equalsIncludingNaN(new double[] { 1d }, new double[0]));
- Assert.assertTrue(MathUtils.equalsIncludingNaN(new double[] { 1d }, new double[] { 1d }));
- Assert.assertTrue(MathUtils.equalsIncludingNaN(new double[] {
- Double.NaN, Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY, 1d, 0d
- }, new double[] {
- Double.NaN, Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY, 1d, 0d
- }));
- Assert.assertFalse(MathUtils.equalsIncludingNaN(new double[] { Double.POSITIVE_INFINITY },
- new double[] { Double.NEGATIVE_INFINITY }));
- Assert.assertFalse(MathUtils.equalsIncludingNaN(new double[] { 1d },
- new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
- }
-
- @Test
public void testFactorial() {
for (int i = 1; i < 21; i++) {
Assert.assertEquals(i + "! ", factorial(i), MathUtils.factorial(i));