commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1027952 [3/5] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ main/java/org/apache/commons/math/linear/ main/resources/META-INF/localization/ test/java/org...
Date Wed, 27 Oct 2010 13:16:58 GMT
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java Wed Oct 27 13:16:57 2010
@@ -34,112 +34,120 @@ public interface FieldMatrix<T extends F
 
     /**
      * Get the type of field elements of the matrix.
-     * @return type of field elements of the matrix
+     *
+     * @return the type of field elements of the matrix.
      */
     Field<T> getField();
 
     /**
-     * Create a new FieldMatrix<T> of the same type as the instance with the supplied
-     * row and column dimensions.
+     * Create a new FieldMatrix<T> of the same type as the instance with
+     * the supplied row and column dimensions.
      *
      * @param rowDimension  the number of rows in the new matrix
      * @param columnDimension  the number of columns in the new matrix
      * @return a new matrix of the same type as the instance
-     * @throws IllegalArgumentException if row or column dimension is not positive
+     * @throws org.apache.commons.math.exception.NotStrictlyPositiveException
+     * if row or column dimension is not positive.
      * @since 2.0
      */
     FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension);
 
     /**
-     * Returns a (deep) copy of this.
+     * Make a (deep) copy of this.
      *
-     * @return matrix copy
+     * @return a copy of this matrix.
      */
     FieldMatrix<T> copy();
 
     /**
      * Compute the sum of this and m.
      *
-     * @param m    matrix to be added
-     * @return     this + m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be added.
+     * @return {@code this} + {@code m}.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
     FieldMatrix<T> add(FieldMatrix<T> m);
 
     /**
-     * Compute this minus m.
+     * Subtract {@code m} from this matrix.
      *
-     * @param m    matrix to be subtracted
-     * @return     this + m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be subtracted.
+     * @return {@code this} - {@code m}.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
     FieldMatrix<T> subtract(FieldMatrix<T> m);
 
      /**
-     * Returns the result of adding d to each entry of this.
+     * Increment each entry of this matrix.
      *
-     * @param d    value to be added to each entry
-     * @return     d + this
+     * @param d Value to be added to each entry.
+     * @return {@code d} + {@code this}.
      */
     FieldMatrix<T> scalarAdd(T d);
 
     /**
-     * Returns the result multiplying each entry of this by d.
+     * Multiply each entry by {@code d}.
      *
-     * @param d    value to multiply all entries by
-     * @return     d * this
+     * @param d Value to multiply all entries by.
+     * @return {@code d} * {@code this}.
      */
     FieldMatrix<T> scalarMultiply(T d);
 
     /**
-     * Returns the result of postmultiplying this by m.
+     * Postmultiply this matrix by {@code m}.
      *
-     * @param m    matrix to postmultiply by
-     * @return     this * m
-     * @throws     IllegalArgumentException
+     * @param m  Matrix to postmultiply by.
+     * @return {@code this} * {@code m}.
+     * @throws IllegalArgumentException
      *             if columnDimension(this) != rowDimension(m)
      */
     FieldMatrix<T> multiply(FieldMatrix<T> m);
 
     /**
-     * Returns the result premultiplying this by <code>m</code>.
-     * @param m    matrix to premultiply by
-     * @return     m * this
-     * @throws     IllegalArgumentException
-     *             if rowDimension(this) != columnDimension(m)
+     * Premultiply this matrix by {@code m}.
+     *
+     * @param m Matrix to premultiply by.
+     * @return {@code m} * {@code this}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the number of columns of {@code m} differ from the number of rows
+     * of this matrix.
      */
     FieldMatrix<T> preMultiply(FieldMatrix<T> m);
 
     /**
      * Returns matrix entries as a two-dimensional array.
      *
-     * @return    2-dimensional array of entries
+     * @return a 2-dimensional array of entries.
      */
     T[][] getData();
 
     /**
-     * Gets a submatrix. Rows and columns are indicated
-     * counting from 0 to n-1.
+     * Get a submatrix. Rows and columns are indicated
+     * counting from 0 to n - 1.
      *
      * @param startRow Initial row index
      * @param endRow Final row index (inclusive)
      * @param startColumn Initial column index
      * @param endColumn Final column index (inclusive)
-     * @return The subMatrix containing the data of the
-     *         specified rows and columns
-     * @exception MatrixIndexException  if the indices are not valid
+     * @return the matrix containing the data of the
+     * specified rows and columns.
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      */
    FieldMatrix<T> getSubMatrix(int startRow, int endRow, int startColumn, int endColumn);
 
    /**
-    * Gets a submatrix. Rows and columns are indicated
-    * counting from 0 to n-1.
+    * Get a submatrix. Rows and columns are indicated
+    * counting from 0 to n - 1.
     *
     * @param selectedRows Array of row indices.
     * @param selectedColumns Array of column indices.
-    * @return The subMatrix containing the data in the
-    *         specified rows and columns
-    * @exception MatrixIndexException if row or column selections are not valid
+    * @return the matrix containing the data in the
+    * specified rows and columns.
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if row or column selections are not valid.
     */
    FieldMatrix<T> getSubMatrix(int[] selectedRows, int[] selectedColumns);
 
@@ -147,34 +155,36 @@ public interface FieldMatrix<T extends F
     * Copy a submatrix. Rows and columns are indicated
     * counting from 0 to n-1.
     *
-    * @param startRow Initial row index
-    * @param endRow Final row index (inclusive)
-    * @param startColumn Initial column index
-    * @param endColumn Final column index (inclusive)
+    * @param startRow Initial row index.
+    * @param endRow Final row index (inclusive).
+    * @param startColumn Initial column index.
+    * @param endColumn Final column index (inclusive).
     * @param destination The arrays where the submatrix data should be copied
