Author: edwardyoon
Date: Sun Sep 7 19:28:42 2008
New Revision: 692985
URL: http://svn.apache.org/viewvc?rev=692985&view=rev
Log:
Operations should throws an IOException
Modified:
incubator/hama/trunk/CHANGES.txt
incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
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/TestDenseMatrix.java
Modified: incubator/hama/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=692985&r1=692984&r2=692985&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Sun Sep 7 19:28:42 2008
@@ -22,6 +22,7 @@
IMPROVEMENTS
+ HAMA-39: IO operations should throws an IOException (edwardyoon)
HAMA-52: Fixture setup (edwardyoon)
HAMA-42: Replace ImmutableBytesWritable to IntWritable (edwardyoon)
HAMA-44: Remove findbugs warnings (edwardyoon)
Modified:
incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java?rev=692985&r1=692984&r2=692985&view=diff
==============================================================================
---
incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
(original)
+++
incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
Sun Sep 7 19:28:42 2008
@@ -19,13 +19,15 @@
*/
package org.apache.hama.examples;
+import java.io.IOException;
+
import org.apache.hama.DenseMatrix;
import org.apache.hama.HamaConfiguration;
import org.apache.hama.Matrix;
public class MatrixAddition {
- public static void main(String[] args) {
+ public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.out.println("addition <row_m> <column_n>");
System.exit(-1);
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=692985&r1=692984&r2=692985&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Sun Sep
7 19:28:42 2008
@@ -78,71 +78,49 @@
}
/** [EMAIL PROTECTED] */
- public double get(int i, int j) {
- Cell c;
+ public double get(int i, int j) throws IOException {
double result = -1;
- try {
- c = table.get(Bytes.toBytes(String.valueOf(i)),
Numeric.getColumnIndex(j));
- if (c != null) {
- result = Numeric.bytesToDouble(c.getValue());
- }
- } catch (IOException e) {
- LOG.error(e, e);
+ Cell c = table.get(Bytes.toBytes(String.valueOf(i)), Numeric
+ .getColumnIndex(j));
+ if (c != null) {
+ result = Numeric.bytesToDouble(c.getValue());
}
return result;
}
/** [EMAIL PROTECTED] */
- public int getRows() {
+ public int getRows() throws IOException {
Cell rows = null;
- try {
- rows = table.get(Constants.METADATA, Constants.METADATA_ROWS);
- } catch (IOException e) {
- LOG.error(e, e);
- }
-
+ rows = table.get(Constants.METADATA, Constants.METADATA_ROWS);
return Bytes.toInt(rows.getValue());
}
/** [EMAIL PROTECTED] */
- public int getColumns() {
- Cell columns = null;
- try {
- columns = table.get(Constants.METADATA, Constants.METADATA_COLUMNS);
- } catch (IOException e) {
- LOG.error(e, e);
- }
+ public int getColumns() throws IOException {
+ Cell columns = table.get(Constants.METADATA, Constants.METADATA_COLUMNS);
return Bytes.toInt(columns.getValue());
}
/** [EMAIL PROTECTED] */
- public void set(int i, int j, double value) {
+ public void set(int i, int j, double value) throws IOException {
BatchUpdate b = new BatchUpdate(new Text(String.valueOf(i)));
b.put(new Text(Constants.COLUMN + String.valueOf(j)), Numeric
.doubleToBytes(value));
- try {
- table.commit(b);
- } catch (IOException e) {
- LOG.error(e, e);
- }
+ table.commit(b);
}
/** [EMAIL PROTECTED] */
- public void add(int i, int j, double value) {
+ public void add(int i, int j, double value) throws IOException {
// TODO Auto-generated method stub
}
/** [EMAIL PROTECTED] */
- public void setDimension(int rows, int columns) {
+ public void setDimension(int rows, int columns) throws IOException {
BatchUpdate b = new BatchUpdate(Constants.METADATA);
b.put(Constants.METADATA_ROWS, Bytes.toBytes(rows));
b.put(Constants.METADATA_COLUMNS, Bytes.toBytes(columns));
- try {
- table.commit(b);
- } catch (IOException e) {
- LOG.error(e, e);
- }
+ table.commit(b);
}
/** [EMAIL PROTECTED] */
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=692985&r1=692984&r2=692985&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Sun Sep 7
19:28:42 2008
@@ -115,8 +115,10 @@
* @param m the number of rows.
* @param n the number of columns.
* @return an m-by-n matrix with uniformly distributed random elements.
+ * @throws IOException
*/
- public static Matrix random(HamaConfiguration conf, int m, int n) {
+ public static Matrix random(HamaConfiguration conf, int m, int n)
+ throws IOException {
String name = RandomVariable.randMatrixName();
Matrix rand = new DenseMatrix(conf, name);
for (int i = 0; i < m; i++) {
@@ -130,7 +132,7 @@
return rand;
}
- public Matrix add(Matrix B) {
+ public Matrix add(Matrix B) throws IOException {
String output = RandomVariable.randMatrixName();
Matrix C = new DenseMatrix(config, output);
@@ -141,16 +143,11 @@
IntWritable.class, DenseVector.class, jobConf);
MatrixReduce.initJob(C.getName(), AdditionReduce.class, jobConf);
- try {
- JobClient.runJob(jobConf);
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+ JobClient.runJob(jobConf);
return C;
}
- public Matrix add(double alpha, Matrix B) {
+ public Matrix add(double alpha, Matrix B) throws IOException {
// TODO Auto-generated method stub
return null;
}
@@ -158,7 +155,7 @@
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 };
@@ -167,13 +164,14 @@
VectorMapWritable<Integer, VectorEntry> trunk = new
VectorMapWritable<Integer, VectorEntry>();
for (RowResult row : scan) {
- trunk.put(Numeric.bytesToInt(row.getRow()), new
VectorEntry(row.get(columnKey)));
+ trunk.put(Numeric.bytesToInt(row.getRow()), new VectorEntry(row
+ .get(columnKey)));
}
return new DenseVector(column, trunk);
}
- public Matrix mult(Matrix B) {
+ public Matrix mult(Matrix B) throws IOException {
String output = RandomVariable.randMatrixName();
Matrix C = new DenseMatrix(config, output);
@@ -184,31 +182,26 @@
IntWritable.class, DenseVector.class, jobConf);
MatrixReduce.initJob(C.getName(), MultiplicationReduce.class, jobConf);
- try {
- JobClient.runJob(jobConf);
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+ JobClient.runJob(jobConf);
return C;
}
- public Matrix multAdd(double alpha, Matrix B, Matrix C) {
+ public Matrix multAdd(double alpha, Matrix B, Matrix C) throws IOException {
// TODO Auto-generated method stub
return null;
}
- public double norm(Norm type) {
+ public double norm(Norm type) throws IOException {
// TODO Auto-generated method stub
return 0;
}
- public Matrix set(double alpha, Matrix B) {
+ public Matrix set(double alpha, Matrix B) throws IOException {
// TODO Auto-generated method stub
return null;
}
- public Matrix set(Matrix B) {
+ public Matrix set(Matrix B) throws IOException {
// 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=692985&r1=692984&r2=692985&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Sun Sep 7
19:28:42 2008
@@ -32,8 +32,9 @@
* @param i ith row of the matrix
* @param j jth column of the matrix
* @return the value of entry
+ * @throws IOException
*/
- public double get(int i, int j);
+ public double get(int i, int j) throws IOException;
/**
* Gets the vector of row
@@ -57,15 +58,17 @@
* Get a number of row of the matrix from the meta-data column
*
* @return a number of rows of the matrix
+ * @throws IOException
*/
- public int getRows();
+ public int getRows() throws IOException;
/**
* Get a number of column of the matrix from the meta-data column
*
* @return a number of columns of the matrix
+ * @throws IOException
*/
- public int getColumns();
+ public int getColumns() throws IOException;
/**
* Sets the double value of (i, j)
@@ -73,8 +76,9 @@
* @param i ith row of the matrix
* @param j jth column of the matrix
* @param value the value of entry
+ * @throws IOException
*/
- public void set(int i, int j, double value);
+ public void set(int i, int j, double value) throws IOException;
/**
* A=alpha*B
@@ -82,24 +86,27 @@
* @param alpha
* @param B
* @return A
+ * @throws IOException
*/
- public Matrix set(double alpha, Matrix B);
+ public Matrix set(double alpha, Matrix B) throws IOException;
/**
* A=B
*
* @param B
* @return A
+ * @throws IOException
*/
- public Matrix set(Matrix B);
+ public Matrix set(Matrix B) throws IOException;
/**
* Sets the dimension of matrix
*
* @param rows the number of rows
* @param columns the number of columns
+ * @throws IOException
*/
- public void setDimension(int rows, int columns);
+ public void setDimension(int rows, int columns) throws IOException;
/**
* A(i, j) += value
@@ -107,16 +114,18 @@
* @param i
* @param j
* @param value
+ * @throws IOException
*/
- public void add(int i, int j, double value);
+ public void add(int i, int j, double value) throws IOException;
/**
* A = B + A
*
* @param B
* @return A
+ * @throws IOException
*/
- public Matrix add(Matrix B);
+ public Matrix add(Matrix B) throws IOException;
/**
* A = alpha*B + A
@@ -124,16 +133,18 @@
* @param alpha
* @param B
* @return A
+ * @throws IOException
*/
- public Matrix add(double alpha, Matrix B);
+ public Matrix add(double alpha, Matrix B) throws IOException;
/**
* C = A*B
*
* @param B
* @return C
+ * @throws IOException
*/
- public Matrix mult(Matrix B);
+ public Matrix mult(Matrix B) throws IOException;
/**
* C = alpha*A*B + C
@@ -142,16 +153,18 @@
* @param B
* @param C
* @return C
+ * @throws IOException
*/
- public Matrix multAdd(double alpha, Matrix B, Matrix C);
+ public Matrix multAdd(double alpha, Matrix B, Matrix C) throws IOException;
/**
* Computes the given norm of the matrix
*
* @param type
* @return norm of the matrix
+ * @throws IOException
*/
- public double norm(Norm type);
+ public double norm(Norm type) throws IOException;
/**
* Supported matrix-norms.
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=692985&r1=692984&r2=692985&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
(original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Sun Sep
7 19:28:42 2008
@@ -38,13 +38,13 @@
private static int SIZE = 5;
private static Matrix m1;
private static Matrix m2;
-
+
public static Test suite() {
TestSetup setup = new TestSetup(new TestSuite(TestDenseMatrix.class)) {
protected void setUp() throws Exception {
HCluster hCluster = new HCluster();
hCluster.setUp();
-
+
m1 = DenseMatrix.random(hCluster.conf, SIZE, SIZE);
m2 = DenseMatrix.random(hCluster.conf, SIZE, SIZE);
}
@@ -55,7 +55,7 @@
};
return setup;
}
-
+
/**
* Column vector test.
*
@@ -74,8 +74,10 @@
/**
* Test matrices addition
+ *
+ * @throws IOException
*/
- public void testMatrixAdd() {
+ public void testMatrixAdd() throws IOException {
Matrix result = m1.add(m2);
for (int i = 0; i < SIZE; i++) {
@@ -87,8 +89,10 @@
/**
* Test matrices multiplication
+ *
+ * @throws IOException
*/
- public void testMatrixMult() {
+ public void testMatrixMult() throws IOException {
Matrix result = m1.mult(m2);
verifyMultResult(SIZE, m1, m2, result);
@@ -101,8 +105,10 @@
* @param m1
* @param m2
* @param result
+ * @throws IOException
*/
- private void verifyMultResult(int size, Matrix m1, Matrix m2, Matrix result)
{
+ private void verifyMultResult(int size, Matrix m1, Matrix m2, Matrix result)
+ throws IOException {
double[][] C = new double[SIZE][SIZE];
for (int i = 0; i < SIZE; i++)