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/09/01 08:02:54 UTC
svn commit: r690854 - in /incubator/hama/trunk: CHANGES.txt
src/java/org/apache/hama/DenseMatrix.java
src/java/org/apache/hama/Matrix.java src/test/org/apache/hama/TestMatrix.java
src/test/org/apache/hama/TestVector.java
Author: edwardyoon
Date: Sun Aug 31 23:02:53 2008
New Revision: 690854
URL: http://svn.apache.org/viewvc?rev=690854&view=rev
Log: (empty)
Modified:
incubator/hama/trunk/CHANGES.txt
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/TestMatrix.java
incubator/hama/trunk/src/test/org/apache/hama/TestVector.java
Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=690854&r1=690853&r2=690854&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Sun Aug 31 23:02:53 2008
@@ -4,6 +4,7 @@
NEW FEATURES
+ HAMA-48: Add getColumn(int column) method which returns column vector (edwardyoon)
HAMA-49: Add iterator() method to vector (edwardyoon)
HAMA-43: Color Hama Logo (Morakot via chanwit)
HAMA-37: Add forrest build to Hudson patch build script (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=690854&r1=690853&r2=690854&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Sun Aug 31 23:02:53 2008
@@ -22,15 +22,21 @@
import java.io.IOException;
import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Scanner;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.io.HbaseMapWritable;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.io.RowResult;
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.mapred.DenseMap;
import org.apache.hama.mapred.MatrixReduce;
+import org.apache.hama.util.Numeric;
import org.apache.hama.util.RandomVariable;
public class DenseMatrix extends AbstractMatrix implements Matrix {
@@ -148,15 +154,24 @@
return null;
}
- public DenseVector getRow(int row) {
- try {
- return new DenseVector(row, table.getRow(String.valueOf(row)));
- } catch (IOException e) {
- LOG.error(e, e);
- }
- return null;
+ public DenseVector getRow(int row) throws IOException {
+ return new DenseVector(row, table.getRow(String.valueOf(row)));
}
+ public Vector getColumn(int column) throws IOException {
+ byte[] columnKey = Numeric.getColumnIndex(column);
+ byte[][] c = { columnKey };
+ Scanner scan = table.getScanner(c, HConstants.EMPTY_START_ROW);
+
+ HbaseMapWritable<byte[], Cell> trunk = new HbaseMapWritable<byte[], Cell>();
+
+ for (RowResult row : scan) {
+ trunk.put(row.getRow(), row.get(columnKey));
+ }
+
+ return new DenseVector(columnKey, trunk);
+ }
+
public Matrix mult(Matrix B) {
// TODO Auto-generated method stub
return null;
@@ -181,5 +196,4 @@
// TODO Auto-generated method stub
return null;
}
-
}
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=690854&r1=690853&r2=690854&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Sun Aug 31 23:02:53 2008
@@ -19,11 +19,13 @@
*/
package org.apache.hama;
+import java.io.IOException;
+
/**
* Basic matrix interface.
*/
public interface Matrix {
-
+
/**
* Gets the double value of (i, j)
*
@@ -37,9 +39,19 @@
* Gets the vector of row
*
* @param row the row index of the matrix
- * @return the feature vector of row
+ * @return the vector of row
+ * @throws IOException
+ */
+ public Vector getRow(int row) throws IOException;
+
+ /**
+ * Gets the vector of column
+ *
+ * @param column the column index of the matrix
+ * @return the vector of column
+ * @throws IOException
*/
- public Vector getRow(int row);
+ public Vector getColumn(int column) throws IOException;
/**
* Get a number of row of the matrix from the meta-data column
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=690854&r1=690853&r2=690854&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestMatrix.java Sun Aug 31 23:02:53 2008
@@ -19,6 +19,12 @@
*/
package org.apache.hama;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hama.util.Numeric;
+
/**
* Matrix test
*/
@@ -26,9 +32,31 @@
/**
* Random matrix creation test
+ *
+ * @throws IOException
+ *
+ * @throws IOException
*/
- public void testRandomMatrix() {
+ public void testRandomMatrix() throws IOException {
Matrix rand = DenseMatrix.random(conf, SIZE, SIZE);
assertTrue(rand.getRows() == SIZE);
+
+ getColumnTest(rand);
+ }
+
+ /**
+ * Column vector test.
+ *
+ * @param rand
+ * @throws IOException
+ */
+ public void getColumnTest(Matrix rand) throws IOException {
+ Vector v = rand.getColumn(0);
+ Iterator<Cell> it = v.iterator();
+ int x = 0;
+ while (it.hasNext()) {
+ assertEquals(rand.get(x, 0), Numeric.bytesToDouble(it.next().getValue()));
+ x++;
+ }
}
}
Modified: incubator/hama/trunk/src/test/org/apache/hama/TestVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestVector.java?rev=690854&r1=690853&r2=690854&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestVector.java Sun Aug 31 23:02:53 2008
@@ -19,6 +19,7 @@
*/
package org.apache.hama;
+import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.hbase.io.Cell;
@@ -33,8 +34,9 @@
/**
* Test vector
+ * @throws IOException
*/
- public void testGetVector() {
+ public void testGetVector() throws IOException {
Matrix m1 = new DenseMatrix(conf, m);
for (int i = 0; i < 2; i++) {