-    * (if larger than rows/columns counts, only the upper-left part will be used)
-    * @exception MatrixIndexException if the indices are not valid
-    * @exception IllegalArgumentException if the destination array is too small
+    * (if larger than rows/columns counts, only the upper-left part will be used).
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the indices are not valid.
+    * @exception IllegalArgumentException if the destination array is too small.
     */
   void copySubMatrix(int startRow, int endRow, int startColumn, int endColumn,
                      T[][] destination);
 
   /**
    * Copy a submatrix. Rows and columns are indicated
-   * counting from 0 to n-1.
+   * counting from 0 to n - 1.
    *
-    * @param selectedRows Array of row indices.
-    * @param selectedColumns Array of column indices.
-   * @param destination The arrays where the submatrix data should be copied
+   * @param selectedRows Array of row indices.
+   * @param selectedColumns Array of column indices.
+   * @param destination Arrays where the submatrix data should be copied
    * (if larger than rows/columns counts, only the upper-left part will be used)
-   * @exception MatrixIndexException if the indices are not valid
+   * @throws org.apache.commons.math.exception.OutOfRangeException
+   * if the indices are not valid.
    * @exception IllegalArgumentException if the destination array is too small
    */
   void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination);
 
    /**
-    * Replace the submatrix starting at <code>row, column</code> using data in
-    * the input <code>subMatrix</code> array. Indexes are 0-based.
+    * Replace the submatrix starting at {@code (row, column)} using data in
+    * the input {@code subMatrix} array. Indexes are 0-based.
     * <p>
     * Example:<br>
     * Starting with <pre>
@@ -189,152 +199,165 @@ public interface FieldMatrix<T extends F
     * 9  5  6  2
     * </pre></p>
     *
-    * @param subMatrix  array containing the submatrix replacement data
-    * @param row  row coordinate of the top, left element to be replaced
-    * @param column  column coordinate of the top, left element to be replaced
-    * @throws MatrixIndexException  if subMatrix does not fit into this
-    *    matrix from element in (row, column)
-    * @throws IllegalArgumentException if <code>subMatrix</code> is not rectangular
-    *  (not all rows have the same length) or empty
-    * @throws NullPointerException if <code>subMatrix</code> is null
+    * @param subMatrix Array containing the submatrix replacement data.
+    * @param row Row coordinate of the top-left element to be replaced.
+    * @param column Column coordinate of the top-left element to be replaced.
+    * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+    * if {@code subMatrix} does not fit into this matrix from element in
+    * {@code (row, column)}.
+    * @throws org.apache.commons.math.exception.ZeroException if a row or column
+    * of {@code subMatrix} is empty.
+    * @throws org.apache.commons.math.exception.DimensionMismatchException
+    * if {@code subMatrix} is not rectangular (not all rows have the same
+    * length).
+    * @throws org.apache.commons.math.exception.NullArgumentException
+    * if {@code subMatrix} is {@code null}.
     * @since 2.0
     */
   void setSubMatrix(T[][] subMatrix, int row, int column);
 
    /**
-    * Returns the entries in row number <code>row</code>
-    * as a row matrix.  Row indices start at 0.
+    * Get the entries in row number {@code row}
+    * as a row matrix.
     *
-    * @param row the row to be fetched
-    * @return row matrix
-    * @throws MatrixIndexException if the specified row index is invalid
+    * @param row Row to be fetched.
+    * @return a row matrix.
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified row index is invalid.
     */
    FieldMatrix<T> getRowMatrix(int row);
 
    /**
-    * Sets the entries in row number <code>row</code>
-    * as a row matrix.  Row indices start at 0.
+    * Set the entries in row number {@code row}
+    * as a row matrix.
     *
-    * @param row the row to be set
-    * @param matrix row matrix (must have one row and the same number of columns
-    * as the instance)
-    * @throws MatrixIndexException if the specified row index is invalid
+    * @param row Row to be set.
+    * @param matrix Row matrix (must have one row and the same number
+    * of columns as the instance).
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified row index is invalid.
     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
     * if the matrix dimensions do not match one instance row.
     */
    void setRowMatrix(int row, FieldMatrix<T> matrix);
 
    /**
-    * Returns the entries in column number <code>column</code>
-    * as a column matrix.  Column indices start at 0.
+    * Get the entries in column number {@code column}
+    * as a column matrix.
     *
-    * @param column the column to be fetched
-    * @return column matrix
-    * @throws MatrixIndexException if the specified column index is invalid
+    * @param column Column to be fetched.
+    * @return a column matrix.
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified column index is invalid.
     */
    FieldMatrix<T> getColumnMatrix(int column);
 
    /**
-    * Sets the entries in column number <code>column</code>
-    * as a column matrix.  Column indices start at 0.
+    * Set the entries in column number {@code column}
+    * as a column matrix.
     *
-    * @param column the column to be set
-    * @param matrix column matrix (must have one column and the same number of rows
-    * as the instance)
-    * @throws MatrixIndexException if the specified column index is invalid
+    * @param column Column to be set.
+    * @param matrix column matrix (must have one column and the same
+    * number of rows as the instance).
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified column index is invalid.
     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
     * if the matrix dimensions do not match one instance column.
     */
    void setColumnMatrix(int column, FieldMatrix<T> matrix);
 
    /**
-    * Returns the entries in row number <code>row</code>
-    * as a vector.  Row indices start at 0.
+    * Get the entries in row number {@code row}
+    * as a vector.
     *
-    * @param row the row to be fetched
-    * @return row vector
-    * @throws MatrixIndexException if the specified row index is invalid
+    * @param row Row to be fetched
+    * @return a row vector.
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified row index is invalid.
     */
    FieldVector<T> getRowVector(int row);
 
    /**
-    * Sets the entries in row number <code>row</code>
-    * as a vector.  Row indices start at 0.
+    * Set the entries in row number {@code row}
+    * as a vector.
     *
-    * @param row the row to be set
+    * @param row Row to be set.
     * @param vector row vector (must have the same number of columns
-    * as the instance)
-    * @throws MatrixIndexException if the specified row index is invalid
+    * as the instance).
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified row index is invalid.
     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
     * if the vector dimension does not match one instance row.
     */
    void setRowVector(int row, FieldVector<T> vector);
 
    /**
-    * Returns the entries in column number <code>column</code>
-    * as a vector.  Column indices start at 0.
+    * Returns the entries in column number {@code column}
+    * as a vector.
     *
-    * @param column the column to be fetched
-    * @return column vector
-    * @throws MatrixIndexException if the specified column index is invalid
+    * @param column Column to be fetched.
+    * @return a column vector.
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified column index is invalid.
     */
    FieldVector<T> getColumnVector(int column);
 
    /**
-    * Sets the entries in column number <code>column</code>
-    * as a vector.  Column indices start at 0.
+    * Set the entries in column number {@code column}
+    * as a vector.
     *
-    * @param column the column to be set
-    * @param vector column vector (must have the same number of rows as the instance)
-    * @throws MatrixIndexException if the specified column index is invalid
+    * @param column Column to be set.
+    * @param vector Column vector (must have the same number of rows
+    * as the instance).
+    * @throws org.apache.commons.math.exception.OutOfRangeException
+    * if the specified column index is invalid.
     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
     * if the vector dimension does not match one instance column.
     */
    void setColumnVector(int column, FieldVector<T> vector);
 
     /**
-     * Returns the entries in row number <code>row</code> as an array.
-     * <p>
-     * Row indices start at 0.  A <code>MatrixIndexException</code> is thrown
-     * unless {@code 0 <= row < rowDimension}.</p>
-     *
-     * @param row the row to be fetched
-     * @return array of entries in the row
-     * @throws MatrixIndexException if the specified row index is not valid
+     * Get the entries in row number {@code row} as an array.
+     *
+     * @param row Row to be fetched.
+     * @return array of entries in the row.
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the specified row index is not valid.
      */
     T[] getRow(int row);
 
     /**
-     * Sets the entries in row number <code>row</code>
-     * as a row matrix.  Row indices start at 0.
+     * Set the entries in row number {@code row}
+     * as a row matrix.
      *
-     * @param row the row to be set
-     * @param array row matrix (must have the same number of columns as the instance)
-     * @throws MatrixIndexException if the specified row index is invalid
+     * @param row Row to be set.
+     * @param array Row matrix (must have the same number of columns as
+     * the instance).
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the specified row index is invalid.
      * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
      * if the array size does not match one instance row.
      */
     void setRow(int row, T[] array);
 
     /**
-     * Returns the entries in column number <code>col</code> as an array.
-     * <p>
-     * Column indices start at 0.  A <code>MatrixIndexException</code> is thrown
-     * unless {@code 0 <= column < columnDimension}.</p>
+     * Get the entries in column number {@code col} as an array.
      *
      * @param column the column to be fetched
      * @return array of entries in the column
-     * @throws MatrixIndexException if the specified column index is not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the specified column index is not valid.
      */
     T[] getColumn(int column);
 
     /**
-     * Sets the entries in column number <code>column</code>
-     * as a column matrix.  Column indices start at 0.
+     * Set the entries in column number {@code column}
+     * as a column matrix.
      *
      * @param column the column to be set
      * @param array column array (must have the same number of rows as the instance)
-     * @throws MatrixIndexException if the specified column index is invalid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the specified column index is invalid.
      * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
      * if the array size does not match one instance column.
      */
@@ -342,71 +365,49 @@ public interface FieldMatrix<T extends F
 
     /**
      * Returns the entry in the specified row and column.
-     * <p>
-     * Row and column indices start at 0 and must satisfy
-     * <ul>
-     * <li>{@code 0 <= row < rowDimension}</li>
-     * <li>{@code 0 <= column < columnDimension}</li>
-     * </ul>
-     * otherwise a <code>MatrixIndexException</code> is thrown.</p>
      *
      * @param row  row location of entry to be fetched
      * @param column  column location of entry to be fetched
      * @return matrix entry in row,column
-     * @throws MatrixIndexException if the row or column index is not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the row or column index is not valid.
      */
     T getEntry(int row, int column);
 
     /**
      * Set the entry in the specified row and column.
-     * <p>
-     * Row and column indices start at 0 and must satisfy
-     * <ul>
-     * <li>{@code 0 <= row < rowDimension}</li>
-     * <li>{@code 0 <= column < columnDimension}</li>
-     * </ul>
-     * otherwise a <code>MatrixIndexException</code> is thrown.</p>
      *
      * @param row  row location of entry to be set
      * @param column  column location of entry to be set
      * @param value matrix entry to be set in row,column
-     * @throws MatrixIndexException if the row or column index is not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the row or column index is not valid.
      * @since 2.0
      */
     void setEntry(int row, int column, T value);
 
     /**
      * Change an entry in the specified row and column.
-     * <p>
-     * Row and column indices start at 0 and must satisfy
-     * <ul>
-     * <li>{@code 0 <= row < rowDimension}</li>
-     * <li>{@code 0 <= column < columnDimension}</li>
-     * </ul>
-     * otherwise a <code>MatrixIndexException</code> is thrown.</p>
      *
-     * @param row  row location of entry to be set
-     * @param column  column location of entry to be set
-     * @param increment value to add to the current matrix entry in row,column
-     * @throws MatrixIndexException if the row or column index is not valid
+     * @param row Row location of entry to be set.
+     * @param column Column location of entry to be set.
+     * @param increment Value to add to the current matrix entry in
+     * {@code (row, column)}.
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the row or column index is not valid.
      * @since 2.0
      */
