Author: edwardyoon
Date: Mon Oct 13 03:00:46 2008
New Revision: 703995
URL: http://svn.apache.org/viewvc?rev=703995&view=rev
Log:
Add identity(int m, int n) which returns an m-by-n matrix with ones on the
diagonal and zeros elsewhere.
Modified:
incubator/hama/trunk/CHANGES.txt
incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
Modified: incubator/hama/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=703995&r1=703994&r2=703995&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Mon Oct 13 03:00:46 2008
@@ -4,6 +4,7 @@
NEW FEATURES
+ Hama-80: Add identity(int m, int n) which returns identity matrix
(edwardyoon)
HAMA-62: Hama Shell Implementation (samuel via edwardyoon)
HAMA-61: Load / save matrices from HTable (edwardyoon)
HAMA-51: Add get/setRowAttribute() method (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=703995&r1=703994&r2=703995&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Mon Oct 13
03:00:46 2008
@@ -64,8 +64,8 @@
public DenseMatrix(HamaConfiguration conf, String matrixName) {
try {
setConfiguration(conf);
- this.matrixName = matrixName;
- if(store.matrixExists(matrixName)) {
+ this.matrixName = matrixName;
+ if (store.matrixExists(matrixName)) {
this.matrixPath = store.getPath(matrixName);
} else {
this.matrixPath = matrixName;
@@ -138,6 +138,33 @@
return rand;
}
+ /**
+ * Generate identity matrix
+ *
+ * @param conf configuration object
+ * @param m the number of rows.
+ * @param n the number of columns.
+ * @return an m-by-n matrix with ones on the diagonal and zeros elsewhere.
+ * @throws IOException
+ */
+ public static Matrix identity(HamaConfiguration conf, int m, int n)
+ throws IOException {
+ String name = RandomVariable.randMatrixName();
+ Matrix identity = new DenseMatrix(conf, name);
+
+ for (int i = 0; i < m; i++) {
+ DenseVector vector = new DenseVector();
+ for (int j = 0; j < n; j++) {
+ vector.set(j, (i == j ? 1.0 : 0.0));
+ }
+ identity.setRow(i, vector);
+ }
+
+ identity.setDimension(m, n);
+ LOG.info("Create the " + m + " * " + n + " identity matrix : " + name);
+ return identity;
+ }
+
public Matrix add(Matrix B) throws IOException {
String output = RandomVariable.randMatrixName();
Matrix result = new DenseMatrix(config, output);