hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r744029 - in /incubator/hama/trunk/src/java/org/apache/hama: AbstractMatrix.java DenseMatrix.java DenseVector.java HamaAdminImpl.java
Date Fri, 13 Feb 2009 08:32:28 GMT
Author: edwardyoon
Date: Fri Feb 13 08:32:27 2009
New Revision: 744029

URL: http://svn.apache.org/viewvc?rev=744029&view=rev
Log:
Added some comments.

Modified:
    incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java
    incubator/hama/trunk/src/java/org/apache/hama/HamaAdminImpl.java

Modified: incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java?rev=744029&r1=744028&r2=744029&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Fri Feb 13 08:32:27
2009
@@ -134,17 +134,32 @@
   }
 
   /** {@inheritDoc} */
-  public void set(int i, int j, double value) throws IOException {
-    VectorUpdate update = new VectorUpdate(i);
-    update.put(j, value);
-    table.commit(update.getBatchUpdate());
+  public String getRowLabel(int row) throws IOException {
+    Cell rows = null;
+    rows = table.get(BytesUtil.getRowIndex(row), Bytes
+        .toBytes(Constants.ATTRIBUTE + "string"));
 
+    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
   }
 
   /** {@inheritDoc} */
-  public void add(int i, int j, double value) throws IOException {
+  public String getColumnLabel(int column) throws IOException {
+    Cell rows = null;
+    rows = table.get(Constants.CINDEX, (Constants.ATTRIBUTE + column));
+    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
+  }
+
+  /** {@inheritDoc} */
+  public void setRowLabel(int row, String name) throws IOException {
+    VectorUpdate update = new VectorUpdate(row);
+    update.put(Constants.ATTRIBUTE + "string", name);
+    table.commit(update.getBatchUpdate());
+  }
+  
+  /** {@inheritDoc} */
+  public void set(int i, int j, double value) throws IOException {
     VectorUpdate update = new VectorUpdate(i);
-    update.put(j, value + this.get(i, j));
+    update.put(j, value);
     table.commit(update.getBatchUpdate());
 
   }
@@ -158,6 +173,14 @@
     table.commit(update.getBatchUpdate());
   }
 
+  /** {@inheritDoc} */
+  public void add(int i, int j, double value) throws IOException {
+    VectorUpdate update = new VectorUpdate(i);
+    update.put(j, value + this.get(i, j));
+    table.commit(update.getBatchUpdate());
+
+  }
+  
   /**
    * Just full scan a table.
    */
@@ -234,27 +257,7 @@
     return this;
   }
 
