optimized isInfinite for NaN vectors

reverted hashcode back to its previous behavior to avoid breaking consistency with equals

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@766793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-04-20 18:42:11 +00:00
parent e2b8720d5d
commit e2c16f0c5c
2 changed files with 2 additions and 15 deletions

View File

@ -594,19 +594,18 @@ public class SparseRealVector implements RealVector {
/** {@inheritDoc} */
public boolean isInfinite() {
boolean infiniteFound = false;
boolean nanFound = false;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
final double value = iter.value();
if (Double.isNaN(value)) {
nanFound = true;
return false;
}
if (Double.isInfinite(value)) {
infiniteFound = true;
}
}
return infiniteFound && (!nanFound);
return infiniteFound;
}
/** {@inheritDoc} */
@ -1234,12 +1233,6 @@ public class SparseRealVector implements RealVector {
temp = Double.doubleToLongBits(epsilon);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + virtualSize;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
temp = Double.doubleToLongBits(iter.value());
result = prime * result + (int) (temp ^ (temp >>> 32));
}
return result;
}

View File

@ -1091,12 +1091,6 @@ public class SparseRealVectorTest extends TestCase {
assertNotSame(v, new SparseRealVector(new double[] { 0, 1, 2 + Math.ulp(2)}));
assertNotSame(v, new SparseRealVector(new double[] { 0, 1, 2, 3 }));
assertTrue(new SparseRealVector(new double[] { Double.NaN, 1, 2 }).hashCode() !=
new SparseRealVector(new double[] { 0, Double.NaN, 2 }).hashCode());
assertTrue(new SparseRealVector(new double[] { Double.NaN, 1, 2 }).hashCode() !=
new SparseRealVector(new double[] { 0, 1, 2 }).hashCode());
}
/** verifies that two vectors are close (sup norm) */