MATH-645
Iterate on the original vector, not on the copy that is modified. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1157403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c6dd40b33
commit
6983d81680
|
@ -342,7 +342,7 @@ public class OpenMapRealVector extends AbstractRealVector
|
|||
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 AbstractRealVector
|
|||
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 AbstractRealVector
|
|||
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 AbstractRealVector
|
|||
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()]);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue