hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r721773 - in /incubator/hama/trunk: ./ src/java/org/apache/hama/ src/java/org/apache/hama/algebra/ src/java/org/apache/hama/io/ src/java/org/apache/hama/mapred/ src/java/org/apache/hama/util/ src/test/org/apache/hama/
Date Sun, 30 Nov 2008 07:18:41 GMT
Author: edwardyoon
Date: Sat Nov 29 23:18:41 2008
New Revision: 721773

URL: http://svn.apache.org/viewvc?rev=721773&view=rev
Log:
Move bytesToSubMatrix/subMatrixToBytes method to submatrix class from BytesUtil

Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/SubMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/algebra/BlockCyclicMultiplyMap.java
    incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java
    incubator/hama/trunk/src/java/org/apache/hama/io/BlockID.java
    incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicMap.java
    incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicReduce.java
    incubator/hama/trunk/src/java/org/apache/hama/util/BytesUtil.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=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Sat Nov 29 23:18:41 2008
@@ -33,6 +33,8 @@
     
   IMPROVEMENTS
     
+    HAMA-117: Move bytesToSubMatrix/subMatrixToBytes method 
+                to submatrix class from BytesUtil (edwardyoon)
     HAMA-114: Remove unwanted code (edwardyoon)
     HAMA-107: Blocking job should be a map/reduce job (samuel via edwardyoon)
     HAMA-99: Implement setColumn(int column, Vector vector) (edwardyoon)

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=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Sat Nov 29 23:18:41 2008
@@ -416,7 +416,7 @@
   }
 
   public SubMatrix getBlock(int i, int j) throws IOException {
-    return BytesUtil.bytesToSubMatrix(table.get(String.valueOf(i),
+    return new SubMatrix(table.get(String.valueOf(i),
         Constants.BLOCK + j).getValue());
   }
 
@@ -437,7 +437,7 @@
 
   public void setBlock(int i, int j, SubMatrix matrix) throws IOException {
     BatchUpdate update = new BatchUpdate(String.valueOf(i));
-    update.put(Constants.BLOCK + j, BytesUtil.subMatrixToBytes(matrix));
+    update.put(Constants.BLOCK + j, matrix.getBytes());
     table.commit(update);
   }
 

Modified: incubator/hama/trunk/src/java/org/apache/hama/SubMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/SubMatrix.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/SubMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/SubMatrix.java Sat Nov 29 23:18:41 2008
@@ -19,6 +19,12 @@
  */
 package org.apache.hama;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import org.apache.log4j.Logger;
 
 /**
@@ -50,6 +56,20 @@
     this.matrix = matrix;
   }
 
+  public SubMatrix(byte[] matrix) throws IOException {
+    ByteArrayInputStream bos = new ByteArrayInputStream(matrix);
+    ObjectInputStream oos = new ObjectInputStream(bos);
+    Object obj = null;
+    try {
+      obj = oos.readObject();
+    } catch (ClassNotFoundException e) {
+      e.printStackTrace();
+    }
+    oos.close();
+    bos.close();
+    this.matrix = ((SubMatrix)obj).matrix;
+  }
+  
   /**
    * Sets the value
    * 
@@ -111,17 +131,35 @@
   public int getRows() {
     return this.matrix.length;
   }
-  
+
   public int getColumns() {
     return this.matrix[0].length;
   }
-  
+
   public void close() {
     matrix = null;
   }
 
-  public double[][] getDoubles() {
+  /**
+   * @return the 2d double array
+   */
+  public double[][] getDoubleArray() {
     double[][] result = matrix;
     return result;
   }
+
+  /**
+   * @return the bytes of the sub matrix
+   * @throws IOException
+   */
+  public byte[] getBytes() throws IOException {
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream oos = new ObjectOutputStream(bos);
+    oos.writeObject(this);
+    oos.flush();
+    oos.close();
+    bos.close();
+    byte[] data = bos.toByteArray();
+    return data;
+  }
 }

Modified: incubator/hama/trunk/src/java/org/apache/hama/algebra/BlockCyclicMultiplyMap.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/algebra/BlockCyclicMultiplyMap.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/algebra/BlockCyclicMultiplyMap.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/algebra/BlockCyclicMultiplyMap.java Sat
Nov 29 23:18:41 2008
@@ -47,7 +47,6 @@
     }
   }
 
