You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2009/09/10 05:08:59 UTC

svn commit: r813201 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/DenseMatrix.java src/test/org/apache/hama/TestMatrixVectorMult.java

Author: edwardyoon
Date: Thu Sep 10 03:08:59 2009
New Revision: 813201

URL: http://svn.apache.org/viewvc?rev=813201&view=rev
Log:
mat-vector multiplication bug fixed 

Added:
    incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java
Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=813201&r1=813200&r2=813201&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Thu Sep 10 03:08:59 2009
@@ -115,6 +115,7 @@
 
   BUG FIXES
 
+    HAMA-190: Bug in Matrix-Vector multiplication (edwardyoon)
     HAMA-183: When we construct the matrix, 
                 dimensions should be defined. (edwardyoon)
     HAMA-172: Vector.add(Vector v) throw the Index out of bounds 

Modified: incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java?rev=813201&r1=813200&r2=813201&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Thu Sep 10 03:08:59 2009
@@ -499,8 +499,13 @@
    */
   public DenseMatrix mult(Matrix B) throws IOException {
     ensureForMultiplication(B);
-    DenseMatrix result = new DenseMatrix(config, this.getRows(), this
-        .getColumns());
+    int columns = 0;
+    if(B.getColumns() == 1 || this.getColumns() == 1)
+      columns = 1;
+    else
+      columns = this.getColumns();
+    
+    DenseMatrix result = new DenseMatrix(config, this.getRows(), columns);
 
     for (int i = 0; i < this.getRows(); i++) {
       JobConf jobConf = new JobConf(config);

Added: incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java?rev=813201&view=auto
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java (added)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java Thu Sep 10 03:08:59 2009
@@ -0,0 +1,84 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.hama;
+
+import java.io.IOException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Logger;
+
+public class TestMatrixVectorMult extends TestCase {
+  static final Logger LOG = Logger.getLogger(TestMatrixVectorMult.class);
+  private static Matrix m1;
+  private static Matrix m2;
+  private static HamaConfiguration conf;
+  private static double[][] result = { { 5 }, { 11 } };
+
+  public static Test suite() {
+    TestSetup setup = new TestSetup(new TestSuite(TestMatrixVectorMult.class)) {
+      protected void setUp() throws Exception {
+        HCluster hCluster = new HCluster();
+        hCluster.setUp();
+
+        conf = hCluster.getConf();
+
+        m1 = new DenseMatrix(conf, "A", true);
+        m1.setDimension(2, 2);
+        m1.set(0, 0, 1);
+        m1.set(0, 1, 2);
+        m1.set(1, 0, 3);
+        m1.set(1, 1, 4);
+        m2 = new DenseMatrix(conf, "B", true);
+        m2.setDimension(2, 1);
+        m2.set(0, 0, 1);
+        m2.set(1, 0, 2);
+      }
+
+      protected void tearDown() {
+        try {
+          closeTest();
+        } catch (IOException e) {
+          e.printStackTrace();
+        }
+      }
+    };
+    return setup;
+  }
+
+  public static void closeTest() throws IOException {
+    m1.close();
+    m2.close();
+  }
+
+  public void testMatVectorMult() throws IOException {
+    DenseMatrix c = (DenseMatrix) m1.mult(m2);
+    assertTrue(m1.getRows() == 2);
+
+    for (int i = 0; i < c.getRows(); i++) {
+      for (int j = 0; j < c.getColumns(); j++) {
+        assertEquals(result[i][j], c.get(i, j));
+      }
+    }
+  }
+}



Re: svn commit: r813201 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/DenseMatrix.java src/test/org/apache/hama/TestMatrixVectorMult.java

Posted by "Edward J. Yoon" <ed...@apache.org>.
Oh. Thank you very much.

On Thu, Sep 10, 2009 at 12:46 PM, Brett Porter <br...@apache.org> wrote:
>
> On 10/09/2009, at 1:08 PM, edwardyoon@apache.org wrote:
>
>> Added:
>> incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java?rev=813201&view=auto
>>
>> ==============================================================================
>> ---
>> incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java
>> (added)
>> +++
>> incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java Thu
>> Sep 10 03:08:59 2009
>> @@ -0,0 +1,84 @@
>> +/**
>> + * Copyright 2007 The Apache Software Foundation
>> + *
>> + * 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.
>
> Note that the copyright statement is no longer required in the header.
>
> http://www.apache.org/legal/src-headers.html#headers
>
> Thanks,
> Brett
>
>



-- 
Best Regards, Edward J. Yoon @ NHN, corp.
edwardyoon@apache.org
http://blog.udanax.org

Re: svn commit: r813201 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/DenseMatrix.java src/test/org/apache/hama/TestMatrixVectorMult.java

Posted by Brett Porter <br...@apache.org>.
On 10/09/2009, at 1:08 PM, edwardyoon@apache.org wrote:

> Added: incubator/hama/trunk/src/test/org/apache/hama/ 
> TestMatrixVectorMult.java
> URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestMatrixVectorMult.java?rev=813201&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- incubator/hama/trunk/src/test/org/apache/hama/ 
> TestMatrixVectorMult.java (added)
> +++ incubator/hama/trunk/src/test/org/apache/hama/ 
> TestMatrixVectorMult.java Thu Sep 10 03:08:59 2009
> @@ -0,0 +1,84 @@
> +/**
> + * Copyright 2007 The Apache Software Foundation
> + *
> + * 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.

Note that the copyright statement is no longer required in the header.

http://www.apache.org/legal/src-headers.html#headers

Thanks,
Brett