You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2009/02/27 02:32:31 UTC

svn commit: r748370 - in /incubator/hama/trunk/src: java/org/apache/hama/DenseVector.java java/org/apache/hama/SparseMatrix.java java/org/apache/hama/SparseVector.java test/org/apache/hama/TestSparseMatrix.java test/org/apache/hama/TestSparseVector.java

Author: edwardyoon
Date: Fri Feb 27 01:32:31 2009
New Revision: 748370

URL: http://svn.apache.org/viewvc?rev=748370&view=rev
Log:
code format alignment

Modified:
    incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java
    incubator/hama/trunk/src/java/org/apache/hama/SparseMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/SparseVector.java
    incubator/hama/trunk/src/test/org/apache/hama/TestSparseMatrix.java
    incubator/hama/trunk/src/test/org/apache/hama/TestSparseVector.java

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=748370&r1=748369&r2=748370&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java Fri Feb 27 01:32:31 2009
@@ -39,6 +39,7 @@
  */
 public class DenseVector extends AbstractVector implements Vector {
   static final Logger LOG = Logger.getLogger(DenseVector.class);
+
   public DenseVector() {
     this(new MapWritable());
   }
@@ -50,7 +51,7 @@
   public DenseVector(RowResult row) {
     this.entries = new MapWritable();
     for (Map.Entry<byte[], Cell> f : row.entrySet()) {
-      this.entries.put(new IntWritable(BytesUtil.getColumnIndex(f.getKey())), 
+      this.entries.put(new IntWritable(BytesUtil.getColumnIndex(f.getKey())),
           new DoubleEntry(f.getValue()));
     }
   }
@@ -59,15 +60,15 @@
     this.entries = m;
     this.entries.put(new Text("row"), new IntWritable(row));
   }
-  
+
   public void setRow(int row) {
     this.entries.put(new Text("row"), new IntWritable(row));
   }
-  
+
   public int getRow() {
     return ((IntWritable) this.entries.get(new Text("row"))).get();
   }
-  
+
   /**
    * x = alpha*v + x
    * 
@@ -98,11 +99,12 @@
       return this;
     }
 
-    for(Map.Entry<Writable, Writable> e : this.getEntries().entrySet()) {
-      double value = ((DoubleEntry) e.getValue()).getValue() + v2.get(((IntWritable) e.getKey()).get());
+    for (Map.Entry<Writable, Writable> e : this.getEntries().entrySet()) {
+      double value = ((DoubleEntry) e.getValue()).getValue()
+          + v2.get(((IntWritable) e.getKey()).get());
       this.entries.put(e.getKey(), new DoubleEntry(value));
     }
-    
+
     return this;
   }
 
@@ -124,14 +126,16 @@
   }
 
   /**
-   * v = alpha*v 
+   * v = alpha*v
    * 
    * @param alpha
    * @return v = alpha*v
    */
   public DenseVector scale(double alpha) {
-    for(Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
-      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue()).getValue() * alpha));
+    for (Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
+      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue())
+          .getValue()
+          * alpha));
     }
     return this;
   }
@@ -195,19 +199,20 @@
    * 
    * @param index
    * @return the value of v(index)
-   * @throws IOException 
+   * @throws IOException
    */
   public double get(int index) {
     double value;
     try {
-      value = ((DoubleEntry) this.entries.get(new IntWritable(index))).getValue();
+      value = ((DoubleEntry) this.entries.get(new IntWritable(index)))
+          .getValue();
     } catch (NullPointerException e) {
       throw new NullPointerException("Unexpected null value : " + e.toString());
     }
-    
+
     return value;
   }
