Skip to content

Commit

Permalink
MAHOUT-1046 - views of MatrixView broken.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/mahout/trunk@1361581 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tdunning committed Jul 14, 2012
1 parent 68e3518 commit 2be3df7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions math/src/main/java/org/apache/mahout/math/MatrixView.java
Expand Up @@ -93,19 +93,19 @@ public int[] getNumNondefaultElements() {

@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);
Expand Down
9 changes: 9 additions & 0 deletions math/src/test/java/org/apache/mahout/math/MatrixTest.java
Expand Up @@ -184,6 +184,15 @@ public void testAssignDoubleArrayArrayCardinality() {
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);
Expand Down

0 comments on commit 2be3df7

Please sign in to comment.