Yes, your right, We should rather use just getEntry(x,y) and getRowDimension/getColumnDimension shouldn't we.Yes, below looks good and definitely an improvement over the current code. If there are cases where access to the full matrix of the external operand is really necessary / much better than just using getEntry, we can insert an instanceOf test and cast to a RealMatrixImpl to get the reference. I haven't looked carefully at all the code to see if these cases exist, though.
Phil
Agreed, I'll change it in my work so the interface is unnecessary, it will look more like this:
Index: RealMatrixImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java,v
retrieving revision 1.32 diff -u -r1.32 RealMatrixImpl.java --- RealMatrixImpl.java 10 Oct 2004 18:00:33 -0000 1.32 +++ RealMatrixImpl.java 11 Oct 2004 23:51:52 -0000 @@ -160,10 +160,9 @@ int rowCount = this.getRowDimension(); int columnCount = this.getColumnDimension(); double[][] outData = new double[rowCount][columnCount]; - double[][] mData = m.getData(); for (int row = 0; row < rowCount; row++) { 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); @@ -184,10 +183,9 @@ int rowCount = this.getRowDimension(); int columnCount = this.getColumnDimension(); double[][] outData = new double[rowCount][columnCount]; - double[][] mData = m.getData(); for (int row = 0; row < rowCount; row++) { 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); @@ -242,14 +240,13 @@ int nRows = this.getRowDimension(); int nCols = m.getColumnDimension(); int nSum = this.getColumnDimension(); - double[][] mData = m.getData(); double[][] outData = new double[nRows][nCols]; double sum = 0; for (int row = 0; row < nRows; row++) { for (int col = 0; col < nCols; col++) { sum = 0; 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; } @@ -715,16 +712,14 @@ int nColB = b.getColumnDimension(); int nRowB = b.getRowDimension();
- // Apply permutations to b - double[][] bv = b.getData(); + // Apply permutations to b\ double[][] bp = new double[nRowB][nColB]; for (int row = 0; row < nRowB; row++) { 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 for (int col = 0; col < nCol; col++) { for (int i = col + 1; i < nCol; i++) {
-Mark
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