-  public String getRowLabel(int row) throws IOException {
-    Cell rows = null;
-    rows = table.get(BytesUtil.getRowIndex(row), Bytes
-        .toBytes(Constants.ATTRIBUTE + "string"));
-
-    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
-  }
-
-  public void setRowLabel(int row, String name) throws IOException {
-    VectorUpdate update = new VectorUpdate(row);
-    update.put(Constants.ATTRIBUTE + "string", name);
-    table.commit(update.getBatchUpdate());
-
-  }
-
-  public String getColumnLabel(int column) throws IOException {
-    Cell rows = null;
-    rows = table.get(Constants.CINDEX, (Constants.ATTRIBUTE + column));
-    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
-  }
-
+  /** {@inheritDoc} */
   public void setColumnLabel(int column, String name) throws IOException {
     VectorUpdate update = new VectorUpdate(Constants.CINDEX);
     update.put(column, name);

Modified: incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java?rev=744029&r1=744028&r2=744029&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Fri Feb 13 08:32:27 2009
@@ -57,6 +57,9 @@
 import org.apache.hama.util.JobManager;
 import org.apache.hama.util.RandomVariable;
 
+/**
+ * This class represents a dense matrix.
+ */
 public class DenseMatrix extends AbstractMatrix implements Matrix {
   static int tryPathLength = Constants.DEFAULT_PATH_LENGTH;
   static final String TABLE_PREFIX = DenseMatrix.class.getSimpleName() + "_";
@@ -339,6 +342,74 @@
     return (c != null) ? BytesUtil.bytesToDouble(c.getValue()) : 0;
   }
 
+  /**
+   * Gets the vector of row
+   * 
+   * @param i the row index of the matrix
+   * @return the vector of row
+   * @throws IOException
+   */
+  public DenseVector getRow(int i) throws IOException {
+    return new DenseVector(table.getRow(BytesUtil.getRowIndex(i)));
+  }
+  
+  /**
+   * Gets the vector of column
+   * 
+   * @param j the column index of the matrix
+   * @return the vector of column
+   * @throws IOException
+   */
+  public DenseVector getColumn(int j) throws IOException {
+    byte[] columnKey = BytesUtil.getColumnIndex(j);
+    byte[][] c = { columnKey };
+    Scanner scan = table.getScanner(c, HConstants.EMPTY_START_ROW);
+
+    HMapWritable<Integer, DoubleEntry> trunk = new HMapWritable<Integer, DoubleEntry>();
+
+    for (RowResult row : scan) {
+      trunk.put(BytesUtil.bytesToInt(row.getRow()), new DoubleEntry(row
+          .get(columnKey)));
+    }
+
+    return new DenseVector(trunk);
+  }
+
+  /**
+   * Set the row of a matrix to a given vector
+   * 
+   * @param row
+   * @param vector
+   * @throws IOException
+   */
+  public void setRow(int row, Vector vector) throws IOException {
+    VectorUpdate update = new VectorUpdate(row);
+    update.putAll(((DenseVector) vector).getEntries().entrySet());
+    table.commit(update.getBatchUpdate());
+  }
+
+  /**
+   * Set the column of a matrix to a given vector
+   * 
+   * @param column
+   * @param vector
+   * @throws IOException
+   */
+  public void setColumn(int column, Vector vector) throws IOException {
+    for (int i = 0; i < vector.size(); i++) {
+      VectorUpdate update = new VectorUpdate(i);
+      update.put(column, vector.get(i));
+      table.commit(update.getBatchUpdate());
+    }
+  }
+  
+  /**
+   * A = B + A
+   * 
+   * @param B
+   * @return A
+   * @throws IOException
+   */
   public Matrix add(Matrix B) throws IOException {
     Matrix result = new DenseMatrix(config);
     JobConf jobConf = new JobConf(config);
@@ -357,6 +428,14 @@
     return result;
   }
 
+  /**
+   * A = alpha*B + A
+   * 
+   * @param alpha
+   * @param B
+   * @return A
+   * @throws IOException
+   */
   public Matrix add(double alpha, Matrix B) throws IOException {
     Matrix temp = new DenseMatrix(config);
     temp.set(alpha, B);
@@ -364,26 +443,14 @@
     Matrix result = this.add(temp);
     return result;
   }
-
-  public DenseVector getRow(int row) throws IOException {
-    return new DenseVector(table.getRow(BytesUtil.getRowIndex(row)));
-  }
-
-  public DenseVector getColumn(int column) throws IOException {
-    byte[] columnKey = BytesUtil.getColumnIndex(column);
-    byte[][] c = { columnKey };
-    Scanner scan = table.getScanner(c, HConstants.EMPTY_START_ROW);
-
-    HMapWritable<Integer, DoubleEntry> trunk = new HMapWritable<Integer, DoubleEntry>();
-
-    for (RowResult row : scan) {
-      trunk.put(BytesUtil.bytesToInt(row.getRow()), new DoubleEntry(row
-          .get(columnKey)));
-    }
-
-    return new DenseVector(trunk);
-  }
-
+  
+  /**
+   * C = A*B using SIMD algorithm
+   * 
+   * @param B
+   * @return C
+   * @throws IOException
+   */
   public Matrix mult(Matrix B) throws IOException {
     Matrix result = new DenseMatrix(config);
 
@@ -402,7 +469,7 @@
   }
 
   /**
-   * A * B
+   * C = A * B using Blocking algorithm
    * 
    * @param B
    * @param blocks the number of blocks
@@ -412,8 +479,10 @@
   public Matrix mult(Matrix B, int blocks) throws IOException {
     Matrix collectionTable = new DenseMatrix(config);
     LOG.info("Collect Blocks");
-    collectBlocks(this, B, blocks, collectionTable);
 
+    collectBlocksMapRed(this.getPath(), collectionTable, blocks, true);
+    collectBlocksMapRed(B.getPath(), collectionTable, blocks, false);
+    
     Matrix result = new DenseMatrix(config);
 
     JobConf jobConf = new JobConf(config);
@@ -432,42 +501,49 @@
     return result;
   }
 
-  private void collectBlocks(Matrix a, Matrix b, int blocks,
-      Matrix collectionTable) throws IOException {
-    collectBlocksMapRed(a.getPath(), collectionTable, blocks, true);
-    collectBlocksMapRed(b.getPath(), collectionTable, blocks, false);
-  }
-
+  /**
+   * C = alpha*A*B + C
+   * 
+   * @param alpha
+   * @param B
+   * @param C
+   * @return C
+   * @throws IOException
+   */
   public Matrix multAdd(double alpha, Matrix B, Matrix C) throws IOException {
     // TODO Auto-generated method stub
     return null;
   }
 
+  /**
+   * Computes the given norm of the matrix
+   * 
+   * @param type
+   * @return norm of the matrix
+   * @throws IOException
+   */
   public double norm(Norm type) throws IOException {
     // TODO Auto-generated method stub
     return 0;
   }
 
-  public void setRow(int row, Vector vector) throws IOException {
-    VectorUpdate update = new VectorUpdate(row);
-    update.putAll(((DenseVector) vector).getEntries().entrySet());
-    table.commit(update.getBatchUpdate());
-  }
-
-  public void setColumn(int column, Vector vector) throws IOException {
-    for (int i = 0; i < vector.size(); i++) {
-      VectorUpdate update = new VectorUpdate(i);
-      update.put(column, vector.get(i));
-      table.commit(update.getBatchUpdate());
-    }
-  }
-
+  /**
+   * Returns type of matrix
+   */
   public String getType() {
     return this.getClass().getSimpleName();
   }
 
   /**
-   * Gets the sub matrix
+   * Returns the sub matrix formed by selecting certain rows and
+   * columns from a bigger matrix. The sub matrix is a in-memory operation only.
+   * 
+   * @param i0 the start index of row
+   * @param i1 the end index of row
+   * @param j0 the start index of column
+   * @param j1 the end index of column
+   * @return the sub matrix of matrix
+   * @throws IOException
    */
   public SubMatrix subMatrix(int i0, int i1, int j0, int j1) throws IOException {
     int columnSize = (j1 - j0) + 1;
@@ -498,9 +574,9 @@
   /**
    * Collect Blocks
    * 
-   * @param path
-   * @param collectionTable
-   * @param blockNum
+   * @param path a input path
+   * @param collectionTable the collection table
+   * @param blockNum the number of blocks
    * @param bool
    * @throws IOException
    */

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=744029&r1=744028&r2=744029&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 13 08:32:27 2009
@@ -30,6 +30,9 @@
 import org.apache.hama.util.BytesUtil;
 import org.apache.log4j.Logger;
 
+/**
+ * This class represents a dense vector.
+ */
 public class DenseVector extends AbstractVector implements Vector {
   static final Logger LOG = Logger.getLogger(DenseVector.class);
 
@@ -49,6 +52,13 @@
     }
   }
 
+  /**
+   * x = alpha*v + x
+   * 
+   * @param alpha
+   * @param v
+   * @return x = alpha*v + x
+   */
   public DenseVector add(double alpha, Vector v) {
     if (alpha == 0)
       return this;
@@ -59,6 +69,12 @@
     return this;
   }
 
+  /**
+   * x = v + x
+   * 
+   * @param v2
+   * @return x = v + x
+   */
   public DenseVector add(Vector v2) {
     if (this.size() == 0) {
       DenseVector trunk = (DenseVector) v2;
@@ -75,6 +91,12 @@
     return this;
   }
 
+  /**
+   * x dot v
+   * 
+   * @param v
+   * @return x dot v
+   */
   public double dot(Vector v) {
     double cosine = 0.0;
     double q_i, d_i;
@@ -86,6 +108,12 @@
     return cosine / (this.getNorm2() * ((DenseVector) v).getNorm2());
   }
 
+  /**
+   * v = alpha*v 
+   * 
+   * @param alpha
+   * @return v = alpha*v
+   */
   public Vector scale(double alpha) {
     for(Map.Entry<Integer, DoubleEntry> e : this.entries.entrySet()) {
       this.entries.put(e.getKey(), new DoubleEntry(e.getValue().getValue() * alpha));
@@ -93,6 +121,12 @@
     return this;
   }
 
+  /**
+   * Computes the given norm of the vector
+   * 
+   * @param type
+   * @return norm of the vector
+   */
   public double norm(Norm type) {
     if (type == Norm.One)
       return getNorm1();
@@ -104,6 +138,12 @@
       return getNormInf();
   }
 
+  /**
+   * Sets the vector
+   * 
+   * @param v
+   * @return x = v
+   */
   public DenseVector set(Vector v) {
     return new DenseVector(((DenseVector) v).getEntries());
   }
@@ -145,6 +185,13 @@
     return 0;
   }
 
+  /**
+   * 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 DenseVector subVector(int i0, int i1) {
     DenseVector res = new DenseVector();
     for (int i = i0; i <= i1; i++) {
@@ -154,6 +201,9 @@
     return res;
   }
 
+  /**
+   * Clears the entries.
+   */
   public void clear() {
     this.entries = null;
   }

Modified: incubator/hama/trunk/src/java/org/apache/hama/HamaAdminImpl.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/HamaAdminImpl.java?rev=744029&r1=744028&r2=744029&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/HamaAdminImpl.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/HamaAdminImpl.java Fri Feb 13 08:32:27 2009
@@ -148,15 +148,15 @@
     matrix.deleteAll(Constants.METADATA, Constants.ALIASENAME);
   }
 
+  /**
+   * we remove the aliase entry store in Admin table, and clear the aliase info
+   * store in matrix table. And check the reference of the matrix table:
+   * 
+   * 1) if the reference of the matrix table is zero: we delete the table. 
+   * 2) if the reference of the matrix table is not zero: we let the matrix who still
+   * reference the table to do the garbage collection.
+   */
   public void delete(String matrixName) throws IOException {
-    // we remove the aliase entry store in Admin table, and
-    // clear the aliase info store in matrix table.
-    // And check the reference of the matrix table:
-    // 1) if the reference of the matrix table is zero:
-    // we delete the table.
-    // 2) if the reference of the matrix table is not zero:
-    // we let the matrix who still reference the table to
-    // do the garbage collection.
     if (matrixExists(matrixName)) {
       String tablename = getPath(matrixName);
 
@@ -164,7 +164,7 @@
       removeEntry(matrixName);
 
       if (tablename == null) { // a matrixName point to a null table. we delete
-                                // the entry.
+        // the entry.
         return;
       }
 



Mime
View raw message