-    void addToEntry(int row, int column, T increment) throws MatrixIndexException;
+    void addToEntry(int row, int column, T increment);
 
     /**
      * Change an entry in the specified row and column.
-     * <p>
-     * Row and column indices start at 0 and must satisfy
-     * <ul>
-     * <li>{@code 0 <= row < rowDimension}</li>
-     * <li>{@code 0 <= column < columnDimension}</li>
-     * </ul>
-     * otherwise a <code>MatrixIndexException</code> is thrown.</p>
      *
-     * @param row  row location of entry to be set
-     * @param column  column location of entry to be set
-     * @param factor multiplication factor for the current matrix entry in row,column
-     * @throws MatrixIndexException if the row or column index is not valid
+     * @param row Row location of entry to be set.
+     * @param column Column location of entry to be set.
+     * @param factor Multiplication factor for the current matrix entry
+     * in {@code (row,column)}
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the row or column index is not valid.
      * @since 2.0
      */
     void multiplyEntry(int row, int column, T factor);
@@ -520,7 +521,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int)
@@ -549,7 +551,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
@@ -624,7 +627,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
@@ -653,7 +657,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
@@ -725,7 +730,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index (inclusive)
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)
@@ -753,7 +759,8 @@ public interface FieldMatrix<T extends F
      * @param startColumn Initial column index
      * @param endColumn Final column index (inclusive)
      * @exception  MatrixVisitorException if the visitor cannot process an entry
-     * @exception MatrixIndexException  if the indices are not valid
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the indices are not valid.
      * @see #walkInRowOrder(FieldMatrixChangingVisitor)
      * @see #walkInRowOrder(FieldMatrixPreservingVisitor)
      * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int)

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldVector.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldVector.java Wed Oct 27 13:16:57 2010
@@ -258,28 +258,24 @@ public interface FieldVector<T extends F
 
     /**
      * Returns the entry in the specified index.
-     * <p>
-     * The index start at 0 and must be lesser than the size,
-     * otherwise a {@link MatrixIndexException} is thrown.
-     * </p>
-     * @param index  index location of entry to be fetched
-     * @return vector entry at index
-     * @throws MatrixIndexException if the index is not valid
+     *
+     * @param index Index location of entry to be fetched.
+     * @return the vector entry at {@code index}.
+     * @throws org.apache.commons.math.exception.OutOfRangeException if the
+     * index is not valid.
      * @see #setEntry(int, FieldElement)
      */
-    T getEntry(int index)
-        throws MatrixIndexException;
+    T getEntry(int index);
 
     /**
      * Set a single element.
      * @param index element index.
      * @param value new value for the element.
-     * @exception MatrixIndexException if the index is
-     * inconsistent with vector size
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the index is inconsistent with vector size.
      * @see #getEntry(int)
      */
-    void setEntry(int index, T value)
-        throws MatrixIndexException;
+    void setEntry(int index, T value);
 
     /**
      * Returns the size of the vector.
@@ -313,33 +309,30 @@ public interface FieldVector<T extends F
      * @param index index of first element.
      * @param n number of elements to be retrieved.
      * @return a vector containing n elements.
-     * @exception MatrixIndexException if the index is
-     * inconsistent with vector size
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the index is inconsistent with vector size.
      */
-    FieldVector<T> getSubVector(int index, int n)
-        throws MatrixIndexException;
+    FieldVector<T> getSubVector(int index, int n);
 
     /**
      * Set a set of consecutive elements.
      * @param index index of first element to be set.
      * @param v vector containing the values to set.
-     * @exception MatrixIndexException if the index is
-     * inconsistent with vector size
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the index is inconsistent with vector size.
      * @see #setSubVector(int, FieldElement[])
      */
-    void setSubVector(int index, FieldVector<T> v)
-        throws MatrixIndexException;
+    void setSubVector(int index, FieldVector<T> v);
 
     /**
      * Set a set of consecutive elements.
      * @param index index of first element to be set.
      * @param v vector containing the values to set.
-     * @exception MatrixIndexException if the index is
-     * inconsistent with vector size
+     * @throws org.apache.commons.math.exception.OutOfRangeException
+     * if the index is inconsistent with vector size.
      * @see #setSubVector(int, FieldVector)
      */
