Author: tdunning
Date: Fri Sep 24 00:26:44 2010
New Revision: 1000670

URL: http://svn.apache.org/viewvc?rev=1000670&view=rev
Log:
Added simpler viewPart method to Matrix

Modified:
    mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/Matrix.java

Modified: 
mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java?rev=1000670&r1=1000669&r2=1000670&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java 
(original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java 
Fri Sep 24 00:26:44 2010
@@ -552,6 +552,10 @@ public abstract class AbstractMatrix imp
     return result;
   }
 
+  public Matrix viewPart(int rowOffset, int rowsRequested, int columnOffset, 
int columnsRequested) {
+    return viewPart(new int[]{rowOffset, columnOffset}, new 
int[]{rowsRequested, columnsRequested});
+  }
+
   public double zSum() {
     double result = 0;
     int[] c = size();

Modified: 
mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java?rev=1000670&r1=1000669&r2=1000670&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java 
(original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java Fri 
Sep 24 00:26:44 2010
@@ -88,21 +88,30 @@ public class DenseMatrix extends Abstrac
   }
   
   public Matrix viewPart(int[] offset, int[] size) {
-    if (offset[ROW] < 0) {
-      throw new IndexException(offset[ROW], rowSize());
+    int rowOffset = offset[ROW];
+    int rowsRequested = size[ROW];
+    int columnOffset = offset[COL];
+    int columnsRequested = size[COL];
+
+    return viewPart(rowOffset, rowsRequested, columnOffset, columnsRequested);
+  }
+
+  public Matrix viewPart(int rowOffset, int rowsRequested, int columnOffset, 
int columnsRequested) {
+    if (rowOffset < 0) {
+      throw new IndexException(rowOffset, rowSize());
+    }
+    if (rowOffset + rowsRequested > rowSize()) {
+      throw new IndexException(rowOffset + rowsRequested, rowSize());
+    }
+    if (columnOffset < 0) {
+      throw new IndexException(columnOffset, columnSize());
     }
-    if (offset[ROW] + size[ROW] > rowSize()) {
-      throw new IndexException(offset[ROW] + size[ROW], rowSize());
+    if (columnOffset + columnsRequested > columnSize()) {
+      throw new IndexException(columnOffset + columnsRequested, columnSize());
     }
-    if (offset[COL] < 0) {
-      throw new IndexException(offset[COL], columnSize());
-    }
-    if (offset[COL] + size[COL] > columnSize()) {
-      throw new IndexException(offset[COL] + size[COL], columnSize());
-    }
-    return new MatrixView(this, offset, size);
+    return new MatrixView(this, new int[]{rowOffset, columnOffset}, new 
int[]{rowsRequested, columnsRequested});
   }
-  
+
   @Override
   public Matrix assign(double value) {
     for (int row = 0; row < rowSize(); row++) {

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/Matrix.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/Matrix.java?rev=1000670&r1=1000669&r2=1000670&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/Matrix.java 
(original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/Matrix.java Fri Sep 
24 00:26:44 2010
@@ -290,13 +290,27 @@ public interface Matrix extends Cloneabl
    *
    * @param offset an int[2] offset into the receiver
    * @param size   the int[2] size of the desired result
-   * @return a new Matrix
+   * @return a new Matrix that is a view of the original
    * @throws CardinalityException if the length is greater than the 
cardinality of the receiver
    * @throws IndexException       if the offset is negative or the 
offset+length is outside of the receiver
    */
   Matrix viewPart(int[] offset, int[] size);
 
   /**
+   * Return a new matrix containing the subset of the recipient
+   *
+   * @param rowOffset           The first row of the view
+   * @param rowsRequested       The number of rows in the view
+   * @param columnOffset        The first column in the view
+   * @param columnsRequested    The number of columns in the view
+   * @return a new Matrix that is a view of the original
+   * @throws CardinalityException if the length is greater than the 
cardinality of the receiver
+   * @throws IndexException       if the offset is negative or the 
offset+length is outside of the
+   *                              receiver
+   */
+  Matrix viewPart(int rowOffset, int rowsRequested, int columnOffset, int 
columnsRequested);
+
+  /**
    * Return the sum of all the elements of the receiver
    *
    * @return a double


Reply via email to