incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r704355 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/DenseVector.java src/java/org/apache/hama/Vector.java src/test/org/apache/hama/TestDenseVector.java
Date Tue, 14 Oct 2008 07:25:31 GMT
Author: edwardyoon
Date: Tue Oct 14 00:25:30 2008
New Revision: 704355

URL: http://svn.apache.org/viewvc?rev=704355&view=rev
Log:
Add subVector(int i0, int i1) to Vector interface

Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java
    incubator/hama/trunk/src/java/org/apache/hama/Vector.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=704355&r1=704354&r2=704355&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Oct 14 00:25:30 2008
@@ -4,6 +4,7 @@
 
   NEW FEATURES
     
+    HAMA-81: Add subVector(int i0, int i1) to Vector interface (edwardyoon)
     Hama-80: Add identity(int m, int n) which returns identity matrix (edwardyoon) 
     HAMA-62: Hama Shell Implementation (samuel via edwardyoon)
     HAMA-61: Load / save matrices from HTable (edwardyoon)

Modified: incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java?rev=704355&r1=704354&r2=704355&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java Tue Oct 14 00:25:30 2008
@@ -27,7 +27,7 @@
 import org.apache.log4j.Logger;
 
 public class DenseVector extends AbstractVector implements Vector {
-  static final Logger LOG = Logger.getLogger(Vector.class);
+  static final Logger LOG = Logger.getLogger(DenseVector.class);
   
   public DenseVector() {
     this(new VectorMapWritable<Integer, VectorEntry>());
@@ -141,4 +141,14 @@
     // TODO Auto-generated method stub
     return 0;
   }
+
+  public Vector subVector(int i0, int i1) {
+    Vector res = new DenseVector();
+    LOG.info(i0 + ", " + i1);
+    for(int i = i0; i <= i1; i++ ) {
+      res.set(i, get(i));
+    }
+      
+    return res;
+  }
 }

Modified: incubator/hama/trunk/src/java/org/apache/hama/Vector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Vector.java?rev=704355&r1=704354&r2=704355&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Vector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Vector.java Tue Oct 14 00:25:30 2008
@@ -101,6 +101,15 @@
   public Vector scale(double alpha);
   
   /**
+   * Returns a sub-vector.
+   * 
+   * @param i0 the index of the first element
+   * @param i1 the index of the last element
+   * @return v[i0:i1]
+   */
+  public Vector subVector( int i0, int i1 ); 
+  
+  /**
    * Computes the given norm of the vector
    * 
    * @param type

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java?rev=704355&r1=704354&r2=704355&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java Tue Oct 14 00:25:30
2008
@@ -71,6 +71,18 @@
     assertEquals(cos, cosine);
   }
 
+  public void testSubVector() {
+    int start = 2;
+    Vector subVector = v1.subVector(start, v1.size() - 1);
+    Iterator<VectorEntry> it = subVector.iterator();
+
+    int i = start;
+    while (it.hasNext()) {
+      assertEquals(v1.get(i), it.next().getValue());
+      i++;
+    }
+  }
+
   /**
    * Test norm one
    */



Mime
View raw message