You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ss...@apache.org on 2013/03/11 13:18:12 UTC

svn commit: r1455111 - in /mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop: DistributedRowMatrix.java MatrixMultiplicationJob.java

Author: ssc
Date: Mon Mar 11 12:18:11 2013
New Revision: 1455111

URL: http://svn.apache.org/r1455111
Log:
MAHOUT-1076 Matrix Multiplication output to user specified directory

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java?rev=1455111&r1=1455110&r2=1455111&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java Mon Mar 11 12:18:11 2013
@@ -171,16 +171,26 @@ public class DistributedRowMatrix implem
     return numCols;
   }
 
+
   /**
    * This implements matrix this.transpose().times(other)
    * @param other   a DistributedRowMatrix
    * @return    a DistributedRowMatrix containing the product
    */
   public DistributedRowMatrix times(DistributedRowMatrix other) throws IOException {
+    return times(other, new Path(outputTmpBasePath.getParent(), "productWith-" + (System.nanoTime() & 0xFF)));
+  }
+
+  /**
+   * This implements matrix this.transpose().times(other)
+   * @param other   a DistributedRowMatrix
+   * @param outPath path to write result to
+   * @return    a DistributedRowMatrix containing the product
+   */
+  public DistributedRowMatrix times(DistributedRowMatrix other, Path outPath) throws IOException {
     if (numRows != other.numRows()) {
       throw new CardinalityException(numRows, other.numRows());
     }
-    Path outPath = new Path(outputTmpBasePath.getParent(), "productWith-" + (System.nanoTime() & 0xFF));
 
     Configuration initialConf = getConf() == null ? new Configuration() : getConf();
     Configuration conf =

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java?rev=1455111&r1=1455110&r2=1455111&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java Mon Mar 11 12:18:11 2013
@@ -91,6 +91,8 @@ public class MatrixMultiplicationJob ext
     addOption("inputPathA", "ia", "Path to the first input matrix", true);
     addOption("inputPathB", "ib", "Path to the second input matrix", true);
 
+    addOption("outputPath", "op", "Path to the output matrix", false);
+
     Map<String, List<String>> argMap = parseArguments(strings);
     if (argMap == null) {
       return -1;
@@ -108,8 +110,12 @@ public class MatrixMultiplicationJob ext
     a.setConf(new Configuration(getConf()));
     b.setConf(new Configuration(getConf()));
 
-    //DistributedRowMatrix c = a.times(b);
-    a.times(b);
+    if (hasOption("outputPath")) {
+      a.times(b, new Path(getOption("outputPath")));
+    } else {
+      a.times(b);
+    }
+
     return 0;
   }