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/13 07:31:28 UTC

svn commit: r713656 - in /incubator/hama/trunk/src: java/org/apache/hama/ java/org/apache/hama/io/ java/org/apache/hama/util/ test/org/apache/hama/

Author: edwardyoon
Date: Wed Nov 12 22:31:27 2008
New Revision: 713656

URL: http://svn.apache.org/viewvc?rev=713656&view=rev
Log: (empty)

Added:
    incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java
    incubator/hama/trunk/src/java/org/apache/hama/io/DoubleEntry.java
Removed:
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorEntry.java
Modified:
    incubator/hama/trunk/src/java/org/apache/hama/AbstractVector.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/Vector.java
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorMapWritable.java
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java
    incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java

Modified: incubator/hama/trunk/src/java/org/apache/hama/AbstractVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/AbstractVector.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractVector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractVector.java Wed Nov 12 22:31:27 2008
@@ -21,11 +21,11 @@
 
 import java.util.Iterator;
 
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 import org.apache.hama.io.VectorMapWritable;
 
 public abstract class AbstractVector {
-  public VectorMapWritable<Integer, VectorEntry> entries;
+  public VectorMapWritable<Integer, DoubleEntry> entries;
   
   public double get(int index) throws NullPointerException {
     return this.entries.get(index).getValue();
@@ -34,10 +34,10 @@
   public void set(int index, double value) {
     // If entries are null, create new object 
     if(this.entries == null) {
-      this.entries = new VectorMapWritable<Integer, VectorEntry>();
+      this.entries = new VectorMapWritable<Integer, DoubleEntry>();
     }
     
-    this.entries.put(index, new VectorEntry(value));
+    this.entries.put(index, new DoubleEntry(value));
   }
   
   public void add(int index, double value) {
@@ -49,7 +49,7 @@
    * 
    * @return iterator
    */
-  public Iterator<VectorEntry> iterator() {
+  public Iterator<DoubleEntry> iterator() {
     return this.entries.values().iterator();
   }
   
@@ -62,7 +62,7 @@
     return (this.entries != null) ? this.entries.size() : 0;
   }
   
-  public VectorMapWritable<Integer, VectorEntry> getEntries() {
+  public VectorMapWritable<Integer, DoubleEntry> getEntries() {
     return this.entries;
   }
 }

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=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Wed Nov 12 22:31:27 2008
@@ -34,7 +34,7 @@
 import org.apache.hama.algebra.RowCyclicAdditionReduce;
 import org.apache.hama.algebra.SIMDMultiplyMap;
 import org.apache.hama.algebra.SIMDMultiplyReduce;
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 import org.apache.hama.io.VectorMapWritable;
 import org.apache.hama.io.VectorUpdate;
 import org.apache.hama.io.VectorWritable;
@@ -276,11 +276,11 @@
     byte[][] c = { columnKey };
     Scanner scan = table.getScanner(c, HConstants.EMPTY_START_ROW);
 
-    VectorMapWritable<Integer, VectorEntry> trunk = new VectorMapWritable<Integer, VectorEntry>();
+    VectorMapWritable<Integer, DoubleEntry> trunk = new VectorMapWritable<Integer, DoubleEntry>();
 
     for (RowResult row : scan) {
       trunk.put(Numeric.bytesToInt(row.getRow()), 
-          new VectorEntry(row.get(columnKey)));
+          new DoubleEntry(row.get(columnKey)));
     }
 
     return new DenseVector(trunk);

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=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseVector.java Wed Nov 12 22:31:27 2008
@@ -25,7 +25,7 @@
 
 import org.apache.hadoop.hbase.io.Cell;
 import org.apache.hadoop.hbase.io.RowResult;
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 import org.apache.hama.io.VectorMapWritable;
 import org.apache.hama.util.Numeric;
 import org.apache.log4j.Logger;
@@ -34,18 +34,18 @@
   static final Logger LOG = Logger.getLogger(DenseVector.class);
 
   public DenseVector() {
-    this(new VectorMapWritable<Integer, VectorEntry>());
+    this(new VectorMapWritable<Integer, DoubleEntry>());
   }
 
-  public DenseVector(VectorMapWritable<Integer, VectorEntry> m) {
+  public DenseVector(VectorMapWritable<Integer, DoubleEntry> m) {
     this.entries = m;
   }
 
   public DenseVector(RowResult row) {
-    this.entries = new VectorMapWritable<Integer, VectorEntry>();
+    this.entries = new VectorMapWritable<Integer, DoubleEntry>();
     for (Map.Entry<byte[], Cell> f : row.entrySet()) {
       this.entries.put(Numeric.getColumnIndex(f.getKey()), 
-          new VectorEntry(f.getValue()));
+          new DoubleEntry(f.getValue()));
     }
   }
 
@@ -69,7 +69,7 @@
     for (int i = 0; i < this.size(); i++) {
       double value = (this.get(i) + v2.get(i));
 
-      this.entries.put(i, new VectorEntry(value));
+      this.entries.put(i, new DoubleEntry(value));
     }
 
     return this;
@@ -87,8 +87,8 @@
   }
 
   public Vector scale(double alpha) {
-    for(Map.Entry<Integer, VectorEntry> e : this.entries.entrySet()) {
-      this.entries.put(e.getKey(), new VectorEntry(e.getValue().getValue() * alpha));
+    for(Map.Entry<Integer, DoubleEntry> e : this.entries.entrySet()) {
+      this.entries.put(e.getKey(), new DoubleEntry(e.getValue().getValue() * alpha));
     }
     return this;
   }

Modified: incubator/hama/trunk/src/java/org/apache/hama/Vector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Vector.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Vector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Vector.java Wed Nov 12 22:31:27 2008
@@ -21,7 +21,7 @@
 
 import java.util.Iterator;
 
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 
 /**
  * Basic vector interface.
@@ -143,5 +143,5 @@
    * 
    * @return iterator
    */
-  public Iterator<VectorEntry> iterator();
+  public Iterator<DoubleEntry> iterator();
 }

Added: 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=713656&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/BlockEntry.java Wed Nov 12 22:31:27 2008
@@ -0,0 +1,129 @@
+package org.apache.hama.io;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.Writable;
+import org.apache.hama.SubMatrix;
+import org.apache.hama.util.Numeric;
+import org.apache.log4j.Logger;
+
+public class BlockEntry implements Writable, Iterable<BlockEntry> {
+  static final Logger LOG = Logger.getLogger(BlockEntry.class);
+  protected byte[][] values;
+  
+  // We don't need this.
+  @Deprecated
+  protected long[] timestamps;
+
+  /** For Writable compatibility */
+  public BlockEntry() {
+    values = null;
+    timestamps = null;
+  }
+
+  public BlockEntry(Cell c) {
+    this.values = new byte[1][];
+    this.values[0] = c.getValue();
+    this.timestamps = new long[1];
+    this.timestamps[0] = c.getTimestamp();
+  }
+
+  public BlockEntry(SubMatrix value) throws IOException {
+    this.values = new byte[1][];
+    this.values[0] = Numeric.subMatrixToBytes(value);
+    this.timestamps = new long[1];
+    this.timestamps[0] = System.currentTimeMillis();
+  }
+
+  /**
+   * @return the current VectorEntry's value
+   * @throws IOException
+   * @throws ClassNotFoundException
+   */
+  public SubMatrix getValue() throws IOException, ClassNotFoundException {
+    return Numeric.bytesToSubMatrix(this.values[0]);
+  }
+
+  /** @return the current VectorEntry's timestamp */
+  public long getTimestamp() {
+    return timestamps[0];
+  }
+
+  /**
+   * Create a new VectorEntry with a given value and timestamp. Used by HStore.
+   * 
+   * @param value
+   * @param timestamp
+   */
+  public BlockEntry(byte[] value, long timestamp) {
+    this.values = new byte[1][];
+    this.values[0] = value;
+    this.timestamps = new long[1];
+    this.timestamps[0] = timestamp;
+  }
+
+  //
+  // Writable
+  //
+
+  /** {@inheritDoc} */
+  public void readFields(final DataInput in) throws IOException {
+    int nvalues = in.readInt();
+    this.timestamps = new long[nvalues];
+    this.values = new byte[nvalues][];
+    for (int i = 0; i < nvalues; i++) {
+      this.timestamps[i] = in.readLong();
+    }
+    for (int i = 0; i < nvalues; i++) {
+      this.values[i] = Bytes.readByteArray(in);
+    }
+  }
+
+  /** {@inheritDoc} */
+  public void write(final DataOutput out) throws IOException {
+    out.writeInt(this.values.length);
+    for (int i = 0; i < this.timestamps.length; i++) {
+      out.writeLong(this.timestamps[i]);
+    }
+    for (int i = 0; i < this.values.length; i++) {
+      Bytes.writeByteArray(out, this.values[i]);
+    }
+  }
+
+  //
+  // Iterable
+  //
+
+  /** {@inheritDoc} */
+  public Iterator<BlockEntry> iterator() {
+    return new BlockEntryIterator();
+  }
+
+  private class BlockEntryIterator implements Iterator<BlockEntry> {
+    private int currentValue = -1;
+
+    BlockEntryIterator() {
+    }
+
+    /** {@inheritDoc} */
+    public boolean hasNext() {
+      return currentValue < values.length;
+    }
+
+    /** {@inheritDoc} */
+    public BlockEntry next() {
+      currentValue += 1;
+      return new BlockEntry(values[currentValue], timestamps[currentValue]);
+    }
+
+    /** {@inheritDoc} */
+    public void remove() throws UnsupportedOperationException {
+      throw new UnsupportedOperationException("remove is not supported");
+    }
+  }
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/io/DoubleEntry.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/DoubleEntry.java?rev=713656&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/DoubleEntry.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/DoubleEntry.java Wed Nov 12 22:31:27 2008
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.io;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.Writable;
+import org.apache.hama.util.Numeric;
+import org.apache.log4j.Logger;
+
+public class DoubleEntry implements Writable, Iterable<DoubleEntry> {
+  static final Logger LOG = Logger.getLogger(DoubleEntry.class);
+  protected byte[][] values;
+  
+  // We don't need this.
+  @Deprecated
+  protected long[] timestamps;
+  
+  /** For Writable compatibility */
+  public DoubleEntry() {
+    values = null;
+    timestamps = null;
+  }
+
+  public DoubleEntry(Cell c) {
+    this.values = new byte[1][];
+    this.values[0] = c.getValue();
+    this.timestamps = new long[1];
+    this.timestamps[0] = c.getTimestamp();
+  }
+
+  public DoubleEntry(double value) {
+    this.values = new byte[1][];
+    this.values[0] = Numeric.doubleToBytes(value);
+    this.timestamps = new long[1];
+    this.timestamps[0] = System.currentTimeMillis();
+  }
+  
+  /** @return the current VectorEntry's value */
+  public double getValue() {
+    return Numeric.bytesToDouble(this.values[0]);
+  }
+
+  /** @return the current VectorEntry's timestamp */
+  public long getTimestamp() {
+    return timestamps[0];
+  }
+
+  /**
+   * Create a new VectorEntry with a given value and timestamp. Used by HStore.
+   * 
+   * @param value
+   * @param timestamp
+   */
+  public DoubleEntry(byte[] value, long timestamp) {
+    this.values = new byte[1][];
+    this.values[0] = value;
+    this.timestamps = new long[1];
+    this.timestamps[0] = timestamp;
+  }
+
+  //
+  // Writable
+  //
+
+  /** {@inheritDoc} */
+  public void readFields(final DataInput in) throws IOException {
+    int nvalues = in.readInt();
+    this.timestamps = new long[nvalues];
+    this.values = new byte[nvalues][];
+    for (int i = 0; i < nvalues; i++) {
+      this.timestamps[i] = in.readLong();
+    }
+    for (int i = 0; i < nvalues; i++) {
+      this.values[i] = Bytes.readByteArray(in);
+    }
+  }
+
+  /** {@inheritDoc} */
+  public void write(final DataOutput out) throws IOException {
+    out.writeInt(this.values.length);
+    for (int i = 0; i < this.timestamps.length; i++) {
+      out.writeLong(this.timestamps[i]);
+    }
+    for (int i = 0; i < this.values.length; i++) {
+      Bytes.writeByteArray(out, this.values[i]);
+    }
+  }
+
+  //
+  // Iterable
+  //
+
+  /** {@inheritDoc} */
+  public Iterator<DoubleEntry> iterator() {
+    return new VectorEntryIterator();
+  }
+
+  private class VectorEntryIterator implements Iterator<DoubleEntry> {
+    private int currentValue = -1;
+
+    VectorEntryIterator() {
+    }
+
+    /** {@inheritDoc} */
+    public boolean hasNext() {
+      return currentValue < values.length;
+    }
+
+    /** {@inheritDoc} */
+    public DoubleEntry next() {
+      currentValue += 1;
+      return new DoubleEntry(values[currentValue], timestamps[currentValue]);
+    }
+
+    /** {@inheritDoc} */
+    public void remove() throws UnsupportedOperationException {
+      throw new UnsupportedOperationException("remove is not supported");
+    }
+  }
+}

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/VectorMapWritable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/VectorMapWritable.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/VectorMapWritable.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/VectorMapWritable.java Wed Nov 12 22:31:27 2008
@@ -53,7 +53,7 @@
     addToMap(HStoreKey.class, code++);
     addToMap(ImmutableBytesWritable.class, code++);
     addToMap(Text.class, code++);
-    addToMap(VectorEntry.class, code++);
+    addToMap(DoubleEntry.class, code++);
     addToMap(byte[].class, code++);
   }
 

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java Wed Nov 12 22:31:27 2008
@@ -71,8 +71,8 @@
     }
   }
 
