Faster "multiply" method.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1178186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-10-02 13:00:41 +00:00
parent b8b4338994
commit a08f9179d3
2 changed files with 21 additions and 7 deletions

View File

@ -212,21 +212,31 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
final int nCols = m.getColumnDimension(); final int nCols = m.getColumnDimension();
final int nSum = this.getColumnDimension(); final int nSum = this.getColumnDimension();
final double[][] outData = new double[nRows][nCols]; final double[][] outData = new double[nRows][nCols];
for (int row = 0; row < nRows; row++) { // Will hold a column of "m".
final double[] dataRow = data[row]; final double[] mCol = new double[nSum];
final double[] outDataRow = outData[row]; final double[][] mData = m.data;
for (int col = 0; col < nCols; col++) {
// 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; double sum = 0;
for (int i = 0; i < nSum; i++) { 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); return new Array2DRowRealMatrix(outData, false);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */

View File

@ -52,6 +52,10 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces! If the output is not quite correct, check for invisible trailing spaces!
--> -->
<release version="3.0" date="TBD" description="TBD"> <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" > <action dev="luc" type="fix" issue="MATH-445" >
Replaced package.html with package-info.java for package documentation. Replaced package.html with package-info.java for package documentation.
</action> </action>