Author: luc
Date: Mon Apr 20 18:42:11 2009
New Revision: 766793

URL: http://svn.apache.org/viewvc?rev=766793&view=rev
Log:
optimized isInfinite for NaN vectors
reverted hashcode back to its previous behavior to avoid breaking consistency 
with equals

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

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java?rev=766793&r1=766792&r2=766793&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
 Mon Apr 20 18:42:11 2009
@@ -594,19 +594,18 @@
     /** {...@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 @@
         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;
     }
 

Modified: 
commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=766793&r1=766792&r2=766793&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
 Mon Apr 20 18:42:11 2009
@@ -1091,12 +1091,6 @@
         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) */


Reply via email to