-  @SuppressWarnings("unchecked")
   public static void initJob(String matrix_a, String matrix_b,
       Class<BlockCyclicMultiplyMap> map, Class<IntWritable> outputKeyClass,
       Class<BlockWritable> outputValueClass, JobConf jobConf) {

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java Sat Nov 29 23:18:41 2008
@@ -28,7 +28,6 @@
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.Writable;
 import org.apache.hama.SubMatrix;
-import org.apache.hama.util.BytesUtil;
 import org.apache.log4j.Logger;
 
 public class BlockEntry implements Writable, Iterable<BlockEntry> {
@@ -54,7 +53,7 @@
 
   public BlockEntry(SubMatrix value) throws IOException {
     this.values = new byte[1][];
-    this.values[0] = BytesUtil.subMatrixToBytes(value);
+    this.values[0] = value.getBytes();
     this.timestamps = new long[1];
     this.timestamps[0] = System.currentTimeMillis();
   }
@@ -64,7 +63,7 @@
    * @throws IOException
    */
   public SubMatrix getValue() throws IOException {
-    return BytesUtil.bytesToSubMatrix(this.values[0]);
+    return new SubMatrix(this.values[0]);
   }
 
   /** @return the current VectorEntry's timestamp */

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/BlockID.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/BlockID.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/BlockID.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/BlockID.java Sat Nov 29 23:18:41 2008
@@ -27,6 +27,7 @@
 import org.apache.hadoop.io.WritableComparator;
 
 /** A WritableComparable for BlockIDs. */
+@SuppressWarnings("unchecked")
 public class BlockID implements WritableComparable {
   private int row;
   private int column;

Modified: incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicMap.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicMap.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicMap.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicMap.java Sat Nov 29 23:18:41
2008
@@ -35,6 +35,7 @@
 import org.apache.hama.io.BlockWritable;
 import org.apache.log4j.Logger;
 
+@SuppressWarnings("unchecked")
 public abstract class BlockCyclicMap<K extends WritableComparable, V extends Writable>
     extends MapReduceBase implements Mapper<IntWritable, BlockWritable, K, V> {
   static final Logger LOG = Logger.getLogger(BlockCyclicMap.class);

Modified: incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicReduce.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicReduce.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicReduce.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/mapred/BlockCyclicReduce.java Sat Nov 29
23:18:41 2008
@@ -33,6 +33,7 @@
 import org.apache.hadoop.mapred.Reporter;
 import org.apache.hama.io.VectorUpdate;
 
+@SuppressWarnings("unchecked")
 public abstract class BlockCyclicReduce<K extends WritableComparable, V extends Writable>
     extends MapReduceBase implements Reducer<K, V, IntWritable, VectorUpdate> {
   /**

Modified: incubator/hama/trunk/src/java/org/apache/hama/util/BytesUtil.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/BytesUtil.java?rev=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/BytesUtil.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/BytesUtil.java Sat Nov 29 23:18:41
2008
@@ -19,16 +19,10 @@
  */
 package org.apache.hama.util;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.nio.ByteBuffer;
 
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hama.Constants;
-import org.apache.hama.SubMatrix;
 
 /**
  * Provides a bytes utility
@@ -99,31 +93,6 @@
     return Bytes.toBytes(Constants.COLUMN + String.valueOf(integer));
   }
   
-  public static byte[] subMatrixToBytes(SubMatrix obj) throws IOException {
-    ByteArrayOutputStream bos = new ByteArrayOutputStream();
-    ObjectOutputStream oos = new ObjectOutputStream(bos);
-    oos.writeObject(obj);
-    oos.flush();
-    oos.close();
-    bos.close();
-    byte[] data = bos.toByteArray();
-    return data;
-  }
-  
-  public static SubMatrix bytesToSubMatrix(byte[] value) throws IOException {
-    ByteArrayInputStream bos = new ByteArrayInputStream(value);
-    ObjectInputStream oos = new ObjectInputStream(bos);
-    Object obj = null;
-    try {
-      obj = oos.readObject();
-    } catch (ClassNotFoundException e) {
-      e.printStackTrace();
-    }
-    oos.close();
-    bos.close();
-    return (SubMatrix) obj;
-  }
-
   public static byte[] getBlockIndex(int integer) {
     return Bytes.toBytes(Constants.BLOCK + String.valueOf(integer));
   }

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=721773&r1=721772&r2=721773&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Sat Nov 29 23:18:41
2008
@@ -87,8 +87,8 @@
     ((DenseMatrix) m1).blocking_mapred(2);
     assertEquals(((DenseMatrix) m1).isBlocked(), true);
     int[] pos = ((DenseMatrix) m1).getBlockPosition(1, 0);
-    double[][] b = ((DenseMatrix) m1).subMatrix(pos[0], pos[1], pos[2], pos[3]).getDoubles();
-    double[][] c = ((DenseMatrix) m1).getBlock(1, 0).getDoubles();
+    double[][] b = ((DenseMatrix) m1).subMatrix(pos[0], pos[1], pos[2], pos[3]).getDoubleArray();
+    double[][] c = ((DenseMatrix) m1).getBlock(1, 0).getDoubleArray();
     assertEquals(((DenseMatrix) m1).getBlockSize(), 2);
     assertEquals(c.length, 5);
     
@@ -110,8 +110,8 @@
     ((DenseMatrix) m2).blocking_mapred(2);
     assertEquals(((DenseMatrix) m2).isBlocked(), true);
     int[] pos = ((DenseMatrix) m2).getBlockPosition(1, 0);
-    double[][] b = ((DenseMatrix) m2).subMatrix(pos[0], pos[1], pos[2], pos[3]).getDoubles();
-    double[][] c = ((DenseMatrix) m2).getBlock(1, 0).getDoubles();
+    double[][] b = ((DenseMatrix) m2).subMatrix(pos[0], pos[1], pos[2], pos[3]).getDoubleArray();
+    double[][] c = ((DenseMatrix) m2).getBlock(1, 0).getDoubleArray();
     assertEquals(((DenseMatrix) m2).getBlockSize(), 2);
     assertEquals(c.length, 5);
     



Mime
View raw message