You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/10/02 15:00:42 UTC

svn commit: r1178186 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java site/xdoc/changes.xml

Author: erans
Date: Sun Oct  2 13:00:41 2011
New Revision: 1178186

URL: http://svn.apache.org/viewvc?rev=1178186&view=rev
Log:
MATH-676
Faster "multiply" method.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java?rev=1178186&r1=1178185&r2=1178186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java Sun Oct  2 13:00:41 2011
@@ -212,21 +212,31 @@ public class Array2DRowRealMatrix extend
         final int nRows = this.getRowDimension();
         final int nCols = m.getColumnDimension();
         final int nSum = this.getColumnDimension();
+
         final double[][] outData = new double[nRows][nCols];
-        for (int row = 0; row < nRows; row++) {
-            final double[] dataRow    = data[row];
-            final double[] outDataRow = outData[row];
-            for (int col = 0; col < nCols; col++) {
+        // Will hold a column of "m".
+        final double[] mCol = new double[nSum];
+        final double[][] mData = m.data;
+
+        // Multiply.
+        for (int col = 0; col < nCols; col++) {
+            // Copy all elements of column "col" of "m" so that
+            // will be in contiguous memory.
+            for (int mRow = 0; mRow < nSum; mRow++) {
+                mCol[mRow] = mData[mRow][col];
+            }
+
+            for (int row = 0; row < nRows; row++) {
+                final double[] dataRow = data[row];
                 double sum = 0;
                 for (int i = 0; i < nSum; i++) {
-                    sum += dataRow[i] * m.data[i][col];
+                    sum += dataRow[i] * mCol[i];
                 }
-                outDataRow[col] = sum;
+                outData[row][col] = sum;
             }
         }
 
         return new Array2DRowRealMatrix(outData, false);
-
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1178186&r1=1178185&r2=1178186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Oct  2 13:00:41 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-676">
+         Faster "multiply" method in "Array2DRowRealMatrix". Code inspired
+         from the Jama project.
+      </action>
       <action dev="luc" type="fix" issue="MATH-445" >
         Replaced package.html with package-info.java for package documentation.
       </action>