mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdunn...@apache.org
Subject svn commit: r1361581 - in /mahout/trunk/math/src: main/java/org/apache/mahout/math/MatrixView.java test/java/org/apache/mahout/math/MatrixTest.java
Date Sat, 14 Jul 2012 20:09:35 GMT
Author: tdunning
Date: Sat Jul 14 20:09:35 2012
New Revision: 1361581

URL: http://svn.apache.org/viewvc?rev=1361581&view=rev
Log:
MAHOUT-1046 - views of MatrixView broken.

Modified:
    mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java?rev=1361581&r1=1361580&r2=1361581&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java Sat Jul 14 20:09:35
2012
@@ -93,19 +93,19 @@ public class MatrixView extends Abstract
 
   @Override
   public Matrix viewPart(int[] offset, int[] size) {
-    if (offset[ROW] < ROW) {
-      throw new IndexException(offset[ROW], ROW);
+    if (offset[ROW] < 0) {
+      throw new IndexException(offset[ROW], 0);
     }
     if (offset[ROW] + size[ROW] > rowSize()) {
       throw new IndexException(offset[ROW] + size[ROW], rowSize());
     }
-    if (offset[COL] < ROW) {
-      throw new IndexException(offset[COL], ROW);
+    if (offset[COL] < 0) {
+      throw new IndexException(offset[COL], 0);
     }
     if (offset[COL] + size[COL] > columnSize()) {
       throw new IndexException(offset[COL] + size[COL], columnSize());
     }
-    int[] origin = offset.clone();
+    int[] origin = this.offset.clone();
     origin[ROW] += offset[ROW];
     origin[COL] += offset[COL];
     return new MatrixView(matrix, origin, size);

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java?rev=1361581&r1=1361580&r2=1361581&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java Sat Jul 14 20:09:35
2012
@@ -184,6 +184,15 @@ public abstract class MatrixTest extends
     test.assign(new double[test.rowSize() + 1][test.columnSize()]);
   }
 
+  /** Tests MAHOUT-1046 */
+  @Test
+  public void testMatrixViewBug() {
+    Matrix m = test.viewPart(0, 3, 0, 2);
+    // old bug would blow cookies with an index exception here.
+    m = m.viewPart(2, 1, 0, 1);
+    assertEquals(5.5, m.zSum(), 0);
+  }
+
   @Test
   public void testAssignMatrixBinaryFunction() {
     test.assign(test, Functions.PLUS);



Mime
View raw message