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:02:26 UTC

svn commit: r1455106 - in /mahout/trunk/math/src: main/java/org/apache/mahout/math/MatrixVectorView.java test/java/org/apache/mahout/math/MatrixVectorViewTest.java

Author: ssc
Date: Mon Mar 11 12:02:26 2013
New Revision: 1455106

URL: http://svn.apache.org/r1455106
Log:
MAHOUT-1146 Cardinality exception bug in 'cross' method of AbstractVector class

Added:
    mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixVectorViewTest.java
Modified:
    mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixVectorView.java

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixVectorView.java?rev=1455106&r1=1455105&r2=1455106&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixVectorView.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixVectorView.java Mon Mar 11 12:02:26 2013
@@ -171,18 +171,9 @@ public class MatrixVectorView extends Ab
     return size();
   }
 
-  /**
-   * Subclasses must override to return an appropriately sparse or dense result
-   *
-   * @param rows    the row cardinality
-   * @param columns the column cardinality
-   * @return a Matrix
-   */
   @Override
   protected Matrix matrixLike(int rows, int columns) {
-    int[] offset = {row, column};
-    int[] size = {rowStride == 0 ? 1 : rowStride, columnStride == 0 ? 1 : columnStride};
-    return matrix.viewPart(offset, size);
+    return matrix.like(rows, columns);
   }
 
   @Override

Added: mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixVectorViewTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixVectorViewTest.java?rev=1455106&view=auto
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixVectorViewTest.java (added)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixVectorViewTest.java Mon Mar 11 12:02:26 2013
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.math;
+
+import org.junit.Test;
+
+public class MatrixVectorViewTest extends MahoutTestCase {
+
+  /**
+   * Test for the error reported in https://issues.apache.org/jira/browse/MAHOUT-1146
+   */
+  @Test
+  public void testColumnView() {
+
+    Matrix matrix = new DenseMatrix(5, 3);
+    Vector column2 = matrix.viewColumn(2);
+    Matrix outerProduct = column2.cross(column2);
+
+    assertEquals(matrix.numRows(), outerProduct.numRows());
+    assertEquals(matrix.numRows(), outerProduct.numCols());
+  }
+}