mirror of
https://github.com/apache/commons-math.git
synced 2025-02-08 02:59:36 +00:00
Eliminated unecessary copying of external operand's data array in arithmetic
operations. PR #31713 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2daf5fd17
commit
e67ec1e168
@ -43,7 +43,7 @@ import java.math.BigDecimal;
|
|||||||
* As specified in the {@link BigMatrix} interface, matrix element indexing
|
* As specified in the {@link BigMatrix} interface, matrix element indexing
|
||||||
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||||
* returns the element in the first row, first column of the matrix.</li></ul>
|
* returns the element in the first row, first column of the matrix.</li></ul>
|
||||||
* @version $Revision: 1.9 $ $Date: 2004/10/25 05:33:24 $
|
* @version $Revision: 1.10 $ $Date: 2004/11/07 20:19:22 $
|
||||||
*/
|
*/
|
||||||
public class BigMatrixImpl implements BigMatrix, Serializable {
|
public class BigMatrixImpl implements BigMatrix, Serializable {
|
||||||
|
|
||||||
@ -231,10 +231,9 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||||||
int rowCount = this.getRowDimension();
|
int rowCount = this.getRowDimension();
|
||||||
int columnCount = this.getColumnDimension();
|
int columnCount = this.getColumnDimension();
|
||||||
BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
|
BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
|
||||||
BigDecimal[][] mData = m.getData();
|
|
||||||
for (int row = 0; row < rowCount; row++) {
|
for (int row = 0; row < rowCount; row++) {
|
||||||
for (int col = 0; col < columnCount; col++) {
|
for (int col = 0; col < columnCount; col++) {
|
||||||
outData[row][col] = data[row][col].add(mData[row][col]);
|
outData[row][col] = data[row][col].add(m.getEntry(row, col));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new BigMatrixImpl(outData);
|
return new BigMatrixImpl(outData);
|
||||||
@ -255,10 +254,9 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||||||
int rowCount = this.getRowDimension();
|
int rowCount = this.getRowDimension();
|
||||||
int columnCount = this.getColumnDimension();
|
int columnCount = this.getColumnDimension();
|
||||||
BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
|
BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
|
||||||
BigDecimal[][] mData = m.getData();
|
|
||||||
for (int row = 0; row < rowCount; row++) {
|
for (int row = 0; row < rowCount; row++) {
|
||||||
for (int col = 0; col < columnCount; col++) {
|
for (int col = 0; col < columnCount; col++) {
|
||||||
outData[row][col] = data[row][col].subtract(mData[row][col]);
|
outData[row][col] = data[row][col].subtract(m.getEntry(row, col));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new BigMatrixImpl(outData);
|
return new BigMatrixImpl(outData);
|
||||||
@ -313,14 +311,13 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||||||
int nRows = this.getRowDimension();
|
int nRows = this.getRowDimension();
|
||||||
int nCols = m.getColumnDimension();
|
int nCols = m.getColumnDimension();
|
||||||
int nSum = this.getColumnDimension();
|
int nSum = this.getColumnDimension();
|
||||||
BigDecimal[][] mData = m.getData();
|
|
||||||
BigDecimal[][] outData = new BigDecimal[nRows][nCols];
|
BigDecimal[][] outData = new BigDecimal[nRows][nCols];
|
||||||
BigDecimal sum = ZERO;
|
BigDecimal sum = ZERO;
|
||||||
for (int row = 0; row < nRows; row++) {
|
for (int row = 0; row < nRows; row++) {
|
||||||
for (int col = 0; col < nCols; col++) {
|
for (int col = 0; col < nCols; col++) {
|
||||||
sum = ZERO;
|
sum = ZERO;
|
||||||
for (int i = 0; i < nSum; i++) {
|
for (int i = 0; i < nSum; i++) {
|
||||||
sum = sum.add(data[row][i].multiply(mData[i][col]));
|
sum = sum.add(data[row][i].multiply(m.getEntry(i, col)));
|
||||||
}
|
}
|
||||||
outData[row][col] = sum;
|
outData[row][col] = sum;
|
||||||
}
|
}
|
||||||
@ -915,14 +912,12 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||||||
int nRowB = b.getRowDimension();
|
int nRowB = b.getRowDimension();
|
||||||
|
|
||||||
// Apply permutations to b
|
// Apply permutations to b
|
||||||
BigDecimal[][] bv = b.getData();
|
|
||||||
BigDecimal[][] bp = new BigDecimal[nRowB][nColB];
|
BigDecimal[][] bp = new BigDecimal[nRowB][nColB];
|
||||||
for (int row = 0; row < nRowB; row++) {
|
for (int row = 0; row < nRowB; row++) {
|
||||||
for (int col = 0; col < nColB; col++) {
|
for (int col = 0; col < nColB; col++) {
|
||||||
bp[row][col] = bv[permutation[row]][col];
|
bp[row][col] = b.getEntry(permutation[row], col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bv = null;
|
|
||||||
|
|
||||||
// Solve LY = b
|
// Solve LY = b
|
||||||
for (int col = 0; col < nCol; col++) {
|
for (int col = 0; col < nCol; col++) {
|
||||||
|
@ -45,7 +45,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||||||
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||||
* returns the element in the first row, first column of the matrix.</li></ul>
|
* returns the element in the first row, first column of the matrix.</li></ul>
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.34 $ $Date: 2004/10/25 02:13:22 $
|
* @version $Revision: 1.35 $ $Date: 2004/11/07 20:19:22 $
|
||||||
*/
|
*/
|
||||||
public class RealMatrixImpl implements RealMatrix, Serializable {
|
public class RealMatrixImpl implements RealMatrix, Serializable {
|
||||||
|
|
||||||
@ -159,10 +159,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||||||
int rowCount = this.getRowDimension();
|
int rowCount = this.getRowDimension();
|
||||||
int columnCount = this.getColumnDimension();
|
int columnCount = this.getColumnDimension();
|
||||||
double[][] outData = new double[rowCount][columnCount];
|
double[][] outData = new double[rowCount][columnCount];
|
||||||
double[][] mData = m.getData();
|
|
||||||
for (int row = 0; row < rowCount; row++) {
|
for (int row = 0; row < rowCount; row++) {
|
||||||
for (int col = 0; col < columnCount; col++) {
|
for (int col = 0; col < columnCount; col++) {
|
||||||
outData[row][col] = data[row][col] + mData[row][col];
|
outData[row][col] = data[row][col] + m.getEntry(row, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RealMatrixImpl(outData);
|
return new RealMatrixImpl(outData);
|
||||||
@ -183,10 +182,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||||||
int rowCount = this.getRowDimension();
|
int rowCount = this.getRowDimension();
|
||||||
int columnCount = this.getColumnDimension();
|
int columnCount = this.getColumnDimension();
|
||||||
double[][] outData = new double[rowCount][columnCount];
|
double[][] outData = new double[rowCount][columnCount];
|
||||||
double[][] mData = m.getData();
|
|
||||||
for (int row = 0; row < rowCount; row++) {
|
for (int row = 0; row < rowCount; row++) {
|
||||||
for (int col = 0; col < columnCount; col++) {
|
for (int col = 0; col < columnCount; col++) {
|
||||||
outData[row][col] = data[row][col] - mData[row][col];
|
outData[row][col] = data[row][col] - m.getEntry(row, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RealMatrixImpl(outData);
|
return new RealMatrixImpl(outData);
|
||||||
@ -241,14 +239,13 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||||||
int nRows = this.getRowDimension();
|
int nRows = this.getRowDimension();
|
||||||
int nCols = m.getColumnDimension();
|
int nCols = m.getColumnDimension();
|
||||||
int nSum = this.getColumnDimension();
|
int nSum = this.getColumnDimension();
|
||||||
double[][] mData = m.getData();
|
|
||||||
double[][] outData = new double[nRows][nCols];
|
double[][] outData = new double[nRows][nCols];
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (int row = 0; row < nRows; row++) {
|
for (int row = 0; row < nRows; row++) {
|
||||||
for (int col = 0; col < nCols; col++) {
|
for (int col = 0; col < nCols; col++) {
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (int i = 0; i < nSum; i++) {
|
for (int i = 0; i < nSum; i++) {
|
||||||
sum += data[row][i] * mData[i][col];
|
sum += data[row][i] * m.getEntry(i, col);
|
||||||
}
|
}
|
||||||
outData[row][col] = sum;
|
outData[row][col] = sum;
|
||||||
}
|
}
|
||||||
@ -667,14 +664,12 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||||||
int nRowB = b.getRowDimension();
|
int nRowB = b.getRowDimension();
|
||||||
|
|
||||||
// Apply permutations to b
|
// Apply permutations to b
|
||||||
double[][] bv = b.getData();
|
|
||||||
double[][] bp = new double[nRowB][nColB];
|
double[][] bp = new double[nRowB][nColB];
|
||||||
for (int row = 0; row < nRowB; row++) {
|
for (int row = 0; row < nRowB; row++) {
|
||||||
for (int col = 0; col < nColB; col++) {
|
for (int col = 0; col < nColB; col++) {
|
||||||
bp[row][col] = bv[permutation[row]][col];
|
bp[row][col] = b.getEntry(permutation[row], col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bv = null;
|
|
||||||
|
|
||||||
// Solve LY = b
|
// Solve LY = b
|
||||||
for (int col = 0; col < nCol; col++) {
|
for (int col = 0; col < nCol; col++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user