-  public void putAll(Set<Entry<Integer, VectorEntry>> entrySet) {
-    for (Map.Entry<Integer, VectorEntry> e : entrySet) {
+  public void putAll(Set<Entry<Integer, DoubleEntry>> entrySet) {
+    for (Map.Entry<Integer, DoubleEntry> e : entrySet) {
       put(e.getKey(), e.getValue().getValue());
     }
   }

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/VectorWritable.java Wed Nov 12 22:31:27 2008
@@ -35,16 +35,16 @@
 import org.apache.hama.Vector;
 import org.apache.hama.util.Numeric;
 
-public class VectorWritable implements Writable, Map<Integer, VectorEntry> {
+public class VectorWritable implements Writable, Map<Integer, DoubleEntry> {
 
   public Integer row;
-  public VectorMapWritable<Integer, VectorEntry> entries;
+  public VectorMapWritable<Integer, DoubleEntry> entries;
 
   public VectorWritable() {
-    this(new VectorMapWritable<Integer, VectorEntry>());
+    this(new VectorMapWritable<Integer, DoubleEntry>());
   }
 
-  public VectorWritable(VectorMapWritable<Integer, VectorEntry> entries) {
+  public VectorWritable(VectorMapWritable<Integer, DoubleEntry> entries) {
     this.entries = entries;
   }
 
@@ -65,15 +65,15 @@
     return this.entries.size();
   }
   
-  public VectorEntry put(Integer key, VectorEntry value) {
+  public DoubleEntry put(Integer key, DoubleEntry value) {
     throw new UnsupportedOperationException("VectorWritable is read-only!");
   }
 
-  public VectorEntry get(Object key) {
+  public DoubleEntry get(Object key) {
     return this.entries.get(key);
   }
 
-  public VectorEntry remove(Object key) {
+  public DoubleEntry remove(Object key) {
     throw new UnsupportedOperationException("VectorWritable is read-only!");
   }
 
@@ -101,14 +101,14 @@
     return result;
   }
 
-  public Set<Map.Entry<Integer, VectorEntry>> entrySet() {
+  public Set<Map.Entry<Integer, DoubleEntry>> entrySet() {
     return Collections.unmodifiableSet(this.entries.entrySet());
   }
 
-  public Collection<VectorEntry> values() {
-    ArrayList<VectorEntry> result = new ArrayList<VectorEntry>();
+  public Collection<DoubleEntry> values() {
+    ArrayList<DoubleEntry> result = new ArrayList<DoubleEntry>();
     for (Writable w : entries.values()) {
-      result.add((VectorEntry) w);
+      result.add((DoubleEntry) w);
     }
     return result;
   }
@@ -127,7 +127,7 @@
     throw new UnsupportedOperationException("Not implemented yet");
   }
 
-  public void putAll(Map<? extends Integer, ? extends VectorEntry> m) {
+  public void putAll(Map<? extends Integer, ? extends DoubleEntry> m) {
     throw new UnsupportedOperationException("Not implemented yet");
   }
 
@@ -136,17 +136,17 @@
    * The inner class for an entry of row.
    * 
    */
-  public static class Entries implements Map.Entry<byte[], VectorEntry> {
+  public static class Entries implements Map.Entry<byte[], DoubleEntry> {
 
     private final byte[] column;
-    private final VectorEntry entry;
+    private final DoubleEntry entry;
 
-    Entries(byte[] column, VectorEntry entry) {
+    Entries(byte[] column, DoubleEntry entry) {
       this.column = column;
       this.entry = entry;
     }
 
-    public VectorEntry setValue(VectorEntry c) {
+    public DoubleEntry setValue(DoubleEntry c) {
       throw new UnsupportedOperationException("VectorWritable is read-only!");
     }
 
@@ -155,7 +155,7 @@
       return key;
     }
 
-    public VectorEntry getValue() {
+    public DoubleEntry getValue() {
       return entry;
     }
   }

Modified: incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java Wed Nov 12 22:31:27 2008
@@ -19,10 +19,16 @@
  */
 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 number format conversion
@@ -92,4 +98,25 @@
   public static byte[] getColumnIndex(int integer) {
     return Bytes.toBytes(Constants.COLUMN + String.valueOf(integer));
   }
+  
+  public static byte[] subMatrixToBytes(Object 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,
+      ClassNotFoundException {
+    ByteArrayInputStream bos = new ByteArrayInputStream(value);
+    ObjectInputStream oos = new ObjectInputStream(bos);
+    Object obj = oos.readObject();
+    oos.close();
+    bos.close();
+    return (SubMatrix) obj;
+  }
 }

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=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Wed Nov 12 22:31:27 2008
@@ -28,7 +28,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 import org.apache.log4j.Logger;
 
 /**
@@ -83,7 +83,7 @@
    */
   public void testGetColumn() throws IOException {
     Vector v = m1.getColumn(0);
-    Iterator<VectorEntry> it = v.iterator();
+    Iterator<DoubleEntry> it = v.iterator();
     int x = 0;
     while (it.hasNext()) {
       assertEquals(m1.get(x, 0), it.next().getValue());
@@ -169,7 +169,7 @@
     }
 
     m1.setRow(SIZE + 1, v);
-    Iterator<VectorEntry> it = m1.getRow(SIZE + 1).iterator();
+    Iterator<DoubleEntry> it = m1.getRow(SIZE + 1).iterator();
 
     // We should remove the timestamp and row attribute from the vector
     int i = 0;

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java?rev=713656&r1=713655&r2=713656&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java Wed Nov 12 22:31:27 2008
@@ -28,7 +28,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hama.io.VectorEntry;
+import org.apache.hama.io.DoubleEntry;
 
 public class TestDenseVector extends TestCase {
   final static Log LOG = LogFactory.getLog(TestDenseVector.class.getName());
@@ -75,7 +75,7 @@
   public void testSubVector() {
     int start = 2;
     Vector subVector = v1.subVector(start, v1.size() - 1);
-    Iterator<VectorEntry> it = subVector.iterator();
+    Iterator<DoubleEntry> it = subVector.iterator();
 
     int i = start;
     while (it.hasNext()) {
@@ -124,18 +124,18 @@
   public void testAdd() {
     v1.add(v2);
     int i = 0;
-    Iterator<VectorEntry> it = v1.iterator();
+    Iterator<DoubleEntry> it = v1.iterator();
     while (it.hasNext()) {
-      VectorEntry c = it.next();
+      DoubleEntry c = it.next();
       assertEquals(c.getValue(), values[0][i] + values[1][i]);
       i++;
     }
 
     v1.add(0.5, v2);
     int j = 0;
-    Iterator<VectorEntry> itt = v1.iterator();
+    Iterator<DoubleEntry> itt = v1.iterator();
     while (itt.hasNext()) {
-      VectorEntry c = itt.next();
+      DoubleEntry c = itt.next();
       assertEquals(c.getValue(), (values[0][j] + values[1][j]) + (0.5 * values[1][j]));
       j++;
     }