Author: psteitz
Date: Fri Oct 14 21:29:05 2011
New Revision: 1183507
URL: http://svn.apache.org/viewvc?rev=1183507&view=rev
Log:
Replaced temporary matrices / entry mutators with double[][] arrays to speed
computation in loops. JIRA: MATH-612. Reported and patched by Christopher Nix.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/TriDiagonalTransformer.java?rev=1183507&r1=1183506&r2=1183507&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
Fri Oct 14 21:29:05 2011
@@ -97,33 +97,34 @@ class TriDiagonalTransformer {
public RealMatrix getQT() {
if (cachedQt == null) {
final int m = householderVectors.length;
- cachedQt = MatrixUtils.createRealMatrix(m, m);
-
+ double[][] qta = new double[m][m];
+
// build up first part of the matrix by applying Householder
transforms
for (int k = m - 1; k >= 1; --k) {
final double[] hK = householderVectors[k - 1];
final double inv = 1.0 / (secondary[k - 1] * hK[k]);
- cachedQt.setEntry(k, k, 1);
+ qta[k][k] = 1;
if (hK[k] != 0.0) {
double beta = 1.0 / secondary[k - 1];
- cachedQt.setEntry(k, k, 1 + beta * hK[k]);
+ qta[k][k] = 1 + beta * hK[k];
for (int i = k + 1; i < m; ++i) {
- cachedQt.setEntry(k, i, beta * hK[i]);
+ qta[k][i] = beta * hK[i];
}
for (int j = k + 1; j < m; ++j) {
beta = 0;
for (int i = k + 1; i < m; ++i) {
- beta += cachedQt.getEntry(j, i) * hK[i];
+ beta += qta[j][i] * hK[i];
}
beta *= inv;
- cachedQt.setEntry(j, k, beta * hK[k]);
+ qta[j][k] = beta * hK[k];
for (int i = k + 1; i < m; ++i) {
- cachedQt.addToEntry(j, i, beta * hK[i]);
+ qta[j][i] += beta * hK[i];
}
}
}
}
- cachedQt.setEntry(0, 0, 1);
+ qta[0][0] = 1;
+ cachedQt = MatrixUtils.createRealMatrix(qta);
}
// return the cached matrix
@@ -137,17 +138,17 @@ class TriDiagonalTransformer {
public RealMatrix getT() {
if (cachedT == null) {
final int m = main.length;
- cachedT = MatrixUtils.createRealMatrix(m, m);
+ double[][] ta = new double[m][m];
for (int i = 0; i < m; ++i) {
- cachedT.setEntry(i, i, main[i]);
+ ta[i][i] = main[i];
if (i > 0) {
- cachedT.setEntry(i, i - 1, secondary[i - 1]);
+ ta[i][i - 1] = secondary[i - 1];
}
if (i < main.length - 1) {
- cachedT.setEntry(i, i + 1, secondary[i]);
+ ta[i][i + 1] = secondary[i];
}
}
-
+ cachedT = MatrixUtils.createRealMatrix(ta);
}
// return the cached matrix
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=1183507&r1=1183506&r2=1183507&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Oct 14 21:29:05 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="psteitz" type="update" issue="MATH-612" due-to="Christopher
Nix">
+ Replaced temporary matrices and entry mutators with double[][] arrays
to speed computation
+ in loops within QRDecomposition, Bi- and TriDiagonalTransformer
implementations.
+ </action>
<action dev="luc" type="fix" issue="MATH-679" due-to="Christopher
Berner">
Fixed an integer overflow in OpenMapRealMatrix.
</action>