Author: edwardyoon
Date: Thu Jul 31 19:48:48 2008
New Revision: 681592
URL: http://svn.apache.org/viewvc?rev=681592&view=rev
Log: (empty)
Modified:
incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java
incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java
incubator/hama/trunk/src/test/org/apache/hama/mapred/TestMatrixMapReduce.java
Modified: incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java?rev=681592&r1=681591&r2=681592&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java Thu Jul 31
19:48:48 2008
@@ -20,7 +20,6 @@
package org.apache.hama;
import org.apache.hadoop.hbase.HBaseClusterTestCase;
-import org.apache.hadoop.io.Text;
import org.apache.log4j.Logger;
/**
@@ -30,8 +29,6 @@
static final Logger LOG = Logger.getLogger(HamaTestCase.class);
protected Matrix matrixA;
protected Matrix matrixB;
- protected Text A = new Text("matrixA");
- protected Text B = new Text("matrixB");
protected int SIZE = 5;
/** constructor */
Modified: incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java?rev=681592&r1=681591&r2=681592&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java Thu Jul 31
19:48:48 2008
@@ -19,7 +19,18 @@
*/
package org.apache.hama;
-import org.apache.hadoop.hbase.MasterNotRunningException;
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hama.algebra.AdditionMap;
+import org.apache.hama.algebra.AdditionReduce;
+import org.apache.hama.io.VectorDatum;
+import org.apache.hama.mapred.MatrixMap;
+import org.apache.hama.mapred.MatrixReduce;
+import org.apache.hama.mapred.TestMatrixMapReduce;
/**
* Matrix test
@@ -34,51 +45,4 @@
assertTrue(rand.getRowDimension() == SIZE);
rand.close();
}
-
- /**
- * Matrix Test
- */
- public void testMatrix() {
- assertTrue(matrixCreate());
-
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- matrixA.set(i, j, i + j);
- }
- }
- matrixA.setDimension(SIZE, SIZE);
-
- assertTrue(matrixA.getRowDimension() == SIZE);
- assertTrue(matrixA.getColumnDimension() == SIZE);
-
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- assertTrue((i + j) == matrixA.get(i, j));
- }
- }
- matrixClose();
- }
-
- /**
- * Object clear
- */
- public void matrixClose() {
- matrixA.clear();
- matrixA.close();
- }
-
- /**
- * Matrix create
- *
- * @return <code>true</code> if the matrix space was initialized.
- */
- public boolean matrixCreate() {
- matrixA = new Matrix(conf, A);
- try {
- return matrixA.admin.tableExists(A);
- } catch (MasterNotRunningException e) {
- e.printStackTrace();
- return false;
- }
- }
}
Modified:
incubator/hama/trunk/src/test/org/apache/hama/mapred/TestMatrixMapReduce.java
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/mapred/TestMatrixMapReduce.java?rev=681592&r1=681591&r2=681592&view=diff
==============================================================================
---
incubator/hama/trunk/src/test/org/apache/hama/mapred/TestMatrixMapReduce.java
(original)
+++
incubator/hama/trunk/src/test/org/apache/hama/mapred/TestMatrixMapReduce.java
Thu Jul 31 19:48:48 2008
@@ -20,21 +20,15 @@
package org.apache.hama.mapred;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.io.BatchUpdate;
-import org.apache.hadoop.hbase.io.Cell;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.OutputCollector;
-import org.apache.hadoop.mapred.Reporter;
-import org.apache.hama.Vector;
import org.apache.hama.HamaTestCase;
import org.apache.hama.Matrix;
+import org.apache.hama.algebra.AdditionMap;
+import org.apache.hama.algebra.AdditionReduce;
import org.apache.hama.io.VectorDatum;
import org.apache.log4j.Logger;
@@ -49,53 +43,16 @@
super();
}
- public static class AdditionMap extends
- MatrixMap<ImmutableBytesWritable, VectorDatum> {
- protected Matrix B;
- public static final String MATRIX_B =
"hama.addition.substraction.matrix.b";
-
- public void configure(JobConf job) {
- B = new Matrix(new HBaseConfiguration(), new Text("MatrixB"));
- }
-
- @Override
- public void map(ImmutableBytesWritable key, VectorDatum value,
- OutputCollector<ImmutableBytesWritable, VectorDatum> output,
- Reporter reporter) throws IOException {
-
- Vector v1 = new Vector(B.getRowResult(key.get()));
- Vector v2 = value.getVector();
- output.collect(key, v1.addition(key.get(), v2));
- }
- }
-
- public static class AdditionReduce extends
- MatrixReduce<ImmutableBytesWritable, VectorDatum> {
-
- @Override
- public void reduce(ImmutableBytesWritable key, Iterator<VectorDatum>
values,
- OutputCollector<ImmutableBytesWritable, BatchUpdate> output,
- Reporter reporter) throws IOException {
-
- BatchUpdate b = new BatchUpdate(key.get());
- VectorDatum r = values.next();
- for (Map.Entry<byte[], Cell> f : r.entrySet()) {
- b.put(f.getKey(), f.getValue().getValue());
- }
-
- output.collect(key, b);
- }
- }
-
public void testMatrixMapReduce() throws IOException {
- Matrix a = new Matrix(conf, new Text("MatrixA"));
- a.set(0, 0, 1);
- a.set(0, 1, 0);
- Matrix b = new Matrix(conf, new Text("MatrixB"));
- b.set(0, 0, 1);
- b.set(0, 1, 1);
- a.close();
- b.close();
+ matrixA = new Matrix(conf, new Text("MatrixA"));
+ matrixA.set(0, 0, 1);
+ matrixA.set(0, 1, 0);
+
+
+ matrixA = new Matrix(conf, new Text("MatrixB"));
+ matrixA.set(0, 0, 1);
+ matrixA.set(0, 1, 1);
+
miniMRJob();
}
@@ -106,7 +63,7 @@
JobConf jobConf = new JobConf(conf, TestMatrixMapReduce.class);
jobConf.setJobName("test MR job");
- MatrixMap.initJob("MatrixA", "column:", AdditionMap.class,
+ MatrixMap.initJob("MatrixA", "MatrixB", AdditionMap.class,
ImmutableBytesWritable.class, VectorDatum.class, jobConf);
MatrixReduce.initJob("xanadu", AdditionReduce.class, jobConf);