commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1157403 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/OpenMapRealVector.java test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
Date Sat, 13 Aug 2011 18:10:14 GMT
Author: erans
Date: Sat Aug 13 18:10:13 2011
New Revision: 1157403

URL: http://svn.apache.org/viewvc?rev=1157403&view=rev
Log:
MATH-645
Iterate on the original vector, not on the copy that is modified.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java?rev=1157403&r1=1157402&r2=1157403&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
Sat Aug 13 18:10:13 2011
@@ -342,7 +342,7 @@ public class OpenMapRealVector extends A
     public OpenMapRealVector ebeDivide(RealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = res.entries.iterator();
+        Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
             res.setEntry(iter.key(), iter.value() / v.getEntry(iter.key()));
@@ -355,7 +355,7 @@ public class OpenMapRealVector extends A
     public OpenMapRealVector ebeDivide(double[] v) {
         checkVectorDimensions(v.length);
         OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = res.entries.iterator();
+        Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
             res.setEntry(iter.key(), iter.value() / v[iter.key()]);
@@ -367,7 +367,7 @@ public class OpenMapRealVector extends A
     public OpenMapRealVector ebeMultiply(RealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = res.entries.iterator();
+        Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
             res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
@@ -380,7 +380,7 @@ public class OpenMapRealVector extends A
     public OpenMapRealVector ebeMultiply(double[] v) {
         checkVectorDimensions(v.length);
         OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = res.entries.iterator();
+        Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
             res.setEntry(iter.key(), iter.value() * v[iter.key()]);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=1157403&r1=1157402&r2=1157403&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
Sat Aug 13 18:10:13 2011
@@ -998,4 +998,30 @@ public class SparseRealVectorTest {
             Assert.assertEquals(msg + " " +  i + " elements differ", m[i],n[i],tolerance);
         }
     }
+
+    /* Check that the operations do not throw an exception (cf. MATH-645). */
+    @Test
+    public void testConcurrentModification() {
+        final RealVector u = new OpenMapRealVector(3, 1e-6);
+        u.setEntry(0, 1);
+        u.setEntry(1, 0);
+        u.setEntry(2, 2);
+
+        final RealVector v1 = new OpenMapRealVector(3, 1e-6);
+        final double[] v2 = new double[3];
+        v1.setEntry(0, 0);
+        v2[0] = 0;
+        v1.setEntry(1, 3);
+        v2[1] = 3;
+        v1.setEntry(2, 0);
+        v2[2] = 0;
+
+        RealVector w;
+
+        w = u.ebeMultiply(v1);
+        w = u.ebeMultiply(v2);
+
+        w = u.ebeDivide(v1);
+        w = u.ebeDivide(v2);
+    }
 }



Mime
View raw message