incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r742857 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/AbstractMatrix.java src/java/org/apache/hama/DenseMatrix.java src/test/org/apache/hama/TestDenseMatrix.java
Date Tue, 10 Feb 2009 05:31:42 GMT
Author: edwardyoon
Date: Tue Feb 10 05:31:40 2009
New Revision: 742857

URL: http://svn.apache.org/viewvc?rev=742857&view=rev
Log:
Implement set(double alpha, Matrix B)

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/test/org/apache/hama/TestDenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=742857&r1=742856&r2=742857&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Feb 10 05:31:40 2009
@@ -4,7 +4,6 @@
 
   NEW FEATURES
   
-    HAMA-100: Implement of set(Matrix B) (edwardyoon)
     HAMA-145: Add privacy policy page (edwardyoon)
     HAMA-83: 2D sqaure blocking for dense matrix multiplication (edwardyoon)
     HAMA-104: Add getNumMap/reduceTasks to HamaConfiguration (edwardyoon)
@@ -35,6 +34,8 @@
     
   IMPROVEMENTS
     
+    HAMA-148: Implement of set(double alpha, Matrix B) (edwardyoon)
+    HAMA-100: Implement of set(Matrix B) (edwardyoon)
     HAMA-144: GetProgress during MR over a matrix (samuel)
     HAMA-129: Improving speed of matrix multiplication (edwardyoon)
     HAMA-142: Trunk doesn't work for large matrices (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=742857&r1=742856&r2=742857&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Tue Feb 10 05:31:40
2009
@@ -20,6 +20,8 @@
 package org.apache.hama;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -161,6 +163,7 @@
    */
   public static class TableReadMapper extends MapReduceBase implements
       TableMap<ImmutableBytesWritable, BatchUpdate> {
+    private static List<Double> alpha = new ArrayList<Double>();
 
     @SuppressWarnings("unchecked")
     public void map(ImmutableBytesWritable key, RowResult value,
@@ -170,10 +173,24 @@
 
       BatchUpdate update = new BatchUpdate(key.get());
       for (Map.Entry<byte[], Cell> e : value.entrySet()) {
-        update.put(e.getKey(), e.getValue().getValue());
+        if (alpha.size() == 0) {
+          update.put(e.getKey(), e.getValue().getValue());
+        } else {
+          String column = new String(e.getKey());
+          if(column.startsWith(Constants.COLUMN)) {
+            double currValue = BytesUtil.bytesToDouble(e.getValue().getValue());
+            update.put(e.getKey(), (BytesUtil.doubleToBytes(currValue * alpha.get(0))));
+          } else {
+            update.put(e.getKey(), e.getValue().getValue());
+          }
+        }
       }
       output.collect(key, update);
     }
+
+    public static void setAlpha(double a) {
+      alpha.add(a);
+    }
   }
 
   /** {@inheritDoc} */
@@ -186,8 +203,28 @@
 
     TableMapReduceUtil.initTableMapJob(B.getPath(), Constants.COLUMN + " "
         + Constants.ATTRIBUTE + " " + Constants.ALIASEFAMILY + " "
-        + Constants.BLOCK, TableReadMapper.class,
-        ImmutableBytesWritable.class, BatchUpdate.class, jobConf);
+        + Constants.BLOCK, TableReadMapper.class, ImmutableBytesWritable.class,
+        BatchUpdate.class, jobConf);
+    TableMapReduceUtil.initTableReduceJob(this.getPath(),
+        IdentityTableReduce.class, jobConf);
+
+    JobManager.execute(jobConf);
+    return this;
+  }
+
+  /** {@inheritDoc} */
+  public Matrix set(double alpha, Matrix B) throws IOException {
+    JobConf jobConf = new JobConf(config);
+    jobConf.setJobName("set MR job : " + this.getPath());
+
+    jobConf.setNumMapTasks(config.getNumMapTasks());
+    jobConf.setNumReduceTasks(config.getNumReduceTasks());
+
+    TableReadMapper.setAlpha(alpha);
+    TableMapReduceUtil.initTableMapJob(B.getPath(), Constants.COLUMN + " "
+        + Constants.ATTRIBUTE + " " + Constants.ALIASEFAMILY + " "
+        + Constants.BLOCK, TableReadMapper.class, ImmutableBytesWritable.class,
+        BatchUpdate.class, jobConf);
     TableMapReduceUtil.initTableReduceJob(this.getPath(),
         IdentityTableReduce.class, jobConf);
 

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=742857&r1=742856&r2=742857&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Tue Feb 10 05:31:40 2009
@@ -441,11 +441,6 @@
     return 0;
   }
 
-  public Matrix set(double alpha, Matrix B) throws IOException {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
   public void setRow(int row, Vector vector) throws IOException {
     VectorUpdate update = new VectorUpdate(row);
     update.putAll(((DenseVector) vector).getEntries().entrySet());

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=742857&r1=742856&r2=742857&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Tue Feb 10 05:31:40
2009
@@ -215,6 +215,17 @@
     }
   }
 
+  public void testSetAlphaMatrix() throws IOException {
+    Matrix a = new DenseMatrix(conf);
+    a.set(0.5, m1);
+    
+    for (int i = 0; i < 5; i++) {
+      int x = RandomVariable.randInt(0, 10);
+      int y = RandomVariable.randInt(0, 10);
+      assertEquals(a.get(x, y), (m1.get(x, y) * 0.5));
+    }
+  }
+  
   public void testLoadSave() throws IOException {
     String path1 = m1.getPath();
     // save m1 to aliase1



Mime
View raw message