You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/12/21 20:02:45 UTC
svn commit: r728478 -
/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java
Author: luc
Date: Sun Dec 21 11:02:44 2008
New Revision: 728478
URL: http://svn.apache.org/viewvc?rev=728478&view=rev
Log:
partially unrolled some computation loops to increase performance
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java?rev=728478&r1=728477&r2=728478&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java Sun Dec 21 11:02:44 2008
@@ -41,10 +41,10 @@
public class DenseRealMatrix extends AbstractRealMatrix implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = 5536250491728216579L;
+ private static final long serialVersionUID = 4991895511313664478L;
/** Block size. */
- private static final int BLOCK_SIZE = 32;
+ private static final int BLOCK_SIZE = 52;
/** Blocks of matrix entries. */
private final double blocks[][];
@@ -396,7 +396,7 @@
* @throws IllegalArgumentException
* if columnDimension(this) != rowDimension(m)
*/
- DenseRealMatrix multiply(DenseRealMatrix m) throws IllegalArgumentException {
+ public DenseRealMatrix multiply(DenseRealMatrix m) throws IllegalArgumentException {
// safety check
checkMultiplicationCompatible(m);
@@ -412,6 +412,9 @@
for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) {
final int jWidth = out.blockWidth(jBlock);
+ final int jWidth2 = jWidth + jWidth;
+ final int jWidth3 = jWidth2 + jWidth;
+ final int jWidth4 = jWidth3 + jWidth;
// select current block
final double[] outBlock = out.blocks[blockIndex];
@@ -426,8 +429,19 @@
final int lEnd = lStart + kWidth;
for (int nStart = 0; nStart < jWidth; ++nStart) {
double sum = 0;
- for (int l = lStart, n = nStart; l < lEnd; ++l, n += jWidth) {
- sum += tBlock[l] * mBlock[n];
+ int l = lStart;
+ int n = nStart;
+ while (l < lEnd - 3) {
+ sum += tBlock[l] * mBlock[n] +
+ tBlock[l + 1] * mBlock[n + jWidth] +
+ tBlock[l + 2] * mBlock[n + jWidth2] +
+ tBlock[l + 3] * mBlock[n + jWidth3];
+ l += 4;
+ n += jWidth4;
+ }
+ while (l < lEnd) {
+ sum += tBlock[l++] * mBlock[n];
+ n += jWidth;
}
outBlock[k++] += sum;
}
@@ -772,8 +786,17 @@
final int qEnd = Math.min(qStart + BLOCK_SIZE, columns);
for (int p = pStart, k = 0; p < pEnd; ++p) {
double sum = 0;
- for (int q = qStart; q < qEnd; ++q) {
- sum += block[k++] * v[q];
+ int q = qStart;
+ while (q < qEnd - 3) {
+ sum += block[k] * v[q] +
+ block[k + 1] * v[q + 1] +
+ block[k + 2] * v[q + 2] +
+ block[k + 3] * v[q + 3];
+ ++k;
+ ++q;
+ }
+ while (q < qEnd) {
+ sum += block[k++] * v[q++];
}
out[p] += sum;
}