-  
+
   /**
    * Sets the value of index
    * 
@@ -215,14 +220,14 @@
    * @param value
    */
   public void set(int index, double value) {
-    // If entries are null, create new object 
-    if(this.entries == null) {
+    // If entries are null, create new object
+    if (this.entries == null) {
       this.entries = new MapWritable();
     }
-    
+
     this.entries.put(new IntWritable(index), new DoubleEntry(value));
   }
-  
+
   /**
    * Adds the value to v(index)
    * 
@@ -232,7 +237,7 @@
   public void add(int index, double value) {
     set(index, get(index) + value);
   }
-  
+
   public double getNorm2Robust() {
     // TODO Auto-generated method stub
     return 0;
@@ -252,9 +257,9 @@
    */
   public DenseVector subVector(int i0, int i1) {
     DenseVector res = new DenseVector();
-    if(this.entries.containsKey(new Text("row"))) 
-        res.setRow(this.getRow());
-    
+    if (this.entries.containsKey(new Text("row")))
+      res.setRow(this.getRow());
+
     for (int i = i0; i <= i1; i++) {
       res.set(i, get(i));
     }

Modified: incubator/hama/trunk/src/java/org/apache/hama/SparseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/SparseMatrix.java?rev=748370&r1=748369&r2=748370&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/SparseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/SparseMatrix.java Fri Feb 27 01:32:31 2009
@@ -65,6 +65,7 @@
     // we don't know where to call Matrix.close in Add & Mul map/reduce
     // process to decrement the reference. It seems difficulty.
   }
+
   /**
    * Generate matrix with random elements
    * 
@@ -84,8 +85,8 @@
     for (int i = 0; i < m; i++) {
       vector.clear();
       for (int j = 0; j < n; j++) {
-        Random r = new Random(); 
-        if(r.nextInt(2) != 0)
+        Random r = new Random();
+        if (r.nextInt(2) != 0)
           vector.set(j, RandomVariable.rand());
       }
       rand.setRow(i, vector);
@@ -94,7 +95,7 @@
     rand.setDimension(m, n);
     return rand;
   }
-  
+
   @Override
   public Matrix add(Matrix B) throws IOException {
     // TODO Auto-generated method stub
@@ -109,9 +110,9 @@
 
   @Override
   public double get(int i, int j) throws IOException {
-    if(this.getRows() < i || this.getColumns() < j)
-      throw new ArrayIndexOutOfBoundsException(i +", "+ j);
-    
+    if (this.getRows() < i || this.getColumns() < j)
+      throw new ArrayIndexOutOfBoundsException(i + ", " + j);
+
     Cell c = table.get(BytesUtil.getRowIndex(i), BytesUtil.getColumnIndex(j));
     return (c != null) ? BytesUtil.bytesToDouble(c.getValue()) : 0.0;
   }
@@ -136,13 +137,13 @@
 
   /** {@inheritDoc} */
   public void set(int i, int j, double value) throws IOException {
-    if(value != 0) {
+    if (value != 0) {
       VectorUpdate update = new VectorUpdate(i);
       update.put(j, value);
       table.commit(update.getBatchUpdate());
     }
   }
-  
+
   /**
    * Returns type of matrix
    */
@@ -160,8 +161,8 @@
     jobConf.setNumMapTasks(config.getNumMapTasks());
     jobConf.setNumReduceTasks(config.getNumReduceTasks());
 
-    SIMDMultiplyMap.initJob(this.getPath(), B.getPath(), this.getType(), SIMDMultiplyMap.class,
-        IntWritable.class, MapWritable.class, jobConf);
+    SIMDMultiplyMap.initJob(this.getPath(), B.getPath(), this.getType(),
+        SIMDMultiplyMap.class, IntWritable.class, MapWritable.class, jobConf);
     SIMDMultiplyReduce.initJob(result.getPath(), SIMDMultiplyReduce.class,
         jobConf);
     JobManager.execute(jobConf);
@@ -184,15 +185,15 @@
   @Override
   public void setColumn(int column, Vector vector) throws IOException {
     // TODO Auto-generated method stub
-    
+
   }
 
   @Override
   public void setRow(int row, Vector vector) throws IOException {
-    if(this.getRows() < row)
+    if (this.getRows() < row)
       increaseRows();
-    
-    if(vector.size() > 0) {  // stores if size > 0
+
+    if (vector.size() > 0) { // stores if size > 0
       VectorUpdate update = new VectorUpdate(row);
       update.putAll(((SparseVector) vector).getEntries());
       table.commit(update.getBatchUpdate());

Modified: incubator/hama/trunk/src/java/org/apache/hama/SparseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/SparseVector.java?rev=748370&r1=748369&r2=748370&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/SparseVector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/SparseVector.java Fri Feb 27 01:32:31 2009
@@ -33,6 +33,7 @@
 
 public class SparseVector extends AbstractVector implements Vector {
   static final Logger LOG = Logger.getLogger(SparseVector.class);
+
   public SparseVector() {
     this(new MapWritable());
   }
@@ -40,11 +41,11 @@
   public SparseVector(MapWritable m) {
     this.entries = m;
   }
-  
+
   public SparseVector(RowResult row) {
     this.entries = new MapWritable();
     for (Map.Entry<byte[], Cell> f : row.entrySet()) {
-      this.entries.put(new IntWritable(BytesUtil.getColumnIndex(f.getKey())), 
+      this.entries.put(new IntWritable(BytesUtil.getColumnIndex(f.getKey())),
           new DoubleEntry(f.getValue()));
     }
   }
@@ -54,7 +55,7 @@
     // TODO Auto-generated method stub
     return null;
   }
-  
+
   /**
    * x = v + x
    * 
@@ -68,14 +69,16 @@
       return this;
     }
 
-    for(Map.Entry<Writable, Writable> e : ((SparseVector )v2).getEntries().entrySet()) {
-      
-      if(this.entries.containsKey(e.getKey())) {
+    for (Map.Entry<Writable, Writable> e : ((SparseVector) v2).getEntries()
+        .entrySet()) {
+
+      if (this.entries.containsKey(e.getKey())) {
         // add
-        double value = ((DoubleEntry) e.getValue()).getValue() + this.get(((IntWritable) e.getKey()).get());
+        double value = ((DoubleEntry) e.getValue()).getValue()
+            + this.get(((IntWritable) e.getKey()).get());
         this.entries.put(e.getKey(), new DoubleEntry(value));
       } else {
-        //  put
+        // put
         this.entries.put(e.getKey(), e.getValue());
       }
     }
@@ -96,14 +99,16 @@
   }
 
   /**
-   * v = alpha*v 
+   * v = alpha*v
    * 
    * @param alpha
    * @return v = alpha*v
    */
   public SparseVector scale(double alpha) {
-    for(Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
-      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue()).getValue() * alpha));
+    for (Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
+      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue())
+          .getValue()
+          * alpha));
     }
     return this;
   }
@@ -113,19 +118,20 @@
    * 
    * @param index
    * @return the value of v(index)
-   * @throws IOException 
+   * @throws IOException
    */
   public double get(int index) {
     double value;
     try {
-      value = ((DoubleEntry) this.entries.get(new IntWritable(index))).getValue();
+      value = ((DoubleEntry) this.entries.get(new IntWritable(index)))
+          .getValue();
     } catch (NullPointerException e) { // returns zero if there is no value
       return 0;
     }
-    
+
     return value;
   }
-  
+
   /**
    * Sets the value of index
    * 
@@ -133,15 +139,15 @@
    * @param value
    */
   public void set(int index, double value) {
-    // If entries are null, create new object 
-    if(this.entries == null) {
+    // If entries are null, create new object
+    if (this.entries == null) {
       this.entries = new MapWritable();
     }
-    
-    if(value != 0) // only stores non-zero element
+
+    if (value != 0) // only stores non-zero element
       this.entries.put(new IntWritable(index), new DoubleEntry(value));
   }
-  
+
   /**
    * Adds the value to v(index)
    * 
@@ -151,7 +157,7 @@
   public void add(int index, double value) {
     set(index, get(index) + value);
   }
-  
+
   @Override
   public Vector set(Vector v) {
     // TODO Auto-generated method stub

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestSparseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestSparseMatrix.java?rev=748370&r1=748369&r2=748370&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestSparseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestSparseMatrix.java Fri Feb 27 01:32:31 2009
@@ -62,16 +62,16 @@
 
   public void testSparsity() throws IOException {
     boolean appeared = false;
-    for(int i = 0; i < m1.getRows(); i++) {
-      for(int j = 0; j < m1.getColumns(); j++) {
-        if(m1.get(i, j) == 0)
+    for (int i = 0; i < m1.getRows(); i++) {
+      for (int j = 0; j < m1.getColumns(); j++) {
+        if (m1.get(i, j) == 0)
           appeared = true;
       }
     }
-    
+
     assertTrue(appeared);
   }
-  
+
   /**
    * Test matrices multiplication
    * 
@@ -81,7 +81,7 @@
     SparseMatrix result = m1.mult(m2);
     verifyMultResult(m1, m2, result);
   }
-  
+
   /**
    * Verifying multiplication result
    * 
@@ -90,8 +90,8 @@
    * @param result
    * @throws IOException
    */
-  private void verifyMultResult(SparseMatrix m1, SparseMatrix m2, SparseMatrix result)
-      throws IOException {
+  private void verifyMultResult(SparseMatrix m1, SparseMatrix m2,
+      SparseMatrix result) throws IOException {
     double[][] c = new double[SIZE][SIZE];
 
     for (int i = 0; i < SIZE; i++) {

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestSparseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestSparseVector.java?rev=748370&r1=748369&r2=748370&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestSparseVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestSparseVector.java Fri Feb 27 01:32:31 2009
@@ -64,12 +64,13 @@
 
   /**
    * Test get/set methods
-   * @throws IOException 
+   * 
+   * @throws IOException
    */
   public void testGetSet() throws IOException {
     assertEquals(v1.get(1), 0.0);
     assertEquals(v2.get(1), 0.0);
-    
+
     HTable table = m1.getHTable();
     Cell c = table.get(BytesUtil.getRowIndex(0), BytesUtil.getColumnIndex(1));
     assertTrue(c == null);