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 2008/11/26 01:35:31 UTC

svn commit: r720684 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/AbstractMatrix.java src/java/org/apache/hama/DenseMatrix.java src/java/org/apache/hama/Matrix.java src/test/org/apache/hama/TestDenseMatrix.java

Author: edwardyoon
Date: Tue Nov 25 16:35:30 2008
New Revision: 720684

URL: http://svn.apache.org/viewvc?rev=720684&view=rev
Log:
DenseMatrix.get(i, j) should returns zero when entry is null

Modified:
    incubator/hama/trunk/CHANGES.txt
    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/Matrix.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=720684&r1=720683&r2=720684&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Nov 25 16:35:30 2008
@@ -80,6 +80,8 @@
 
   BUG FIXES
    
+    HAMA-112: DenseMatrix.get(i, j) should returns zero 
+                when entry is null (edwardyoon)
     HAMA-106: SubMatrix should be able to get row, column size (edwardyoon)
     HAMA-98: change '~=' operation to use `echo $f | grep 'examples$'` 
                (samuel via edwardyoon)

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=720684&r1=720683&r2=720684&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Tue Nov 25 16:35:30 2008
@@ -94,16 +94,6 @@
   }
 
   /** {@inheritDoc} */
-  public double get(int i, int j) throws IOException {
-    double result = -1;
-    Cell c = table.get(BytesUtil.intToBytes(i), BytesUtil.getColumnIndex(j));
-    if (c != null) {
-      result = BytesUtil.bytesToDouble(c.getValue());
-    }
-    return result;
-  }
-
-  /** {@inheritDoc} */
   public int getRows() throws IOException {
     Cell rows = null;
     rows = table.get(Constants.METADATA, Constants.METADATA_ROWS);
@@ -139,7 +129,7 @@
     table.commit(update.getBatchUpdate());
   }
 
-  public String getRowAttribute(int row) throws IOException {
+  public String getRowLabel(int row) throws IOException {
     Cell rows = null;
     rows = table.get(BytesUtil.intToBytes(row), Bytes.toBytes(Constants.ATTRIBUTE
         + "string"));
@@ -147,19 +137,19 @@
     return (rows != null) ? Bytes.toString(rows.getValue()) : null;
   }
 
-  public void setRowAttribute(int row, String name) throws IOException {
+  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 getColumnAttribute(int column) 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;
   }
 
-  public void setColumnAttribute(int column, String name) throws IOException {
+  public void setColumnLabel(int column, String name) throws IOException {
     VectorUpdate update = new VectorUpdate(Constants.CINDEX);
     update.put(column, name);
     table.commit(update.getBatchUpdate());

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=720684&r1=720683&r2=720684&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Tue Nov 25 16:35:30 2008
@@ -252,6 +252,19 @@
     return identity;
   }
 
+  /**
+   * Gets the double value of (i, j)
+   * 
+   * @param i ith row of the matrix
+   * @param j jth column of the matrix
+   * @return the value of entry, or zero If entry is null
+   * @throws IOException
+   */
+  public double get(int i, int j) throws IOException {
+    Cell c = table.get(BytesUtil.intToBytes(i), BytesUtil.getColumnIndex(j));
+    return (c != null) ? BytesUtil.bytesToDouble(c.getValue()) : 0;
+  }
+
   public Matrix add(Matrix B) throws IOException {
     Matrix result = new DenseMatrix(config);
 
@@ -349,7 +362,7 @@
   }
 
   public void setColumn(int column, Vector vector) throws IOException {
-    for(int i = 0; i < vector.size(); i++) {
+    for (int i = 0; i < vector.size(); i++) {
       VectorUpdate update = new VectorUpdate(i);
       update.put(column, vector.get(i));
       table.commit(update.getBatchUpdate());

Modified: incubator/hama/trunk/src/java/org/apache/hama/Matrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Matrix.java?rev=720684&r1=720683&r2=720684&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Tue Nov 25 16:35:30 2008
@@ -71,18 +71,18 @@
   public int getColumns() throws IOException;
 
   /**
-   * Gets the attribute of the row
+   * Gets the label of the row
    * 
    * @throws IOException
    */
-  public String getRowAttribute(int i) throws IOException;
+  public String getRowLabel(int i) throws IOException;
 
   /**
-   * Gets the attribute of the column
+   * Gets the label of the column
    * 
    * @throws IOException
    */
-  public String getColumnAttribute(int j) throws IOException;
+  public String getColumnLabel(int j) throws IOException;
 
   /**
    * Return the matrix path. 
@@ -93,22 +93,22 @@
   public String getPath();
 
   /**
-   * Sets the attribute of the row
+   * Sets the label of the row
    * 
    * @param i
    * @param name
    * @throws IOException
    */
-  public void setRowAttribute(int i, String name) throws IOException;
+  public void setRowLabel(int i, String name) throws IOException;
 
   /**
-   * Sets the attribute of the column
+   * Sets the label of the column
    * 
    * @param j
    * @param name
    * @throws IOException
    */
-  public void setColumnAttribute(int j, String name) throws IOException;
+  public void setColumnLabel(int j, String name) throws IOException;
 
   /**
    * Sets the double value of (i, j)

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java?rev=720684&r1=720683&r2=720684&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Tue Nov 25 16:35:30 2008
@@ -120,13 +120,13 @@
   }
   
   public void testGetSetAttribute() throws IOException {
-    m1.setRowAttribute(0, "row1");
-    assertEquals(m1.getRowAttribute(0), "row1");
-    assertEquals(m1.getRowAttribute(1), null);
-
-    m1.setColumnAttribute(0, "column1");
-    assertEquals(m1.getColumnAttribute(0), "column1");
-    assertEquals(m1.getColumnAttribute(1), null);
+    m1.setRowLabel(0, "row1");
+    assertEquals(m1.getRowLabel(0), "row1");
+    assertEquals(m1.getRowLabel(1), null);
+
+    m1.setColumnLabel(0, "column1");
+    assertEquals(m1.getColumnLabel(0), "column1");
+    assertEquals(m1.getColumnLabel(1), null);
   }
 
   public void testSubMatrix() throws IOException {