commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/linear BigMatrixImplTest.java RealMatrixImplTest.java
Date Sun, 05 Sep 2004 01:19:23 GMT
psteitz     2004/09/04 18:19:23

  Modified:    math/src/java/org/apache/commons/math/linear BigMatrix.java
                        BigMatrixImpl.java RealMatrix.java
                        RealMatrixImpl.java
               math/src/test/org/apache/commons/math/linear
                        BigMatrixImplTest.java RealMatrixImplTest.java
  Log:
  Changed matrix indexing to be 0-based.
  
  Revision  Changes    Path
  1.7       +27 -24    jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrix.java
  
  Index: BigMatrix.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrix.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BigMatrix.java	1 Sep 2004 21:26:11 -0000	1.6
  +++ BigMatrix.java	5 Sep 2004 01:19:23 -0000	1.7
  @@ -21,6 +21,9 @@
   /**
    * 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$ $Date$
    */
  @@ -151,8 +154,8 @@
       /**
        * 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 @@
        * 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 @@
       /**
        * 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 @@
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
        * 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.
        * 
  
  
  
  1.6       +44 -40    jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrixImpl.java
  
  Index: BigMatrixImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrixImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BigMatrixImpl.java	1 Sep 2004 21:26:11 -0000	1.5
  +++ BigMatrixImpl.java	5 Sep 2004 01:19:23 -0000	1.6
  @@ -30,15 +30,19 @@
    * <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.
  - *
  + * 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$ $Date$
    */
   public class BigMatrixImpl implements BigMatrix, Serializable {
  @@ -428,20 +432,20 @@
       /**
        * 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 @@
        * 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 @@
        /**
        * 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 @@
        * 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 @@
        /**
        * 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 @@
           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 @@
       /**
        * 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 @@
           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 @@
        * 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 @@
           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);
       }
       
   }
  
  
  
  1.22      +16 -12    jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrix.java
  
  Index: RealMatrix.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrix.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- RealMatrix.java	1 Sep 2004 21:26:11 -0000	1.21
  +++ RealMatrix.java	5 Sep 2004 01:19:23 -0000	1.22
  @@ -17,7 +17,11 @@
   package org.apache.commons.math.linear;
   
   /**
  - * Interface defining a real-valued matrix with basic algebraic operations
  + * 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$ $Date$
    */
   public interface RealMatrix {
  @@ -108,8 +112,8 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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 @@
       /**
        * 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.
        * 
  
  
  
  1.28      +25 -20    jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
  
  Index: RealMatrixImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- RealMatrixImpl.java	1 Sep 2004 21:26:11 -0000	1.27
  +++ RealMatrixImpl.java	5 Sep 2004 01:19:23 -0000	1.28
  @@ -29,14 +29,19 @@
    * <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$ $Date$
    */
  @@ -306,41 +311,41 @@
        /**
        * 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 @@
       /**
        * 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 @@
           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 @@
           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 @@
           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);
       }
   
   }
  
  
  
  1.3       +14 -14    jakarta-commons/math/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java
  
  Index: BigMatrixImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BigMatrixImplTest.java	11 Jul 2004 04:49:24 -0000	1.2
  +++ BigMatrixImplTest.java	5 Sep 2004 01:19:23 -0000	1.3
  @@ -425,8 +425,8 @@
       
       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 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 @@
               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 @@
           }
           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 @@
             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);
             }
  
  
  
  1.15      +11 -11    jakarta-commons/math/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
  
  Index: RealMatrixImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RealMatrixImplTest.java	18 May 2004 04:08:38 -0000	1.14
  +++ RealMatrixImplTest.java	5 Sep 2004 01:19:23 -0000	1.15
  @@ -369,8 +369,8 @@
       
       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 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 @@
               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 @@
           }
           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 @@
             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);
             }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message