hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yxji...@apache.org
Subject svn commit: r1575712 - in /hama/trunk: ./ commons/src/main/java/org/apache/hama/commons/math/ commons/src/test/java/org/apache/hama/commons/math/
Date Sun, 09 Mar 2014 14:59:58 GMT
Author: yxjiang
Date: Sun Mar  9 14:59:57 2014
New Revision: 1575712

URL: http://svn.apache.org/r1575712
Log:
HAMA-889: NonDefaultIterator of DenseDoubleVector never reaches the end

Modified:
    hama/trunk/CHANGES.txt
    hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java
    hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java
    hama/trunk/commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java
    hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java

Modified: hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hama/trunk/CHANGES.txt?rev=1575712&r1=1575711&r2=1575712&view=diff
==============================================================================
--- hama/trunk/CHANGES.txt (original)
+++ hama/trunk/CHANGES.txt Sun Mar  9 14:59:57 2014
@@ -5,7 +5,8 @@ Release 0.7.0 (unreleased changes)
   NEW FEATURES
 
   BUG FIXES
-
+  
+   HAMA-889: NonDefaultIterator of DenseDoubleVector never reaches the end (Yexi Jiang)
    HAMA-885: Semi-Clustering is not producing expected output (Renil J via edwardyoon)
 
   IMPROVEMENTS

Modified: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java?rev=1575712&r1=1575711&r2=1575712&view=diff
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java (original)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java Sun
Mar  9 14:59:57 2014
@@ -501,8 +501,8 @@ public final class DenseDoubleVector imp
    * @see de.jungblut.math.DoubleVector#iterateNonZero()
    */
   @Override
-  public Iterator<DoubleVectorElement> iterateNonZero() {
-    return new NonZeroIterator();
+  public Iterator<DoubleVectorElement> iterateNonDefault() {
+    return new NonDefaultIterator();
   }
 
   /*
@@ -544,21 +544,24 @@ public final class DenseDoubleVector imp
   }
 
   /**
-   * Non-zero iterator for vector elements.
+   * Non-default iterator for vector elements.
    */
-  private final class NonZeroIterator extends
+  private final class NonDefaultIterator extends
       AbstractIterator<DoubleVectorElement> {
 
     private final DoubleVectorElement element = new DoubleVectorElement();
     private final double[] array;
     private int currentIndex = 0;
 
-    private NonZeroIterator() {
+    private NonDefaultIterator() {
       this.array = vector;
     }
 
     @Override
     protected final DoubleVectorElement computeNext() {
+      if (currentIndex >= array.length) {
+        return endOfData();
+      }
       while (array[currentIndex] == 0.0d) {
         currentIndex++;
         if (currentIndex >= array.length)
@@ -566,6 +569,7 @@ public final class DenseDoubleVector imp
       }
       element.setIndex(currentIndex);
       element.setValue(array[currentIndex]);
+      ++currentIndex;
       return element;
     }
   }

Modified: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java?rev=1575712&r1=1575711&r2=1575712&view=diff
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java (original)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java Sun Mar
 9 14:59:57 2014
@@ -300,9 +300,9 @@ public interface DoubleVector {
   public DoubleVector deepCopy();
 
   /**
-   * @return an iterator that only iterates over non zero elements.
+   * @return an iterator that only iterates over non default elements.
    */
-  public Iterator<DoubleVectorElement> iterateNonZero();
+  public Iterator<DoubleVectorElement> iterateNonDefault();
 
   /**
    * @return an iterator that iterates over all elements.

Modified: hama/trunk/commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java?rev=1575712&r1=1575711&r2=1575712&view=diff
==============================================================================
--- hama/trunk/commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java (original)
+++ hama/trunk/commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java Sun
Mar  9 14:59:57 2014
@@ -202,8 +202,8 @@ public final class NamedDoubleVector imp
   }
 
   @Override
-  public Iterator<DoubleVectorElement> iterateNonZero() {
-    return vector.iterateNonZero();
+  public Iterator<DoubleVectorElement> iterateNonDefault() {
+    return vector.iterateNonDefault();
   }
 
   @Override

Modified: hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java
URL: http://svn.apache.org/viewvc/hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java?rev=1575712&r1=1575711&r2=1575712&view=diff
==============================================================================
--- hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java
(original)
+++ hama/trunk/commons/src/test/java/org/apache/hama/commons/math/TestDenseDoubleVector.java
Sun Mar  9 14:59:57 2014
@@ -20,6 +20,10 @@ package org.apache.hama.commons.math;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
+import java.util.Iterator;
+
+import org.apache.hama.commons.math.DoubleVector.DoubleVectorElement;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -205,4 +209,29 @@ public class TestDenseDoubleVector {
     });
     vec.multiply(mat);
   }
+  
+  @Test(timeout=100)
+  public void testIterator() {
+    double[] expectedRes = new double[] {38, 44, 50, 56, 0, 0, 3, 0, 0, 0};
+    DoubleVector vec = new DenseDoubleVector(expectedRes);
+    Iterator<DoubleVectorElement> itr = vec.iterate();
+    
+    int curIdx = 0;
+    while (itr.hasNext()) {
+      DoubleVectorElement elem = itr.next();
+      assertEquals(curIdx, elem.getIndex());
+      assertEquals(expectedRes[curIdx++], elem.getValue(), 0.000001);
+    }
+    
+    Iterator<DoubleVectorElement> itrNonZero = vec.iterateNonDefault();
+    
+    curIdx = 0;
+    while (itrNonZero.hasNext()) {
+      while (expectedRes[curIdx] == 0.0) {
+        ++curIdx;
+      }
+      assertEquals(expectedRes[curIdx++], itrNonZero.next().getValue(), 0.000001);
+    }
+    
+  }
 }



Mime
View raw message