-    void setSubVector(int index, T[] v)
-        throws MatrixIndexException;
+    void setSubVector(int index, T[] v);
 
     /**
      * Set all elements to a single value.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java Wed Oct 27 13:16:57 2010
@@ -25,6 +25,8 @@ import org.apache.commons.math.exception
  * Thrown when an operation addresses a matrix coordinate (row, col)
  * which is outside of the dimensions of a matrix.
  * @version $Revision$ $Date$
+ * @deprecated in 2.2 (to be removed in 3.0). Please use the exceptions in package
+ * {@link org.apache.commons.math.exception}.
  */
 public class MatrixIndexException extends MathRuntimeException {
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java Wed Oct 27 13:16:57 2010
@@ -21,12 +21,15 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Array;
-import java.math.BigDecimal;
 import java.util.Arrays;
 
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
 import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.OutOfRangeException;
+import org.apache.commons.math.exception.ZeroException;
+import org.apache.commons.math.exception.NumberIsTooSmallException;
+import org.apache.commons.math.exception.NullArgumentException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.fraction.BigFraction;
 import org.apache.commons.math.fraction.Fraction;
@@ -97,13 +100,18 @@ public class MatrixUtils {
      *
      * @param data input array
      * @return  RealMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if either <code>data</code> or
-     * <code>data[0]</code> is null
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code data} is not rectangular (not all rows have the same length).
+     * @throws ZeroException if a row or column is empty.
+     * @throws NullArgumentException if either {@code data} or {@code data[0]}
+     * is {@code null}.
      * @see #createRealMatrix(int, int)
      */
     public static RealMatrix createRealMatrix(double[][] data) {
+        if (data == null ||
+            data[0] == null) {
+            throw new NullArgumentException();
+        }
         return (data.length * data[0].length <= 4096) ?
                 new Array2DRowRealMatrix(data) : new BlockRealMatrix(data);
     }
@@ -118,15 +126,20 @@ public class MatrixUtils {
      * <p>The input array is copied, not referenced.</p>
      * @param <T> the type of the field elements
      * @param data input array
-     * @return  RealMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if either <code>data</code> or
-     * <code>data[0]</code> is null
+     * @return a matrix containing the values of the array.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code data} is not rectangular (not all rows have the same length).
+     * @throws ZeroException if a row or column is empty.
+     * @throws NullArgumentException if either {@code data} or {@code data[0]}
+     * is {@code null}.
      * @see #createFieldMatrix(Field, int, int)
      * @since 2.0
      */
     public static <T extends FieldElement<T>> FieldMatrix<T> createFieldMatrix(T[][] data) {
+        if (data == null ||
+            data[0] == null) {
+            throw new NullArgumentException();
+        }
         return (data.length * data[0].length <= 4096) ?
                 new Array2DRowFieldMatrix<T>(data) : new BlockFieldMatrix<T>(data);
     }
@@ -172,26 +185,6 @@ public class MatrixUtils {
     }
 
     /**
-     * Returns <code>dimension x dimension</code> identity matrix.
-     *
-     * @param dimension dimension of identity matrix to generate
-     * @return identity matrix
-     * @throws IllegalArgumentException if dimension is not positive
-     * @since 1.1
-     * @deprecated since 2.0, replaced by {@link #createFieldIdentityMatrix(Field, int)}
-     */
-    @Deprecated
-    public static BigMatrix createBigIdentityMatrix(int dimension) {
-        final BigDecimal[][] d = new BigDecimal[dimension][dimension];
-        for (int row = 0; row < dimension; row++) {
-            final BigDecimal[] dRow = d[row];
-            Arrays.fill(dRow, BigMatrixImpl.ZERO);
-            dRow[row] = BigMatrixImpl.ONE;
-        }
-        return new BigMatrixImpl(d, false);
-    }
-
-    /**
      * Returns a diagonal matrix with specified elements.
      *
      * @param diagonal diagonal elements of the matrix (the array elements
@@ -227,84 +220,17 @@ public class MatrixUtils {
     }
 
     /**
-     * Returns a {@link BigMatrix} whose entries are the the values in the
-     * the input array.  The input array is copied, not referenced.
-     *
-     * @param data input array
-     * @return  RealMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if data is null
-     * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])}
-     */
-    @Deprecated
-    public static BigMatrix createBigMatrix(double[][] data) {
-        return new BigMatrixImpl(data);
-    }
-
-    /**
-     * Returns a {@link BigMatrix} whose entries are the the values in the
-     * the input array.  The input array is copied, not referenced.
-     *
-     * @param data input array
-     * @return  RealMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if data is null
-     * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])}
-     */
-    @Deprecated
-    public static BigMatrix createBigMatrix(BigDecimal[][] data) {
-        return new BigMatrixImpl(data);
-    }
-
-    /**
-     * Returns a {@link BigMatrix} whose entries are the the values in the
-     * the input array.
-     * <p>If an array is built specially in order to be embedded in a
-     * BigMatrix and not used directly, the <code>copyArray</code> may be
-     * set to <code>false</code. This will prevent the copying and improve
-     * performance as no new array will be built and no data will be copied.</p>
-     * @param data data for new matrix
-     * @param copyArray if true, the input array will be copied, otherwise
-     * it will be referenced
-     * @return  BigMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if <code>data</code> is null
-     * @see #createRealMatrix(double[][])
-     * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])}
-     */
-    @Deprecated
-    public static BigMatrix createBigMatrix(BigDecimal[][] data, boolean copyArray) {
-        return new BigMatrixImpl(data, copyArray);
-    }
-
-    /**
-     * Returns a {@link BigMatrix} whose entries are the the values in the
-     * the input array.  The input array is copied, not referenced.
-     *
-     * @param data input array
-     * @return  RealMatrix containing the values of the array
-     * @throws IllegalArgumentException if <code>data</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if data is null
-     * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])}
-     */
-    @Deprecated
-    public static BigMatrix createBigMatrix(String[][] data) {
-        return new BigMatrixImpl(data);
-    }
-
-    /**
      * Creates a {@link RealVector} using the data from the input array.
      *
      * @param data the input data
      * @return a data.length RealVector
-     * @throws IllegalArgumentException if <code>data</code> is empty
-     * @throws NullPointerException if <code>data</code>is null
+     * @throws ZeroException if {@code data} is empty.
+     * @throws NullArgumentException if {@code data} is {@code null}.
      */
     public static RealVector createRealVector(double[] data) {
+        if (data == null) {
+            throw new NullArgumentException();
+        }
         return new ArrayRealVector(data, true);
     }
 
@@ -314,23 +240,29 @@ public class MatrixUtils {
      * @param <T> the type of the field elements
      * @param data the input data
      * @return a data.length FieldVector
-     * @throws IllegalArgumentException if <code>data</code> is empty
-     * @throws NullPointerException if <code>data</code>is null
+     * @throws ZeroException if {@code data} is empty.
+     * @throws NullArgumentException if {@code data} is {@code null}.
      */
     public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data) {
+        if (data == null) {
+            throw new NullArgumentException();
+        }
         return new ArrayFieldVector<T>(data, true);
     }
 
     /**
-     * Creates a row {@link RealMatrix} using the data from the input
+     * Create a row {@link RealMatrix} using the data from the input
      * array.
      *
      * @param rowData the input row data
      * @return a 1 x rowData.length RealMatrix
-     * @throws IllegalArgumentException if <code>rowData</code> is empty
-     * @throws NullPointerException if <code>rowData</code>is null
+     * @throws ZeroException if {@code rowData} is empty.
+     * @throws NullArgumentException if {@code rowData} is {@code null}.
      */
     public static RealMatrix createRowRealMatrix(double[] rowData) {
+        if (rowData == null) {
+            throw new NullArgumentException();
+        }
         final int nCols = rowData.length;
         final RealMatrix m = createRealMatrix(1, nCols);
         for (int i = 0; i < nCols; ++i) {
@@ -340,20 +272,23 @@ public class MatrixUtils {
     }
 
     /**
-     * Creates a row {@link FieldMatrix} using the data from the input
+     * Create a row {@link FieldMatrix} using the data from the input
      * array.
      *
      * @param <T> the type of the field elements
      * @param rowData the input row data
      * @return a 1 x rowData.length FieldMatrix
-     * @throws IllegalArgumentException if <code>rowData</code> is empty
-     * @throws NullPointerException if <code>rowData</code>is null
+     * @throws ZeroException if {@code rowData} is empty.
+     * @throws NullArgumentException if {@code rowData} is {@code null}.
      */
     public static <T extends FieldElement<T>> FieldMatrix<T>
         createRowFieldMatrix(final T[] rowData) {
+        if (rowData == null) {
+            throw new NullArgumentException();
+        }
         final int nCols = rowData.length;
         if (nCols == 0) {
-            throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
+            throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
         }
         final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols);
         for (int i = 0; i < nCols; ++i) {
@@ -363,73 +298,18 @@ public class MatrixUtils {
     }
 
     /**
-     * Creates a row {@link BigMatrix} using the data from the input
-     * array.
-     *
-     * @param rowData the input row data
-     * @return a 1 x rowData.length BigMatrix
-     * @throws IllegalArgumentException if <code>rowData</code> is empty
-     * @throws NullPointerException if <code>rowData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createRowBigMatrix(double[] rowData) {
-        final int nCols = rowData.length;
-        final BigDecimal[][] data = new BigDecimal[1][nCols];
-        for (int i = 0; i < nCols; ++i) {
-            data[0][i] = new BigDecimal(rowData[i]);
-        }
-        return new BigMatrixImpl(data, false);
-    }
-
-    /**
-     * Creates a row {@link BigMatrix} using the data from the input
-     * array.
-     *
-     * @param rowData the input row data
-     * @return a 1 x rowData.length BigMatrix
-     * @throws IllegalArgumentException if <code>rowData</code> is empty
-     * @throws NullPointerException if <code>rowData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createRowBigMatrix(BigDecimal[] rowData) {
-        final int nCols = rowData.length;
-        final BigDecimal[][] data = new BigDecimal[1][nCols];
-        System.arraycopy(rowData, 0, data[0], 0, nCols);
-        return new BigMatrixImpl(data, false);
-    }
-
-    /**
-     * Creates a row {@link BigMatrix} using the data from the input
-     * array.
-     *
-     * @param rowData the input row data
-     * @return a 1 x rowData.length BigMatrix
-     * @throws IllegalArgumentException if <code>rowData</code> is empty
-     * @throws NullPointerException if <code>rowData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createRowBigMatrix(String[] rowData) {
-        final int nCols = rowData.length;
-        final BigDecimal[][] data = new BigDecimal[1][nCols];
-        for (int i = 0; i < nCols; ++i) {
-            data[0][i] = new BigDecimal(rowData[i]);
-        }
-        return new BigMatrixImpl(data, false);
-    }
-
-    /**
      * Creates a column {@link RealMatrix} using the data from the input
      * array.
      *
      * @param columnData  the input column data
      * @return a columnData x 1 RealMatrix
-     * @throws IllegalArgumentException if <code>columnData</code> is empty
-     * @throws NullPointerException if <code>columnData</code>is null
+     * @throws ZeroException if {@code columnData} is empty.
+     * @throws NullArgumentException if {@code columnData} is {@code null}.
      */
     public static RealMatrix createColumnRealMatrix(double[] columnData) {
+        if (columnData == null) {
+            throw new NullArgumentException();
+        }
         final int nRows = columnData.length;
         final RealMatrix m = createRealMatrix(nRows, 1);
         for (int i = 0; i < nRows; ++i) {
@@ -445,11 +325,14 @@ public class MatrixUtils {
      * @param <T> the type of the field elements
      * @param columnData  the input column data
      * @return a columnData x 1 FieldMatrix
-     * @throws IllegalArgumentException if <code>columnData</code> is empty
-     * @throws NullPointerException if <code>columnData</code>is null
+     * @throws ZeroException if {@code data} is empty.
+     * @throws NullArgumentException if {@code columnData} is {@code null}.
      */
     public static <T extends FieldElement<T>> FieldMatrix<T>
         createColumnFieldMatrix(final T[] columnData) {
+        if (columnData == null) {
+            throw new NullArgumentException();
+        }
         final int nRows = columnData.length;
         if (nRows == 0) {
             throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW);
@@ -462,118 +345,77 @@ public class MatrixUtils {
     }
 
     /**
-     * Creates a column {@link BigMatrix} using the data from the input
-     * array.
+     * Check if matrix indices are valid.
      *
-     * @param columnData  the input column data
-     * @return a columnData x 1 BigMatrix
-     * @throws IllegalArgumentException if <code>columnData</code> is empty
-     * @throws NullPointerException if <code>columnData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createColumnBigMatrix(double[] columnData) {
-        final int nRows = columnData.length;
-        final BigDecimal[][] data = new BigDecimal[nRows][1];
-        for (int row = 0; row < nRows; row++) {
-            data[row][0] = new BigDecimal(columnData[row]);
-        }
-        return new BigMatrixImpl(data, false);
-    }
-
-    /**
-     * Creates a column {@link BigMatrix} using the data from the input
-     * array.
-     *
-     * @param columnData  the input column data
-     * @return a columnData x 1 BigMatrix
-     * @throws IllegalArgumentException if <code>columnData</code> is empty
-     * @throws NullPointerException if <code>columnData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createColumnBigMatrix(BigDecimal[] columnData) {
-        final int nRows = columnData.length;
-        final BigDecimal[][] data = new BigDecimal[nRows][1];
-        for (int row = 0; row < nRows; row++) {
-            data[row][0] = columnData[row];
-        }
-        return new BigMatrixImpl(data, false);
-    }
-
-    /**
-     * Creates a column {@link BigMatrix} using the data from the input
-     * array.
-     *
-     * @param columnData  the input column data
-     * @return a columnData x 1 BigMatrix
-     * @throws IllegalArgumentException if <code>columnData</code> is empty
-     * @throws NullPointerException if <code>columnData</code>is null
-     * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])}
-     */
-    @Deprecated
-    public static BigMatrix createColumnBigMatrix(String[] columnData) {
-        int nRows = columnData.length;
-        final BigDecimal[][] data = new BigDecimal[nRows][1];
-        for (int row = 0; row < nRows; row++) {
-            data[row][0] = new BigDecimal(columnData[row]);
-        }
-        return new BigMatrixImpl(data, false);
+     * @param m Matrix.
+     * @param row Row index to check.
+     * @param column Column index to check.
+     * @throws OutOfRangeException if {@code row} or {@code column} is not
+     * a valid index.
+     */
+    public static void checkMatrixIndex(final AnyMatrix m,
+                                        final int row, final int column) {
+        checkRowIndex(m, row);
+        checkColumnIndex(m, column);
     }
 
     /**
      * Check if a row index is valid.
-     * @param m matrix containing the submatrix
-     * @param row row index to check
-     * @exception MatrixIndexException if index is not valid
+     *
+     * @param m Matrix.
+     * @param row Row index to check.
+     * @throws OutOfRangeException if {@code row} is not a valid index.
      */
     public static void checkRowIndex(final AnyMatrix m, final int row) {
-        if (row < 0 || row >= m.getRowDimension()) {
-            throw new MatrixIndexException(LocalizedFormats.ROW_INDEX_OUT_OF_RANGE,
-                                           row, 0, m.getRowDimension() - 1);
+        if (row < 0 ||
+            row >= m.getRowDimension()) {
+            throw new OutOfRangeException(LocalizedFormats.ROW_INDEX,
+                                          row, 0, m.getRowDimension() - 1);
         }
     }
 
     /**
      * Check if a column index is valid.
-     * @param m matrix containing the submatrix
-     * @param column column index to check
-     * @exception MatrixIndexException if index is not valid
+     *
+     * @param m Matrix.
+     * @param column Column index to check.
+     * @throws OutOfRangeException if {@code column} is not a valid index.
      */
-    public static void checkColumnIndex(final AnyMatrix m, final int column)
-        throws MatrixIndexException {
+    public static void checkColumnIndex(final AnyMatrix m, final int column) {
         if (column < 0 || column >= m.getColumnDimension()) {
-            throw new MatrixIndexException(LocalizedFormats.COLUMN_INDEX_OUT_OF_RANGE,
+            throw new OutOfRangeException(LocalizedFormats.COLUMN_INDEX,
                                            column, 0, m.getColumnDimension() - 1);
         }
     }
 
     /**
      * Check if submatrix ranges indices are valid.
-     * Rows and columns are indicated counting from 0 to n-1.
+     * Rows and columns are indicated counting from 0 to {@code n - 1}.
      *
-     * @param m matrix containing the submatrix
-     * @param startRow Initial row index
-     * @param endRow Final row index
-     * @param startColumn Initial column index
-     * @param endColumn Final column index
-     * @exception MatrixIndexException  if the indices are not valid
+     * @param m Matrix.
+     * @param startRow Initial row index.
+     * @param endRow Final row index.
+     * @param startColumn Initial column index.
+     * @param endColumn Final column index.
+     * @throws OutOfRangeException if the indices are invalid.
+     * @throws NumberIsTooSmallException if {@code endRow < startRow} or
+     * {@code endColumn < startColumn}.
      */
     public static void checkSubMatrixIndex(final AnyMatrix m,
                                            final int startRow, final int endRow,
                                            final int startColumn, final int endColumn) {
         checkRowIndex(m, startRow);
         checkRowIndex(m, endRow);
-        if (startRow > endRow) {
-            throw new MatrixIndexException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
-                                           startRow, endRow);
+        if (endRow < startRow) {
+            throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
+                                                endRow, startRow, false);
         }
 
         checkColumnIndex(m, startColumn);
         checkColumnIndex(m, endColumn);
-        if (startColumn > endColumn) {
-            throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN,
-                                           startColumn, endColumn);
+        if (endColumn < startColumn) {
+            throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN,
+                                                endColumn, startColumn, false);
         }
 
 
@@ -583,19 +425,29 @@ public class MatrixUtils {
      * Check if submatrix ranges indices are valid.
      * Rows and columns are indicated counting from 0 to n-1.
      *
-     * @param m matrix containing the submatrix
+     * @param m Matrix.
      * @param selectedRows Array of row indices.
      * @param selectedColumns Array of column indices.
-     * @exception MatrixIndexException if row or column selections are not valid
+     * @throws NullArgumentException if {@code selectedRows} or
+     * {@code selectedColumns} are {@code null}.
+     * @throws ZeroException if the row or column selections are empty (zero
+     * length).
+     * @throws OutOfRangeException if row or column selections are not valid.
      */
     public static void checkSubMatrixIndex(final AnyMatrix m,
-                                           final int[] selectedRows, final int[] selectedColumns)
-        throws MatrixIndexException {
-        if (selectedRows.length * selectedColumns.length == 0) {
-            if (selectedRows.length == 0) {
-                throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
-            }
-            throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
+                                           final int[] selectedRows,
+                                           final int[] selectedColumns) {
+        if (selectedRows == null) {
+            throw new NullArgumentException();
+        }
+        if (selectedColumns == null) {
+            throw new NullArgumentException();
+        }
+        if (selectedRows.length == 0) {
+            throw new ZeroException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
+        }
+        if (selectedColumns.length == 0) {
+            throw new ZeroException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
         }
 
         for (final int row : selectedRows) {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealMatrix.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealMatrix.java Wed Oct 27 13:16:57 2010
@@ -27,38 +27,37 @@ import org.apache.commons.math.util.Open
  * @version $Revision$ $Date$
  * @since 2.0
  */
-public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealMatrix, Serializable {
-
+public class OpenMapRealMatrix extends AbstractRealMatrix
+    implements SparseRealMatrix, Serializable {
     /** Serializable version identifier. */
     private static final long serialVersionUID = -5962461716457143437L;
-
     /** Number of rows of the matrix. */
     private final int rows;
-
     /** Number of columns of the matrix. */
     private final int columns;
-
     /** Storage for (sparse) matrix elements. */
     private final OpenIntToDoubleHashMap entries;
 
     /**
      * Build a sparse matrix with the supplied row and column dimensions.
-     * @param rowDimension number of rows of the matrix
-     * @param columnDimension number of columns of the matrix
+     *
+     * @param rowDimension Number of rows of the matrix.
+     * @param columnDimension Number of columns of the matrix.
      */
     public OpenMapRealMatrix(int rowDimension, int columnDimension) {
         super(rowDimension, columnDimension);
-        this.rows    = rowDimension;
+        this.rows = rowDimension;
         this.columns = columnDimension;
         this.entries = new OpenIntToDoubleHashMap(0.0);
     }
 
     /**
      * Build a matrix by copying another one.
-     * @param matrix matrix to copy
+     *
+     * @param matrix matrix to copy.
      */
     public OpenMapRealMatrix(OpenMapRealMatrix matrix) {
-        this.rows    = matrix.rows;
+        this.rows = matrix.rows;
         this.columns = matrix.columns;
         this.entries = new OpenIntToDoubleHashMap(matrix.entries);
     }
@@ -71,8 +70,7 @@ public class OpenMapRealMatrix extends A
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealMatrix createMatrix(int rowDimension, int columnDimension)
-            throws IllegalArgumentException {
+    public OpenMapRealMatrix createMatrix(int rowDimension, int columnDimension) {
         return new OpenMapRealMatrix(rowDimension, columnDimension);
     }
 
@@ -82,25 +80,15 @@ public class OpenMapRealMatrix extends A
         return columns;
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public OpenMapRealMatrix add(final RealMatrix m)
-        throws IllegalArgumentException {
-        try {
-            return add((OpenMapRealMatrix) m);
-        } catch (ClassCastException cce) {
-            return (OpenMapRealMatrix) super.add(m);
-        }
-    }
-
     /**
-     * Compute the sum of this and <code>m</code>.
+     * Compute the sum of this matrix and {@code m}.
      *
-     * @param m    matrix to be added
-     * @return     this + m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be added.
+     * @return {@code this} + {@code m}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
-    public OpenMapRealMatrix add(OpenMapRealMatrix m) throws IllegalArgumentException {
+    public OpenMapRealMatrix add(OpenMapRealMatrix m) {
 
         // safety check
         MatrixUtils.checkAdditionCompatible(this, m);
@@ -129,15 +117,15 @@ public class OpenMapRealMatrix extends A
     }
 
     /**
-     * Compute this minus <code>m</code>.
+     * Subtract {@code m} from this matrix.
      *
-     * @param m    matrix to be subtracted
-     * @return     this - m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be subtracted.
+     * @return {@code this} - {@code m}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
-    public OpenMapRealMatrix subtract(OpenMapRealMatrix m) throws IllegalArgumentException {
-
-        // safety check
+    public OpenMapRealMatrix subtract(OpenMapRealMatrix m) {
+        // Safety check.
         MatrixUtils.checkAdditionCompatible(this, m);
 
         final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
@@ -149,7 +137,6 @@ public class OpenMapRealMatrix extends A
         }
 
         return out;
-
     }
 
     /** {@inheritDoc} */
@@ -177,21 +164,20 @@ public class OpenMapRealMatrix extends A
             }
 
             return out;
-
         }
     }
 
     /**
-     * Returns the result of postmultiplying this by m.
+     * Postmultiply this matrix by {@code m}.
      *
-     * @param m    matrix to postmultiply by
-     * @return     this * m
-     * @throws     IllegalArgumentException
-     *             if columnDimension(this) != rowDimension(m)
+     * @param m Matrix to postmultiply by.
+     * @return {@code this} * {@code m}.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if the number of rows of {@code m} differ from the number of columns
+     * of this matrix.
      */
-    public OpenMapRealMatrix multiply(OpenMapRealMatrix m) throws IllegalArgumentException {
-
-        // safety check
+    public OpenMapRealMatrix multiply(OpenMapRealMatrix m) {
+        // Safety check.
         MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final int outCols = m.getColumnDimension();
@@ -218,12 +204,11 @@ public class OpenMapRealMatrix extends A
         }
 
         return out;
-
     }
 
     /** {@inheritDoc} */
     @Override
-    public double getEntry(int row, int column) throws MatrixIndexException {
+    public double getEntry(int row, int column) {
         MatrixUtils.checkRowIndex(this, row);
         MatrixUtils.checkColumnIndex(this, column);
         return entries.get(computeKey(row, column));
@@ -237,8 +222,7 @@ public class OpenMapRealMatrix extends A
 
     /** {@inheritDoc} */
     @Override
-    public void setEntry(int row, int column, double value)
-            throws MatrixIndexException {
+    public void setEntry(int row, int column, double value) {
         MatrixUtils.checkRowIndex(this, row);
         MatrixUtils.checkColumnIndex(this, column);
         if (value == 0.0) {
@@ -250,8 +234,7 @@ public class OpenMapRealMatrix extends A
 
     /** {@inheritDoc} */
     @Override
-    public void addToEntry(int row, int column, double increment)
-            throws MatrixIndexException {
+    public void addToEntry(int row, int column, double increment) {
         MatrixUtils.checkRowIndex(this, row);
         MatrixUtils.checkColumnIndex(this, column);
         final int key = computeKey(row, column);
@@ -265,8 +248,7 @@ public class OpenMapRealMatrix extends A
 
     /** {@inheritDoc} */
     @Override
-    public void multiplyEntry(int row, int column, double factor)
-            throws MatrixIndexException {
+    public void multiplyEntry(int row, int column, double factor) {
         MatrixUtils.checkRowIndex(this, row);
         MatrixUtils.checkColumnIndex(this, column);
         final int key = computeKey(row, column);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java Wed Oct 27 13:16:57 2010
@@ -18,59 +18,58 @@ package org.apache.commons.math.linear;
 
 import java.io.Serializable;
 
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.MathArithmeticException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.util.OpenIntToDoubleHashMap;
 import org.apache.commons.math.util.OpenIntToDoubleHashMap.Iterator;
 import org.apache.commons.math.util.FastMath;
 
 /**
- * This class implements the {@link RealVector} interface with a {@link OpenIntToDoubleHashMap} backing store.
+ * This class implements the {@link RealVector} interface with a
+ * {@link OpenIntToDoubleHashMap} backing store.
  * @version $Revision$ $Date$
  * @since 2.0
 */
-public class OpenMapRealVector extends AbstractRealVector implements SparseRealVector, Serializable {
-
+public class OpenMapRealVector extends AbstractRealVector
+    implements SparseRealVector, Serializable {
     /** Default Tolerance for having a value considered zero. */
     public static final double DEFAULT_ZERO_TOLERANCE = 1.0e-12;
-
     /** Serializable version identifier. */
     private static final long serialVersionUID = 8772222695580707260L;
-
     /** Entries of the vector. */
     private final OpenIntToDoubleHashMap entries;
-
     /** Dimension of the vector. */
     private final int virtualSize;
-
     /** Tolerance for having a value considered zero. */
     private final double epsilon;
 
     /**
      * Build a 0-length vector.
-     * <p>Zero-length vectors may be used to initialized construction of vectors
+     * Zero-length vectors may be used to initialized construction of vectors
      * by data gathering. We start with zero-length and use either the {@link
      * #OpenMapRealVector(OpenMapRealVector, int)} constructor
-     * or one of the <code>append</code> method ({@link #append(double)}, {@link
+     * or one of the {@code append} method ({@link #append(double)}, {@link
      * #append(double[])}, {@link #append(RealVector)}) to gather data
-     * into this vector.</p>
+     * into this vector.
      */
     public OpenMapRealVector() {
         this(0, DEFAULT_ZERO_TOLERANCE);
     }
 
     /**
-     * Construct a (dimension)-length vector of zeros.
-     * @param dimension size of the vector
+     * Construct a vector of zeroes.
+     *
+     * @param dimension Size of the vector.
      */
     public OpenMapRealVector(int dimension) {
         this(dimension, DEFAULT_ZERO_TOLERANCE);
     }
 
     /**
-     * Construct a (dimension)-length vector of zeros, specifying zero tolerance.
-     * @param dimension Size of the vector
-     * @param epsilon The tolerance for having a value considered zero
+     * Construct a vector of zeroes, specifying zero tolerance.
+     *
+     * @param dimension Size of the vector.
+     * @param epsilon Tolerance below which a value considered zero.
      */
     public OpenMapRealVector(int dimension, double epsilon) {
         virtualSize = dimension;
@@ -80,8 +79,9 @@ public class OpenMapRealVector extends A
 
     /**
      * Build a resized vector, for use with append.
-     * @param v The original vector
-     * @param resize The amount to resize it
+     *
+     * @param v Original vector.
+     * @param resize Amount to add.
      */
     protected OpenMapRealVector(OpenMapRealVector v, int resize) {
         virtualSize = v.getDimension() + resize;
@@ -91,18 +91,21 @@ public class OpenMapRealVector extends A
 
     /**
      * Build a vector with known the sparseness (for advanced use only).
-     * @param dimension The size of the vector
-     * @param expectedSize The expected number of non-zero entries
+     *
+     * @param dimension Size of the vector.
+     * @param expectedSize The expected number of non-zero entries.
      */
     public OpenMapRealVector(int dimension, int expectedSize) {
         this(dimension, expectedSize, DEFAULT_ZERO_TOLERANCE);
     }
 
     /**
-     * Build a vector with known the sparseness and zero tolerance setting (for advanced use only).
-     * @param dimension The size of the vector
-     * @param expectedSize The expected number of non-zero entries
-     * @param epsilon The tolerance for having a value considered zero
+     * Build a vector with known the sparseness and zero tolerance
+     * setting (for advanced use only).
+     *
+     * @param dimension Size of the vector.
+     * @param expectedSize Expected number of non-zero entries.
+     * @param epsilon Tolerance below which a value is considered zero.
      */
     public OpenMapRealVector(int dimension, int expectedSize, double epsilon) {
         virtualSize = dimension;
@@ -111,19 +114,21 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     * Create from a double array.
-     * Only non-zero entries will be stored
-     * @param values The set of values to create from
+     * Create from an array.
+     * Only non-zero entries will be stored.
+     *
+     * @param values Set of values to create from.
      */
     public OpenMapRealVector(double[] values) {
         this(values, DEFAULT_ZERO_TOLERANCE);
     }
 
     /**
-     * Create from a double array, specifying zero tolerance.
-     * Only non-zero entries will be stored
-     * @param values The set of values to create from
-     * @param epsilon The tolerance for having a value considered zero
+     * Create from an array, specifying zero tolerance.
+     * Only non-zero entries will be stored.
+     *
+     * @param values Set of values to create from.
+     * @param epsilon Tolerance below which a value is considered zero.
      */
     public OpenMapRealVector(double[] values, double epsilon) {
         virtualSize = values.length;
@@ -138,8 +143,9 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     * Create from a Double array.
-     * Only non-zero entries will be stored
+     * Create from an array.
+     * Only non-zero entries will be stored.
+     *
      * @param values The set of values to create from
      */
     public OpenMapRealVector(Double[] values) {
@@ -147,10 +153,11 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     * Create from a Double array.
-     * Only non-zero entries will be stored
-     * @param values The set of values to create from
-     * @param epsilon The tolerance for having a value considered zero
+     * Create from an array.
+     * Only non-zero entries will be stored.
+     *
+     * @param values Set of values to create from.
+     * @param epsilon Tolerance below which a value is considered zero.
      */
     public OpenMapRealVector(Double[] values, double epsilon) {
         virtualSize = values.length;
@@ -166,7 +173,8 @@ public class OpenMapRealVector extends A
 
     /**
      * Copy constructor.
-     * @param v The instance to copy from
+     *
+     * @param v Instance to copy from.
      */
     public OpenMapRealVector(OpenMapRealVector v) {
         virtualSize = v.getDimension();
@@ -176,7 +184,8 @@ public class OpenMapRealVector extends A
 
     /**
      * Generic copy constructor.
-     * @param v The instance to copy from
+     *
+     * @param v Instance to copy from.
      */
     public OpenMapRealVector(RealVector v) {
         virtualSize = v.getDimension();
@@ -192,7 +201,8 @@ public class OpenMapRealVector extends A
 
     /**
      * Get the entries of this instance.
-     * @return entries of this instance
+     *
+     * @return the entries of this instance.
      */
     private OpenIntToDoubleHashMap getEntries() {
         return entries;
@@ -200,8 +210,10 @@ public class OpenMapRealVector extends A
 
     /**
      * Determine if this value is within epsilon of zero.
-     * @param value The value to test
-     * @return <code>true</code> if this value is within epsilon to zero, <code>false</code> otherwise
+     *
+     * @param value Value to test
+     * @return {@code true} if this value is within epsilon to zero,
+     * {@code false} otherwise.
      * @since 2.1
      */
     protected boolean isDefaultValue(double value) {
@@ -210,7 +222,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public RealVector add(RealVector v) throws IllegalArgumentException {
+        public RealVector add(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return add((OpenMapRealVector) v);
@@ -220,12 +232,15 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     * Optimized method to add two OpenMapRealVectors.  Copies the larger vector, iterates over the smaller.
-     * @param v Vector to add with
-     * @return The sum of <code>this</code> with <code>v</code>
-     * @throws IllegalArgumentException If the dimensions don't match
+     * Optimized method to add two OpenMapRealVectors.
+     * It copies the larger vector, then iterates over the smaller.
+     *
+     * @param v Vector to add.
+     * @return the sum of {@code this} and {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the dimensions do not match.
      */
-    public OpenMapRealVector add(OpenMapRealVector v) throws IllegalArgumentException{
+    public OpenMapRealVector add(OpenMapRealVector v) {
         checkVectorDimensions(v.getDimension());
         boolean copyThis = entries.size() > v.entries.size();
         OpenMapRealVector res = copyThis ? this.copy() : v.copy();
@@ -246,7 +261,7 @@ public class OpenMapRealVector extends A
     /**
      * Optimized method to append a OpenMapRealVector.
      * @param v vector to append
-     * @return The result of appending <code>v</code> to self
+     * @return The result of appending {@code v} to self
      */
     public OpenMapRealVector append(OpenMapRealVector v) {
         OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension());
@@ -293,12 +308,14 @@ public class OpenMapRealVector extends A
 
     /**
      * Optimized method to compute the dot product with an OpenMapRealVector.
-     * Iterates over the smaller of the two.
-     * @param v The vector to compute the dot product with
-     * @return The dot product of <code>this</code> and <code>v</code>
-     * @throws IllegalArgumentException If the dimensions don't match
+     * It iterates over the smallest of the two.
+     *
+     * @param v Cector to compute the dot product with.
+     * @return the dot product of {@code this} and {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the dimensions do not match.
      */
-    public double dotProduct(OpenMapRealVector v) throws IllegalArgumentException {
+    public double dotProduct(OpenMapRealVector v) {
         checkVectorDimensions(v.getDimension());
         boolean thisIsSmaller  = entries.size() < v.entries.size();
         Iterator iter = thisIsSmaller  ? entries.iterator() : v.entries.iterator();
@@ -313,7 +330,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double dotProduct(RealVector v) throws IllegalArgumentException {
+    public double dotProduct(RealVector v) {
         if(v instanceof OpenMapRealVector) {
             return dotProduct((OpenMapRealVector)v);
         } else {
@@ -322,7 +339,7 @@ public class OpenMapRealVector extends A
     }
 
     /** {@inheritDoc} */
-    public OpenMapRealVector ebeDivide(RealVector v) throws IllegalArgumentException {
+    public OpenMapRealVector ebeDivide(RealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = new OpenMapRealVector(this);
         Iterator iter = res.entries.iterator();
@@ -335,7 +352,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector ebeDivide(double[] v) throws IllegalArgumentException {
+    public OpenMapRealVector ebeDivide(double[] v) {
         checkVectorDimensions(v.length);
         OpenMapRealVector res = new OpenMapRealVector(this);
         Iterator iter = res.entries.iterator();
@@ -347,7 +364,7 @@ public class OpenMapRealVector extends A
     }
 
     /** {@inheritDoc} */
-    public OpenMapRealVector ebeMultiply(RealVector v) throws IllegalArgumentException {
+    public OpenMapRealVector ebeMultiply(RealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = new OpenMapRealVector(this);
         Iterator iter = res.entries.iterator();
@@ -360,7 +377,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector ebeMultiply(double[] v) throws IllegalArgumentException {
+    public OpenMapRealVector ebeMultiply(double[] v) {
         checkVectorDimensions(v.length);
         OpenMapRealVector res = new OpenMapRealVector(this);
         Iterator iter = res.entries.iterator();
@@ -372,7 +389,7 @@ public class OpenMapRealVector extends A
     }
 
     /** {@inheritDoc} */
-    public OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException {
+    public OpenMapRealVector getSubVector(int index, int n) {
         checkIndex(index);
         checkIndex(index + n - 1);
         OpenMapRealVector res = new OpenMapRealVector(n);
@@ -407,11 +424,13 @@ public class OpenMapRealVector extends A
 
     /**
      * Optimized method to compute distance.
-     * @param v The vector to compute distance to
-     * @return The distance from <code>this</code> and <code>v</code>
-     * @throws IllegalArgumentException If the dimensions don't match
+     *
+     * @param v Vector to compute distance to.
+     * @return the distance from {@code this} and {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the dimensions do not match.
      */
-    public double getDistance(OpenMapRealVector v) throws IllegalArgumentException {
+    public double getDistance(OpenMapRealVector v) {
         Iterator iter = entries.iterator();
         double res = 0;
         while (iter.hasNext()) {
@@ -435,7 +454,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getDistance(RealVector v) throws IllegalArgumentException {
+    public double getDistance(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getDistance((OpenMapRealVector) v);
@@ -445,7 +464,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getDistance(double[] v) throws IllegalArgumentException {
+    public double getDistance(double[] v) {
         checkVectorDimensions(v.length);
         double res = 0;
         for (int i = 0; i < v.length; i++) {
@@ -456,18 +475,19 @@ public class OpenMapRealVector extends A
     }
 
     /** {@inheritDoc} */
-    public double getEntry(int index) throws MatrixIndexException {
+    public double getEntry(int index) {
         checkIndex(index);
         return entries.get(index);
     }
 
     /**
      * Distance between two vectors.
-     * <p>This method computes the distance consistent with
+     * This method computes the distance consistent with
      * L<sub>1</sub> norm, i.e. the sum of the absolute values of
-     * elements differences.</p>
-     * @param v vector to which distance is requested
-     * @return distance between two vectors.
+     * elements differences.
+     *
+     * @param v Vector to which distance is requested.
+     * @return distance between this vector and {@code v}.
      */
     public double getL1Distance(OpenMapRealVector v) {
         double max = 0;
@@ -491,7 +511,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getL1Distance(RealVector v) throws IllegalArgumentException {
+    public double getL1Distance(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getL1Distance((OpenMapRealVector) v);
@@ -501,7 +521,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getL1Distance(double[] v) throws IllegalArgumentException {
+    public double getL1Distance(double[] v) {
         checkVectorDimensions(v.length);
         double max = 0;
         for (int i = 0; i < v.length; i++) {
@@ -513,8 +533,9 @@ public class OpenMapRealVector extends A
 
     /**
      * Optimized method to compute LInfDistance.
-     * @param v The vector to compute from
-     * @return the LInfDistance
+     *
+     * @param v Vector to compute distance from.
+     * @return the LInfDistance.
      */
     private double getLInfDistance(OpenMapRealVector v) {
         double max = 0;
@@ -541,7 +562,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getLInfDistance(RealVector v) throws IllegalArgumentException {
+    public double getLInfDistance(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getLInfDistance((OpenMapRealVector) v);
@@ -551,7 +572,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public double getLInfDistance(double[] v) throws IllegalArgumentException {
+    public double getLInfDistance(double[] v) {
         checkVectorDimensions(v.length);
         double max = 0;
         for (int i = 0; i < v.length; i++) {
@@ -609,7 +630,7 @@ public class OpenMapRealVector extends A
 
      /** {@inheritDoc} */
     @Override
-    public RealMatrix outerProduct(double[] v) throws IllegalArgumentException {
+    public RealMatrix outerProduct(double[] v) {
         checkVectorDimensions(v.length);
         RealMatrix res = new OpenMapRealMatrix(virtualSize, virtualSize);
         Iterator iter = entries.iterator();
@@ -625,20 +646,20 @@ public class OpenMapRealVector extends A
     }
 
     /** {@inheritDoc} */
-    public RealVector projection(RealVector v) throws IllegalArgumentException {
+    public RealVector projection(RealVector v) {
         checkVectorDimensions(v.getDimension());
         return v.mapMultiply(dotProduct(v) / v.dotProduct(v));
     }
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector projection(double[] v) throws IllegalArgumentException {
+    public OpenMapRealVector projection(double[] v) {
         checkVectorDimensions(v.length);
         return (OpenMapRealVector) projection(new OpenMapRealVector(v));
     }
 
     /** {@inheritDoc} */
-    public void setEntry(int index, double value) throws MatrixIndexException {
+    public void setEntry(int index, double value) {
         checkIndex(index);
         if (!isDefaultValue(value)) {
             entries.put(index, value);
@@ -649,7 +670,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public void setSubVector(int index, RealVector v) throws MatrixIndexException {
+    public void setSubVector(int index, RealVector v) {
         checkIndex(index);
         checkIndex(index + v.getDimension() - 1);
         setSubVector(index, v.getData());
@@ -657,7 +678,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public void setSubVector(int index, double[] v) throws MatrixIndexException {
+    public void setSubVector(int index, double[] v) {
         checkIndex(index);
         checkIndex(index + v.length - 1);
         for (int i = 0; i < v.length; i++) {
@@ -675,11 +696,13 @@ public class OpenMapRealVector extends A
 
     /**
      * Optimized method to subtract OpenMapRealVectors.
-     * @param v The vector to subtract from <code>this</code>
-     * @return The difference of <code>this</code> and <code>v</code>
-     * @throws IllegalArgumentException If the dimensions don't match
+     *
+     * @param v Vector to subtract from {@code this}.
+     * @return the difference of {@code this} and {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the dimensions do not match.
      */
-    public OpenMapRealVector subtract(OpenMapRealVector v) throws IllegalArgumentException{
+    public OpenMapRealVector subtract(OpenMapRealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = copy();
         Iterator iter = v.getEntries().iterator();
@@ -697,7 +720,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector subtract(RealVector v) throws IllegalArgumentException {
+    public OpenMapRealVector subtract(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return subtract((OpenMapRealVector) v);
@@ -707,7 +730,7 @@ public class OpenMapRealVector extends A
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector subtract(double[] v) throws IllegalArgumentException {
+    public OpenMapRealVector subtract(double[] v) {
         checkVectorDimensions(v.length);
         OpenMapRealVector res = new OpenMapRealVector(this);
         for (int i = 0; i < v.length; i++) {
@@ -734,27 +757,26 @@ public class OpenMapRealVector extends A
     public void unitize() {
         double norm = getNorm();
         if (isDefaultValue(norm)) {
-            throw  MathRuntimeException.createArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
+            throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
         }
         Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
             entries.put(iter.key(), iter.value() / norm);
         }
-
     }
 
-
     /** {@inheritDoc} */
     @Override
     public double[] toArray() {
         return getData();
     }
 
-    /** {@inheritDoc}
-     * <p> Implementation Note: This works on exact values, and as a result
+    /**
+     * {@inheritDoc}
+     * Implementation Note: This works on exact values, and as a result
      * it is possible for {@code a.subtract(b)} to be the zero vector, while
-     * {@code a.hashCode() != b.hashCode()}.</p>
+     * {@code a.hashCode() != b.hashCode()}.
      */
     @Override
     public int hashCode() {
@@ -774,10 +796,10 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     * <p> Implementation Note: This performs an exact comparison, and as a result
-     * it is possible for {@code a.subtract(b}} to be the zero vector, while
-     * {@code  a.equals(b) == false}.</p>
      * {@inheritDoc}
+     * Implementation Note: This performs an exact comparison, and as a result
+     * it is possible for {@code a.subtract(b}} to be the zero vector, while
+     * {@code  a.equals(b) == false}.
      */
     @Override
     public boolean equals(Object obj) {
@@ -817,18 +839,8 @@ public class OpenMapRealVector extends A
     /**
      *
      * @return the percentage of none zero elements as a decimal percent.
-     * @deprecated Use the correctly spelled {@link #getSparsity()}
      */
-    @Deprecated
-    public double getSparcity() {
-        return getSparsity();
-    }
-
-    /**
-    *
-    * @return the percentage of none zero elements as a decimal percent.
-    */
-   public double getSparsity() {
+    public double getSparsity() {
         return (double)entries.size()/(double)getDimension();
     }
 
@@ -839,17 +851,18 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     *  Implementation of <code>Entry</code> optimized for OpenMap.
-     * <p>This implementation does not allow arbitrary calls to <code>setIndex</code>
-     * since the order that entries are returned is undefined.
+     * Implementation of {@code Entry} optimized for OpenMap.
+     * This implementation does not allow arbitrary calls to {@code setIndex}
+     * since the order in which entries are returned is undefined.
      */
     protected class OpenMapEntry extends Entry {
-
         /** Iterator pointing to the entry. */
         private final Iterator iter;
 
-        /** Build an entry from an iterator point to an element.
-         * @param iter iterator pointing to the entry
+        /**
+         * Build an entry from an iterator point to an element.
+         *
+         * @param iter Iterator pointing to the entry.
          */
         protected OpenMapEntry(Iterator iter) {
             this.iter = iter;
@@ -876,15 +889,13 @@ public class OpenMapRealVector extends A
     }
 
     /**
-     *  Iterator class to do iteration over just the non-zero elements.
-     *  <p>This implementation is fail-fast, so cannot be used to modify any zero element.
-     *
+     * Iterator class to do iteration over just the non-zero elements.
+     * This implementation is fail-fast, so cannot be used to modify
+     * any zero element.
      */
     protected class OpenMapSparseIterator implements java.util.Iterator<Entry> {
-
         /** Underlying iterator. */
         private final Iterator iter;
-
         /** Current entry. */
         private final Entry current;
 
@@ -908,7 +919,6 @@ public class OpenMapRealVector extends A
         /** {@inheritDoc} */
         public void remove() {
             throw new UnsupportedOperationException("Not supported");
-       }
-
+        }
     }
 }



Mime
View raw message