Changed matrix indexing to be 0-based.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141442 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b1b111d8bd
commit
1f0fde531a
|
@ -21,8 +21,11 @@ import java.math.BigDecimal;
|
|||
/**
|
||||
* Interface defining a real-valued matrix with basic algebraic operations, using
|
||||
* BigDecimal representations for the entries.
|
||||
* <p>
|
||||
* Matrix element indexing is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||
* returns the element in the first row, first column of the matrix.
|
||||
*
|
||||
* @version $Revision: 1.6 $ $Date: 2004/09/01 21:26:11 $
|
||||
* @version $Revision: 1.7 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
public interface BigMatrix {
|
||||
|
||||
|
@ -151,8 +154,8 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Returns the entries in row number <code>row</code> as an array.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
|
@ -164,8 +167,8 @@ public interface BigMatrix {
|
|||
* Returns the entries in row number <code>row</code> as an array
|
||||
* of double values.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
|
@ -176,8 +179,8 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Returns the entries in column number <code>col</code> as an array.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
|
@ -189,8 +192,8 @@ public interface BigMatrix {
|
|||
* Returns the entries in column number <code>col</code> as an array
|
||||
* of double values.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
|
@ -201,10 +204,10 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Returns the entry in the specified row and column.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -218,10 +221,10 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Returns the entry in the specified row and column as a double.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -235,10 +238,10 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -254,10 +257,10 @@ public interface BigMatrix {
|
|||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -274,10 +277,10 @@ public interface BigMatrix {
|
|||
* Sets the entry in the specified row and column to the
|
||||
* <code>BigDecimal</code> value represented by the input string.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
|
|
@ -30,16 +30,20 @@ import java.math.BigDecimal;
|
|||
* <li>getDeterminant</li>
|
||||
* <li>inverse</li> </ul>
|
||||
* <p>
|
||||
* <strong>Usage note</strong>:<br>
|
||||
* <strong>Usage notes</strong>:<br>
|
||||
* <ul><li>
|
||||
* The LU decomposition is stored and reused on subsequent calls. If matrix
|
||||
* data are modified using any of the public setXxx methods, the saved
|
||||
* data are modified using any of the public setXxx methods, the saved
|
||||
* decomposition is discarded. If data are modified via references to the
|
||||
* underlying array obtained using <code>getDataRef()</code>, then the stored
|
||||
* LU decomposition will not be discarded. In this case, you need to
|
||||
* LU decomposition will not be discarded. In this case, you need to
|
||||
* explicitly invoke <code>LUDecompose()</code> to recompute the decomposition
|
||||
* before using any of the methods above.
|
||||
*
|
||||
* @version $Revision: 1.5 $ $Date: 2004/09/01 21:26:11 $
|
||||
* before using any of the methods above.</li>
|
||||
* <li>
|
||||
* As specified in the {@link BigMatrix} interface, matrix element indexing
|
||||
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||
* returns the element in the first row, first column of the matrix.</li></ul>
|
||||
* @version $Revision: 1.6 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
public class BigMatrixImpl implements BigMatrix, Serializable {
|
||||
|
||||
|
@ -428,20 +432,20 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
/**
|
||||
* Returns the entries in row number <code>row</code> as an array.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
* @throws MatrixIndexException if the specified row index is not valid
|
||||
*/
|
||||
public BigDecimal[] getRow(int row) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate( row, 1 ) ) {
|
||||
if ( !isValidCoordinate( row, 0 ) ) {
|
||||
throw new MatrixIndexException("illegal row argument");
|
||||
}
|
||||
int ncols = this.getColumnDimension();
|
||||
BigDecimal[] out = new BigDecimal[ncols];
|
||||
System.arraycopy(data[row - 1], 0, out, 0, ncols);
|
||||
System.arraycopy(data[row], 0, out, 0, ncols);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -449,21 +453,21 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
* Returns the entries in row number <code>row</code> as an array
|
||||
* of double values.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
* @throws MatrixIndexException if the specified row index is not valid
|
||||
*/
|
||||
public double[] getRowAsDoubleArray(int row) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate( row, 1 ) ) {
|
||||
if ( !isValidCoordinate( row, 0 ) ) {
|
||||
throw new MatrixIndexException("illegal row argument");
|
||||
}
|
||||
int ncols = this.getColumnDimension();
|
||||
double[] out = new double[ncols];
|
||||
for (int i=0;i<ncols;i++) {
|
||||
out[i] = data[row-1][i].doubleValue();
|
||||
out[i] = data[row][i].doubleValue();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -471,21 +475,21 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
/**
|
||||
* Returns the entries in column number <code>col</code> as an array.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
* @throws MatrixIndexException if the specified column index is not valid
|
||||
*/
|
||||
public BigDecimal[] getColumn(int col) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate(1, col) ) {
|
||||
if ( !isValidCoordinate(0, col) ) {
|
||||
throw new MatrixIndexException("illegal column argument");
|
||||
}
|
||||
int nRows = this.getRowDimension();
|
||||
BigDecimal[] out = new BigDecimal[nRows];
|
||||
for (int i = 0; i < nRows; i++) {
|
||||
out[i] = data[i][col - 1];
|
||||
out[i] = data[i][col];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -494,21 +498,21 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
* Returns the entries in column number <code>col</code> as an array
|
||||
* of double values.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
* @throws MatrixIndexException if the specified column index is not valid
|
||||
*/
|
||||
public double[] getColumnAsDoubleArray(int col) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate( 1, col ) ) {
|
||||
if ( !isValidCoordinate( 0, col ) ) {
|
||||
throw new MatrixIndexException("illegal column argument");
|
||||
}
|
||||
int nrows = this.getRowDimension();
|
||||
double[] out = new double[nrows];
|
||||
for (int i=0;i<nrows;i++) {
|
||||
out[i] = data[i][col-1].doubleValue();
|
||||
out[i] = data[i][col].doubleValue();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -516,10 +520,10 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
/**
|
||||
* Returns the entry in the specified row and column.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -533,16 +537,16 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
if (!isValidCoordinate(row,column)) {
|
||||
throw new MatrixIndexException("matrix entry does not exist");
|
||||
}
|
||||
return data[row - 1][column - 1];
|
||||
return data[row][column];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry in the specified row and column as a double.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -559,10 +563,10 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -576,17 +580,17 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
if (!isValidCoordinate(row,column)) {
|
||||
throw new MatrixIndexException("matrix entry does not exist");
|
||||
}
|
||||
data[row - 1][column - 1] = value;
|
||||
data[row][column] = value;
|
||||
lu = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -603,10 +607,10 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
* Sets the entry in the specified row and column to the
|
||||
* <code>BigDecimal</code> value represented by the input string.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -1166,7 +1170,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
|
|||
int nRows = this.getRowDimension();
|
||||
int nCols = this.getColumnDimension();
|
||||
|
||||
return !(row < 1 || row > nRows || col < 1 || col > nCols);
|
||||
return !(row < 0 || row >= nRows || col < 0 || col >= nCols);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,12 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
/**
|
||||
* Interface defining a real-valued matrix with basic algebraic operations
|
||||
* @version $Revision: 1.21 $ $Date: 2004/09/01 21:26:11 $
|
||||
* Interface defining a real-valued matrix with basic algebraic operations.
|
||||
* <p>
|
||||
* Matrix element indexing is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||
* returns the element in the first row, first column of the matrix.
|
||||
*
|
||||
* @version $Revision: 1.22 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
public interface RealMatrix {
|
||||
|
||||
|
@ -108,8 +112,8 @@ public interface RealMatrix {
|
|||
/**
|
||||
* Returns the entries in row number <code>row</code> as an array.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
|
@ -120,8 +124,8 @@ public interface RealMatrix {
|
|||
/**
|
||||
* Returns the entries in column number <code>col</code> as an array.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
|
@ -132,10 +136,10 @@ public interface RealMatrix {
|
|||
/**
|
||||
* Returns the entry in the specified row and column.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -149,10 +153,10 @@ public interface RealMatrix {
|
|||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
|
|
@ -29,16 +29,21 @@ import java.io.Serializable;
|
|||
* <li>getDeterminant</li>
|
||||
* <li>inverse</li> </ul>
|
||||
* <p>
|
||||
* <strong>Usage note</strong>:<br>
|
||||
* <strong>Usage notes</strong>:<br>
|
||||
* <ul><li>
|
||||
* The LU decomposition is stored and reused on subsequent calls. If matrix
|
||||
* data are modified using any of the public setXxx methods, the saved
|
||||
* decomposition is discarded. If data are modified via references to the
|
||||
* underlying array obtained using <code>getDataRef()</code>, then the stored
|
||||
* LU decomposition will not be discarded. In this case, you need to
|
||||
* explicitly invoke <code>LUDecompose()</code> to recompute the decomposition
|
||||
* before using any of the methods above.
|
||||
* before using any of the methods above.</li>
|
||||
* <li>
|
||||
* As specified in the {@link RealMatrix} interface, matrix element indexing
|
||||
* is 0-based -- e.g., <code>getEntry(0, 0)</code>
|
||||
* returns the element in the first row, first column of the matrix.</li></ul>
|
||||
*
|
||||
* @version $Revision: 1.27 $ $Date: 2004/09/01 21:26:11 $
|
||||
* @version $Revision: 1.28 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
public class RealMatrixImpl implements RealMatrix, Serializable {
|
||||
|
||||
|
@ -306,41 +311,41 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||
/**
|
||||
* Returns the entries in row number <code>row</code> as an array.
|
||||
* <p>
|
||||
* Row indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < row <= rowDimension.</code>
|
||||
* Row indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= row < rowDimension.</code>
|
||||
*
|
||||
* @param row the row to be fetched
|
||||
* @return array of entries in the row
|
||||
* @throws MatrixIndexException if the specified row index is not valid
|
||||
*/
|
||||
public double[] getRow(int row) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate( row, 1 ) ) {
|
||||
if ( !isValidCoordinate( row, 0 ) ) {
|
||||
throw new MatrixIndexException("illegal row argument");
|
||||
}
|
||||
int ncols = this.getColumnDimension();
|
||||
double[] out = new double[ncols];
|
||||
System.arraycopy(data[row - 1], 0, out, 0, ncols);
|
||||
System.arraycopy(data[row], 0, out, 0, ncols);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entries in column number <code>col</code> as an array.
|
||||
* <p>
|
||||
* Column indices start at 1. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 < column <= columnDimension.</code>
|
||||
* Column indices start at 0. A <code>MatrixIndexException</code> is thrown
|
||||
* unless <code>0 <= column < columnDimension.</code>
|
||||
*
|
||||
* @param col the column to be fetched
|
||||
* @return array of entries in the column
|
||||
* @throws MatrixIndexException if the specified column index is not valid
|
||||
*/
|
||||
public double[] getColumn(int col) throws MatrixIndexException {
|
||||
if ( !isValidCoordinate(1, col) ) {
|
||||
if ( !isValidCoordinate(0, col) ) {
|
||||
throw new MatrixIndexException("illegal column argument");
|
||||
}
|
||||
int nRows = this.getRowDimension();
|
||||
double[] out = new double[nRows];
|
||||
for (int row = 0; row < nRows; row++) {
|
||||
out[row] = data[row][col - 1];
|
||||
out[row] = data[row][col];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -348,10 +353,10 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||
/**
|
||||
* Returns the entry in the specified row and column.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -365,16 +370,16 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||
if (!isValidCoordinate(row,column)) {
|
||||
throw new MatrixIndexException("matrix entry does not exist");
|
||||
}
|
||||
return data[row - 1][column - 1];
|
||||
return data[row][column];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry in the specified row and column to the specified value.
|
||||
* <p>
|
||||
* Row and column indices start at 1 and must satisfy
|
||||
* Row and column indices start at 0 and must satisfy
|
||||
* <ul>
|
||||
* <li><code>0 < row <= rowDimension</code></li>
|
||||
* <li><code> 0 < column <= columnDimension</code></li>
|
||||
* <li><code>0 <= row < rowDimension</code></li>
|
||||
* <li><code> 0 <= column < columnDimension</code></li>
|
||||
* </ul>
|
||||
* otherwise a <code>MatrixIndexException</code> is thrown.
|
||||
*
|
||||
|
@ -388,7 +393,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||
if (!isValidCoordinate(row,column)) {
|
||||
throw new MatrixIndexException("matrix entry does not exist");
|
||||
}
|
||||
data[row - 1][column - 1] = value;
|
||||
data[row][column] = value;
|
||||
lu = null;
|
||||
}
|
||||
|
||||
|
@ -850,7 +855,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
|
|||
int nRows = this.getRowDimension();
|
||||
int nCols = this.getColumnDimension();
|
||||
|
||||
return !(row < 1 || row > nRows || col < 1 || col > nCols);
|
||||
return !(row < 0 || row > nRows - 1 || col < 0 || col > nCols -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.math.BigDecimal;
|
|||
/**
|
||||
* Test cases for the {@link BigMatrixImpl} class.
|
||||
*
|
||||
* @version $Revision: 1.2 $ $Date: 2004/07/11 04:49:24 $
|
||||
* @version $Revision: 1.3 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
|
||||
public final class BigMatrixImplTest extends TestCase {
|
||||
|
@ -425,8 +425,8 @@ public final class BigMatrixImplTest extends TestCase {
|
|||
|
||||
public void testGetVectors() {
|
||||
BigMatrix m = new BigMatrixImpl(testData);
|
||||
assertClose("get row",m.getRowAsDoubleArray(1),testDataRow1,entryTolerance);
|
||||
assertClose("get col",m.getColumnAsDoubleArray(3),testDataCol3,entryTolerance);
|
||||
assertClose("get row",m.getRowAsDoubleArray(0),testDataRow1,entryTolerance);
|
||||
assertClose("get col",m.getColumnAsDoubleArray(2),testDataCol3,entryTolerance);
|
||||
try {
|
||||
double[] x = m.getRowAsDoubleArray(10);
|
||||
fail("expecting MatrixIndexException");
|
||||
|
@ -443,17 +443,17 @@ public final class BigMatrixImplTest extends TestCase {
|
|||
|
||||
public void testEntryMutators() {
|
||||
BigMatrix m = new BigMatrixImpl(testData);
|
||||
assertEquals("get entry",m.getEntry(1,2).doubleValue(),2d,entryTolerance);
|
||||
m.setEntry(1,2,100d);
|
||||
assertEquals("get entry",m.getEntry(1,2).doubleValue(),100d,entryTolerance);
|
||||
assertEquals("get entry",m.getEntry(0,1).doubleValue(),2d,entryTolerance);
|
||||
m.setEntry(0,1,100d);
|
||||
assertEquals("get entry",m.getEntry(0,1).doubleValue(),100d,entryTolerance);
|
||||
try {
|
||||
double x = m.getEntry(0,2).doubleValue();
|
||||
double x = m.getEntry(-1,2).doubleValue();
|
||||
fail("expecting MatrixIndexException");
|
||||
} catch (MatrixIndexException ex) {
|
||||
;
|
||||
}
|
||||
try {
|
||||
m.setEntry(1,4,200d);
|
||||
m.setEntry(1,3,200d);
|
||||
fail("expecting MatrixIndexException");
|
||||
} catch (MatrixIndexException ex) {
|
||||
;
|
||||
|
@ -529,8 +529,8 @@ public final class BigMatrixImplTest extends TestCase {
|
|||
throw new InvalidMatrixException("incorrect dimensions");
|
||||
}
|
||||
int n = lu.getRowDimension();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (j < i) {
|
||||
lower.setEntry(i, j, lu.getEntry(i, j));
|
||||
upper.setEntry(i, j, 0d);
|
||||
|
@ -552,9 +552,9 @@ public final class BigMatrixImplTest extends TestCase {
|
|||
}
|
||||
int n = matrix.getRowDimension();
|
||||
BigMatrix out = new BigMatrixImpl(n, n);
|
||||
for (int i =1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
out.setEntry(i, j, matrix.getEntry(permutation[i -1] + 1, j));
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
out.setEntry(i, j, matrix.getEntry(permutation[i], j));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
@ -577,7 +577,7 @@ public final class BigMatrixImplTest extends TestCase {
|
|||
for (int i = 0; i < m.getRowDimension(); i++) {
|
||||
String os = "";
|
||||
for (int j = 0; j < m.getColumnDimension(); j++) {
|
||||
os += m.getEntry(i+1, j+1) + " ";
|
||||
os += m.getEntry(i, j) + " ";
|
||||
}
|
||||
System.out.println(os);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import junit.framework.TestSuite;
|
|||
/**
|
||||
* Test cases for the {@link RealMatrixImpl} class.
|
||||
*
|
||||
* @version $Revision: 1.14 $ $Date: 2004/05/18 04:08:38 $
|
||||
* @version $Revision: 1.15 $ $Date: 2004/09/05 01:19:23 $
|
||||
*/
|
||||
|
||||
public final class RealMatrixImplTest extends TestCase {
|
||||
|
@ -369,8 +369,8 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
|
||||
public void testGetVectors() {
|
||||
RealMatrix m = new RealMatrixImpl(testData);
|
||||
assertClose("get row",m.getRow(1),testDataRow1,entryTolerance);
|
||||
assertClose("get col",m.getColumn(3),testDataCol3,entryTolerance);
|
||||
assertClose("get row",m.getRow(0),testDataRow1,entryTolerance);
|
||||
assertClose("get col",m.getColumn(2),testDataCol3,entryTolerance);
|
||||
try {
|
||||
double[] x = m.getRow(10);
|
||||
fail("expecting MatrixIndexException");
|
||||
|
@ -387,11 +387,11 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
|
||||
public void testEntryMutators() {
|
||||
RealMatrix m = new RealMatrixImpl(testData);
|
||||
assertEquals("get entry",m.getEntry(1,2),2d,entryTolerance);
|
||||
assertEquals("get entry",m.getEntry(0,1),2d,entryTolerance);
|
||||
m.setEntry(1,2,100d);
|
||||
assertEquals("get entry",m.getEntry(1,2),100d,entryTolerance);
|
||||
try {
|
||||
double x = m.getEntry(0,2);
|
||||
double x = m.getEntry(-1,2);
|
||||
fail("expecting MatrixIndexException");
|
||||
} catch (MatrixIndexException ex) {
|
||||
;
|
||||
|
@ -492,8 +492,8 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
throw new InvalidMatrixException("incorrect dimensions");
|
||||
}
|
||||
int n = lu.getRowDimension();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (j < i) {
|
||||
lower.setEntry(i, j, lu.getEntry(i, j));
|
||||
upper.setEntry(i, j, 0d);
|
||||
|
@ -515,9 +515,9 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
}
|
||||
int n = matrix.getRowDimension();
|
||||
RealMatrix out = new RealMatrixImpl(n, n);
|
||||
for (int i =1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
out.setEntry(i, j, matrix.getEntry(permutation[i -1] + 1, j));
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
out.setEntry(i, j, matrix.getEntry(permutation[i], j));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
@ -540,7 +540,7 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
for (int i = 0; i < m.getRowDimension(); i++) {
|
||||
String os = "";
|
||||
for (int j = 0; j < m.getColumnDimension(); j++) {
|
||||
os += m.getEntry(i+1, j+1) + " ";
|
||||
os += m.getEntry(i, j) + " ";
|
||||
}
|
||||
System.out.println(os);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue