You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2014/02/20 16:56:37 UTC
svn commit: r1570246 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math3/linear/
test/java/org/apache/commons/math3/linear/
Author: luc
Date: Thu Feb 20 15:56:37 2014
New Revision: 1570246
URL: http://svn.apache.org/r1570246
Log:
Continue un-deprecation of sparse methods.
JIRA: MATH-870
JIRA: MATH-803
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java?rev=1570246&r1=1570245&r2=1570246&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java Thu Feb 20 15:56:37 2014
@@ -366,25 +366,6 @@ public class OpenMapRealVector extends S
iter.advance();
res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
}
- /*
- * MATH-803: the above loop assumes that 0d * x = 0d for any double x,
- * which allows to consider only the non-zero entries of this. However,
- * this fails if this[i] == 0d and (v[i] = NaN or v[i] = Infinity).
- *
- * These special cases are handled below.
- */
- if (v.isNaN() || v.isInfinite()) {
- final int n = getDimension();
- for (int i = 0; i < n; i++) {
- final double y = v.getEntry(i);
- if (Double.isNaN(y)) {
- res.setEntry(i, Double.NaN);
- } else if (Double.isInfinite(y)) {
- final double x = this.getEntry(i);
- res.setEntry(i, x * y);
- }
- }
- }
return res;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1570246&r1=1570245&r2=1570246&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Thu Feb 20 15:56:37 2014
@@ -343,17 +343,7 @@ public abstract class RealVector {
* @return a vector containing this[i] / v[i] for all i.
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this} vector.
- * @deprecated As of version 3.1, this method is deprecated, and will be
- * removed in version 4.0. This decision follows the discussion reported in
- * <a href="https://issues.apache.org/jira/browse/MATH-803?focusedCommentId=13399150#comment-13399150">MATH-803</a>.
- * Uses of this method involving sparse implementations of
- * {@link RealVector} might lead to wrong results. Since there is no
- * satisfactory correction to this bug, this method is deprecated. Users who
- * want to preserve this feature are advised to implement
- * {@link RealVectorPreservingVisitor} (possibly ignoring corner cases for
- * the sake of efficiency).
*/
- @Deprecated
public abstract RealVector ebeDivide(RealVector v)
throws DimensionMismatchException;
@@ -364,17 +354,7 @@ public abstract class RealVector {
* @return a vector containing this[i] * v[i] for all i.
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this} vector.
- * @deprecated As of version 3.1, this method is deprecated, and will be
- * removed in version 4.0. This decision follows the discussion reported in
- * <a href="https://issues.apache.org/jira/browse/MATH-803?focusedCommentId=13399150#comment-13399150">MATH-803</a>.
- * Uses of this method involving sparse implementations of
- * {@link RealVector} might lead to wrong results. Since there is no
- * satisfactory correction to this bug, this method is deprecated. Users who
- * want to preserve this feature are advised to implement
- * {@link RealVectorPreservingVisitor} (possibly ignoring corner cases for
- * the sake of efficiency).
*/
- @Deprecated
public abstract RealVector ebeMultiply(RealVector v)
throws DimensionMismatchException;
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1570246&r1=1570245&r2=1570246&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Thu Feb 20 15:56:37 2014
@@ -55,13 +55,12 @@ import org.apache.commons.math3.exceptio
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.util.MathArrays;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
public abstract class RealVectorAbstractTest {
- private enum BinaryOperation {
+ protected enum BinaryOperation {
ADD, SUB, MUL, DIV
}
@@ -264,7 +263,6 @@ public abstract class RealVectorAbstract
public void testAddToEntry() {
final double x = getPreferredEntryValue();
final double[] data1 = {x, 1d, 2d, x, x};
- final double[] data2 = {x, x, 3d, x, 4d, x};
final double[] expected = MathArrays.copyOf(data1);
final RealVector actual = create(data1);
@@ -459,7 +457,7 @@ public abstract class RealVectorAbstract
Assert.assertFalse(v.isInfinite());
}
- private void doTestEbeBinaryOperation(final BinaryOperation op, final boolean mixed) {
+ protected void doTestEbeBinaryOperation(final BinaryOperation op, final boolean mixed, boolean ignoreSpecial) {
final double[] data1 = new double[values.length * values.length];
final double[] data2 = new double[values.length * values.length];
int k = 0;
@@ -509,8 +507,11 @@ public abstract class RealVectorAbstract
}
}
for (int i = 0; i < expected.length; i++) {
- final String msg = "entry #"+i+", left = "+data1[i]+", right = " + data2[i];
- Assert.assertEquals(msg, expected[i], actual.getEntry(i), 0.0);
+ boolean isSpecial = Double.isNaN(expected[i]) || Double.isInfinite(expected[i]);
+ if (!(isSpecial && ignoreSpecial)) {
+ final String msg = "entry #"+i+", left = "+data1[i]+", right = " + data2[i];
+ Assert.assertEquals(msg, expected[i], actual.getEntry(i), 0.0);
+ }
}
}
@@ -536,12 +537,12 @@ public abstract class RealVectorAbstract
@Test
public void testAddSameType() {
- doTestEbeBinaryOperation(BinaryOperation.ADD, false);
+ doTestEbeBinaryOperation(BinaryOperation.ADD, false, false);
}
@Test
public void testAddMixedTypes() {
- doTestEbeBinaryOperation(BinaryOperation.ADD, true);
+ doTestEbeBinaryOperation(BinaryOperation.ADD, true, false);
}
@Test(expected = DimensionMismatchException.class)
@@ -551,12 +552,12 @@ public abstract class RealVectorAbstract
@Test
public void testSubtractSameType() {
- doTestEbeBinaryOperation(BinaryOperation.SUB, false);
+ doTestEbeBinaryOperation(BinaryOperation.SUB, false, false);
}
@Test
public void testSubtractMixedTypes() {
- doTestEbeBinaryOperation(BinaryOperation.SUB, true);
+ doTestEbeBinaryOperation(BinaryOperation.SUB, true, false);
}
@Test(expected = DimensionMismatchException.class)
@@ -564,37 +565,31 @@ public abstract class RealVectorAbstract
doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.SUB);
}
- @Ignore("ebeMultiply(RealVector) is known to be faulty (MATH-803) and is deprecated.")
@Test
public void testEbeMultiplySameType() {
- doTestEbeBinaryOperation(BinaryOperation.MUL, false);
+ doTestEbeBinaryOperation(BinaryOperation.MUL, false, false);
}
- @Ignore("ebeMultiply(RealVector) is known to be faulty (MATH-803) and is deprecated.")
@Test
public void testEbeMultiplyMixedTypes() {
- doTestEbeBinaryOperation(BinaryOperation.MUL, true);
+ doTestEbeBinaryOperation(BinaryOperation.MUL, true, false);
}
- @Ignore("ebeMultiply(RealVector) is known to be faulty (MATH-803) and is deprecated.")
@Test(expected = DimensionMismatchException.class)
public void testEbeMultiplyDimensionMismatch() {
doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.MUL);
}
- @Ignore("ebeDivide(RealVector) is known to be faulty (MATH-803) and is deprecated.")
@Test
public void testEbeDivideSameType() {
- doTestEbeBinaryOperation(BinaryOperation.DIV, false);
+ doTestEbeBinaryOperation(BinaryOperation.DIV, false, false);
}
- @Ignore("ebeDivide(RealVector) is known to be faulty (MATH-803) and is deprecated.")
- @Test
+ @Test
public void testEbeDivideMixedTypes() {
- doTestEbeBinaryOperation(BinaryOperation.DIV, true);
+ doTestEbeBinaryOperation(BinaryOperation.DIV, true, false);
}
- @Ignore("ebeDivide(RealVector) is known to be faulty (MATH-803) and is deprecated.")
@Test(expected = DimensionMismatchException.class)
public void testEbeDivideDimensionMismatch() {
doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV);
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java?rev=1570246&r1=1570245&r2=1570246&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Thu Feb 20 15:56:37 2014
@@ -16,6 +16,7 @@
*/
package org.apache.commons.math3.linear;
+import org.apache.commons.math3.linear.RealVectorAbstractTest.BinaryOperation;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -99,6 +100,24 @@ public class SparseRealVectorTest extend
u.ebeDivide(v1);
}
+ @Test
+ @Override
+ public void testEbeMultiplyMixedTypes() {
+ doTestEbeBinaryOperation(BinaryOperation.MUL, true, true);
+ }
+
+ @Test
+ @Override
+ public void testEbeMultiplySameType() {
+ doTestEbeBinaryOperation(BinaryOperation.MUL, false, true);
+ }
+
+ @Test
+ @Override
+ public void testEbeDivideSameType() {
+ doTestEbeBinaryOperation(BinaryOperation.DIV, false, true);
+ }
+
/**
* XXX This test is disabled because it currently fails.
* The bug must still be fixed in the sparse vector implementation.