commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r710168 - in /commons/proper/math/branches/MATH_2_0/src: java/org/apache/commons/math/ java/org/apache/commons/math/linear/ test/org/apache/commons/math/linear/
Date Mon, 03 Nov 2008 21:32:27 GMT
Author: luc
Date: Mon Nov  3 13:32:26 2008
New Revision: 710168

URL: http://svn.apache.org/viewvc?rev=710168&view=rev
Log:
improved error handling in linear package with finer grained exceptions

Added:
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java   (with props)
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java   (with props)
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java   (with props)
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java   (with props)
Modified:
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MessagesResources_fr.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/BigMatrixImpl.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/InvalidMatrixException.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/MatrixIndexException.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealVectorImpl.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java

Added: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java?rev=710168&view=auto
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java (added)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java Mon Nov  3 13:32:26 2008
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+* Base class for commons-math unchecked exceptions.
+* 
+* @version $Revision$ $Date$
+* @since 2.0
+*/
+public class MathRuntimeException extends RuntimeException {
+    
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -2880601850253924272L;
+
+    /** Cache for resources bundle. */
+    private static ResourceBundle cachedResources = null;
+ 
+    /**
+     * Pattern used to build the message.
+     */
+    private final String pattern;
+
+    /**
+     * Arguments used to build the message.
+     */
+    private final Object[] arguments;
+
+    /**
+     * Translate a string to a given locale.
+     * @param s string to translate
+     * @param locale locale into which to translate the string
+     * @return translated string or original string
+     * for unsupported locales or unknown strings
+     */
+    private static String translate(final String s, final Locale locale) {
+        try {
+            if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale))) {
+                // caching the resource bundle
+                cachedResources =
+                    ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
+            }
+
+            if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
+                // the value of the resource is the translated string
+                return cachedResources.getString(s);
+            }
+            
+        } catch (MissingResourceException mre) {
+            // do nothing here
+        }
+
+        // the locale is not supported or the resource is unknown
+        // don't translate and fall back to using the string as is
+        return s;
+
+    }
+
+    /**
+     * Builds a message string by from a pattern and its arguments.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param locale Locale in which the message should be translated
+     * @return a message string
+     */
+    private static String buildMessage(final String pattern, final Object[] arguments,
+                                       final Locale locale) {
+        return new MessageFormat(translate(pattern, locale), locale).format(arguments);        
+    }
+
+    /**
+     * Constructs a new <code>MathRuntimeException</code> with no
+     * detail message.
+     */
+    public MathRuntimeException() {
+        super();
+        this.pattern   = null;
+        this.arguments = new Object[0];
+    }
+    
+    /**
+     * Constructs a new <code>MathRuntimeException</code> with specified
+     * formatted detail message.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     */
+    public MathRuntimeException(final String pattern, final Object[] arguments) {
+      super(buildMessage(pattern, arguments, Locale.US));
+      this.pattern   = pattern;
+      this.arguments = (Object[]) arguments.clone();
+    }
+
+    /**
+     * Constructs a new <code>MathRuntimeException</code> with specified
+     * nested <code>Throwable</code> root cause.
+     *
+     * @param rootCause  the exception or error that caused this exception
+     *                   to be thrown.
+     */
+    public MathRuntimeException(final Throwable rootCause) {
+        super(rootCause);
+        this.pattern   = getMessage();
+        this.arguments = new Object[0];
+    }
+    
+    /**
+     * Constructs a new <code>MathRuntimeException</code> with specified
+     * formatted detail message and nested <code>Throwable</code> root cause.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param rootCause the exception or error that caused this exception
+     * to be thrown.
+     */
+    public MathRuntimeException(final String pattern, final Object[] arguments,
+                                final Throwable rootCause) {
+      super(buildMessage(pattern, arguments, Locale.US), rootCause);
+      this.pattern   = pattern;
+      this.arguments = (Object[]) arguments.clone();
+    }
+
+    /** Gets the pattern used to build the message of this throwable.
+     *
+     * @return the pattern used to build the message of this throwable
+     */
+    public String getPattern() {
+        return pattern;
+    }
+
+    /** Gets the arguments used to build the message of this throwable.
+     *
+     * @return the arguments used to build the message of this throwable
+     */
+    public Object[] getArguments() {
+        return (Object[]) arguments.clone();
+    }
+
+    /** Gets the message in a specified locale.
+     *
+     * @param locale Locale in which the message should be translated
+     * 
+     * @return localized message
+     */
+    public String getMessage(final Locale locale) {
+        return (pattern == null) ? null : buildMessage(pattern, arguments, locale);
+    }
+
+    /** {@inheritDoc} */
+    public String getLocalizedMessage() {
+        return getMessage(Locale.getDefault());
+    }
+
+    /**
+     * Prints the stack trace of this exception to the standard error stream.
+     */
+    public void printStackTrace() {
+        printStackTrace(System.err);
+    }
+    
+    /**
+     * Prints the stack trace of this exception to the specified stream.
+     *
+     * @param out  the <code>PrintStream</code> to use for output
+     */
+    public void printStackTrace(final PrintStream out) {
+        synchronized (out) {
+            PrintWriter pw = new PrintWriter(out, false);
+            printStackTrace(pw);
+            // Flush the PrintWriter before it's GC'ed.
+            pw.flush();
+        }
+    }
+    
+}

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MessagesResources_fr.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MessagesResources_fr.java Mon Nov  3 13:32:26 2008
@@ -133,7 +133,7 @@
     { "unable to orthogonalize matrix in {0} iterations",
       "impossible de rendre la matrice orthogonale en {0} it\u00e9rations" },
 
-    // org.apache.commons.math.ode.AdaptiveStepsizeIntegrator
+    // org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator
     { "minimal step size ({0}) reached, integration needs {1}",
       "pas minimal ({0}) atteint, l''int\u00e9gration n\u00e9cessite {1}" },
     { "dimensions mismatch: state vector has dimension {0}," +
@@ -145,8 +145,8 @@
       "incompatibilit\u00e9 de dimensions entre le vecteur d''\u00e9tat ({0})," +
       " et le vecteur de tol\u00e9rance relative ({1})" },
 
-    // org.apache.commons.math.ode.AdaptiveStepsizeIntegrator,
-    // org.apache.commons.math.ode.RungeKuttaIntegrator
+    // org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator,
+    // org.apache.commons.math.ode.nonstiff.RungeKuttaIntegrator
     { "dimensions mismatch: ODE problem has dimension {0}," +
       " initial state vector has dimension {1}",
       "incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0})," +
@@ -158,9 +158,55 @@
     { "too small integration interval: length = {0}",
       "intervalle d''int\u00e9gration trop petit : {0}" },
 
+    // org.apache.commons.math.ode.ContinuousOutputModel
+    // org.apache.commons.math.optimization.DirectSearchOptimizer
+    { "unexpected exception caught",
+      "exception inattendue lev\u00e9e" },
+
     // org.apache.commons.math.optimization.DirectSearchOptimizer
     { "none of the {0} start points lead to convergence",
-      "aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence"  }
+      "aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence"  },
+
+    // org.apache.commons.math.random.EmpiricalDistributionImpl
+    { "no bin selected",
+      "aucun compartiment s\u00e9lectionn\u00e9" },
+
+    // org.apache.commons.math.linear.EigenDecompositionImpl
+    { "negative element on decomposed tridiagonal of {0}x{1} matrix",
+      "\u00e9l\u00e9ment n\u00e9gatif dans la d\u00e9composition tri-diagonale d''une matrice {0}x{1}" },
+
+    // org.apache.commons.math.linear.NonSquareMatrixException
+    { "a {0}x{1} matrix was provided instead of a square matrix",
+      "une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e" },
+
+    // org.apache.commons.math.linear.SingularMatrixException
+    { "matrix is singular",
+      "matrice singuli\u00e8re" },
+
+    // org.apache.commons.math.linear.RankDeficientMatrixException
+    { "matrix is rank-deficient",
+      "le rang de la matrice est inf\u00e9rieur \u00e0 sa dimension" },
+
+    // org.apache.commons.math.linear.RealVectorImpl
+    { "index {0} out of allowed range [{1}, {2}]",
+      "index {0} hors de la plage autoris\u00e9e [{1}, {2}]" },
+
+    // org.apache.commons.math.linear.BigMatrixImpl
+    // org.apache.commons.math.linear.RealMatrixImpl
+    { "row index {0} out of allowed range [{1}, {2}]",
+      "index de ligne {0} hors de la plage autoris\u00e9e [{1}, {2}]" },
+    { "column index {0} out of allowed range [{1}, {2}]",
+      "index de colonne {0} hors de la plage autoris\u00e9e [{1}, {2}]" },
+    { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
+      "pas d''entr\u00e9e aux indices ({0}, {1}) dans une matrice {2}x{3}" },
+    { "initial row {0} after final row {1}",
+      "ligne initiale {0} apr\u00e8s la ligne finale {1}" },
+    { "initial column {0} after final column {1}",
+      "colonne initiale {0} apr\u00e8s la colonne finale {1}" },
+    { "empty selected row index array",
+      "tableau des indices de lignes s\u00e9lectionn\u00e9es vide" },
+    { "empty selected column index array",
+      "tableau des indices de colonnes s\u00e9lectionn\u00e9es vide" }
 
   };
 

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/BigMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/BigMatrixImpl.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/BigMatrixImpl.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/BigMatrixImpl.java Mon Nov  3 13:32:26 2008
@@ -579,20 +579,31 @@
     public BigMatrix getSubMatrix(int startRow, int endRow,
                                   int startColumn, int endColumn)
         throws MatrixIndexException {
-        if (startRow < 0 || startRow > endRow || endRow > data.length ||
-                startColumn < 0 || startColumn > endColumn ||
-                endColumn > data[0].length ) {
-            throw new MatrixIndexException(
-            "invalid row or column index selection");
+
+        checkRowIndex(startRow);
+        checkRowIndex(endRow);
+        if (startRow > endRow) {
+            throw new MatrixIndexException("initial row {0} after final row {1}",
+                                           new Object[] { startRow, endRow });
+        }
+
+        checkColumnIndex(startColumn);
+        checkColumnIndex(endColumn);
+        if (startColumn > endColumn) {
+            throw new MatrixIndexException("initial column {0} after final column {1}",
+                                           new Object[] { startColumn, endColumn });
         }
+
         final BigDecimal[][] subMatrixData =
             new BigDecimal[endRow - startRow + 1][endColumn - startColumn + 1];
         for (int i = startRow; i <= endRow; i++) {
             System.arraycopy(data[i], startColumn,
-                    subMatrixData[i - startRow], 0,
-                    endColumn - startColumn + 1);
+                             subMatrixData[i - startRow], 0,
+                             endColumn - startColumn + 1);
         }
+
         return new BigMatrixImpl(subMatrixData, false);
+
     }
     
     /**
@@ -608,10 +619,14 @@
      */
     public BigMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
         throws MatrixIndexException {
+
         if (selectedRows.length * selectedColumns.length == 0) {
-            throw new MatrixIndexException(
-            "selected row and column index arrays must be non-empty");
+            if (selectedRows.length == 0) {
+                throw new MatrixIndexException("empty selected row index array", new Object[0]);
+            }
+            throw new MatrixIndexException("empty selected column index array", new Object[0]);
         }
+
         final BigDecimal[][] subMatrixData =
             new BigDecimal[selectedRows.length][selectedColumns.length];
         try  {
@@ -622,9 +637,15 @@
                     subI[j] = dataSelectedI[selectedColumns[j]];
                 }
             }
-        }
-        catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException("matrix dimension mismatch");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // we redo the loop with checks enabled
+            // in order to generate an appropriate message
+            for (final int row : selectedRows) {
+                checkRowIndex(row);
+            }
+            for (final int column : selectedColumns) {
+                checkColumnIndex(column);
+            }
         }
         return new BigMatrixImpl(subMatrixData, false);
     } 
@@ -658,40 +679,41 @@
      */
     public void setSubMatrix(BigDecimal[][] subMatrix, int row, int column) 
     throws MatrixIndexException {
-        if ((row < 0) || (column < 0)){
-            throw new MatrixIndexException
-            ("invalid row or column index selection");          
-        }
+
         final int nRows = subMatrix.length;
+        final int nCols = subMatrix[0].length;
+
         if (nRows == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one row."); 
+            throw new IllegalArgumentException("Matrix must have at least one row."); 
         }
-        final int nCols = subMatrix[0].length;
         if (nCols == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one column."); 
+            throw new IllegalArgumentException("Matrix must have at least one column."); 
         }
+
         for (int r = 1; r < nRows; r++) {
             if (subMatrix[r].length != nCols) {
-                throw new IllegalArgumentException(
-                "All input rows must have the same length.");
+                throw new IllegalArgumentException("All input rows must have the same length.");
             }
-        }       
+        }
+
         if (data == null) {
-            if ((row > 0)||(column > 0)) throw new MatrixIndexException
-            ("matrix must be initialized to perfom this method");
+            if ((row > 0) || (column > 0)) {
+                throw new IllegalStateException("matrix must be initialized to perform this method");
+            }
             data = new BigDecimal[nRows][nCols];
             System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);          
-        }   
-        if (((nRows + row) > this.getRowDimension()) ||
-            (nCols + column > this.getColumnDimension()))
-            throw new MatrixIndexException(
-            "invalid row or column index selection");                   
+        } else {
+            checkRowIndex(row);
+            checkColumnIndex(column);
+            checkRowIndex(nRows + row - 1);
+            checkColumnIndex(nCols + column - 1);
+        }
         for (int i = 0; i < nRows; i++) {
             System.arraycopy(subMatrix[i], 0, data[row + i], column, nCols);
         } 
+
         lu = null;
+
     }
     
     /**
@@ -703,9 +725,7 @@
      * @throws MatrixIndexException if the specified row index is invalid
      */
     public BigMatrix getRowMatrix(int row) throws MatrixIndexException {
-        if ( !isValidCoordinate( row, 0)) {
-            throw new MatrixIndexException("illegal row argument");
-        }
+        checkRowIndex(row);
         final int ncols = this.getColumnDimension();
         final BigDecimal[][] out = new BigDecimal[1][ncols]; 
         System.arraycopy(data[row], 0, out[0], 0, ncols);
@@ -721,9 +741,7 @@
      * @throws MatrixIndexException if the specified column index is invalid
      */
     public BigMatrix getColumnMatrix(int column) throws MatrixIndexException {
-        if ( !isValidCoordinate( 0, column)) {
-            throw new MatrixIndexException("illegal column argument");
-        }
+        checkColumnIndex(column);
         final int nRows = this.getRowDimension();
         final BigDecimal[][] out = new BigDecimal[nRows][1]; 
         for (int row = 0; row < nRows; row++) {
@@ -743,9 +761,7 @@
      * @throws MatrixIndexException if the specified row index is not valid
      */
     public BigDecimal[] getRow(int row) throws MatrixIndexException {
-        if ( !isValidCoordinate( row, 0 ) ) {
-            throw new MatrixIndexException("illegal row argument");
-        }
+        checkRowIndex(row);
         final int ncols = this.getColumnDimension();
         final BigDecimal[] out = new BigDecimal[ncols];
         System.arraycopy(data[row], 0, out, 0, ncols);
@@ -764,9 +780,7 @@
      * @throws MatrixIndexException if the specified row index is not valid
      */
     public double[] getRowAsDoubleArray(int row) throws MatrixIndexException {
-        if ( !isValidCoordinate( row, 0 ) ) {
-            throw new MatrixIndexException("illegal row argument");
-        }
+        checkRowIndex(row);
         final int ncols = this.getColumnDimension();
         final double[] out = new double[ncols];
         for (int i=0;i<ncols;i++) {
@@ -786,9 +800,7 @@
      * @throws MatrixIndexException if the specified column index is not valid
      */
     public BigDecimal[] getColumn(int col) throws MatrixIndexException {
-        if ( !isValidCoordinate(0, col) ) {
-            throw new MatrixIndexException("illegal column argument");
-        }
+        checkColumnIndex(col);
         final int nRows = this.getRowDimension();
         final BigDecimal[] out = new BigDecimal[nRows];
         for (int i = 0; i < nRows; i++) {
@@ -809,9 +821,7 @@
      * @throws MatrixIndexException if the specified column index is not valid
      */
     public double[] getColumnAsDoubleArray(int col) throws MatrixIndexException {
-        if ( !isValidCoordinate( 0, col ) ) {
-            throw new MatrixIndexException("illegal column argument");
-        }
+        checkColumnIndex(col);
         final int nrows = this.getRowDimension();
         final double[] out = new double[nrows];
         for (int i=0;i<nrows;i++) {
@@ -840,7 +850,11 @@
         try {
             return data[row][column];
         } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException("matrix entry does not exist");
+            throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix",
+                                           new Object[] {
+                                               row, column,
+                                               getRowDimension(), getColumnDimension()
+                                           });
         }
     }
     
@@ -900,7 +914,7 @@
      */
     public BigDecimal getDeterminant() throws InvalidMatrixException {
         if (!isSquare()) {
-            throw new InvalidMatrixException("matrix is not square");
+            throw new NonSquareMatrixException(getRowDimension(), getColumnDimension());
         }
         if (isSingular()) {   // note: this has side effect of attempting LU decomp if lu == null
             return ZERO;
@@ -1098,10 +1112,10 @@
             throw new IllegalArgumentException("Incorrect row dimension");
         }
         if (!this.isSquare()) {
-            throw new InvalidMatrixException("coefficient matrix is not square");
+            throw new NonSquareMatrixException(getRowDimension(), getColumnDimension());
         }
         if (this.isSingular()) { // side effect: compute LU decomp
-            throw new InvalidMatrixException("Matrix is singular.");
+            throw new SingularMatrixException();
         }
         
         final int nCol = this.getColumnDimension();
@@ -1171,7 +1185,7 @@
         final int nRows = this.getRowDimension();
         final int nCols = this.getColumnDimension();
         if (nRows != nCols) {
-            throw new InvalidMatrixException("LU decomposition requires that the matrix be square.");
+            throw new NonSquareMatrixException(getRowDimension(), getColumnDimension());
         }
         lu = this.getData();
         
@@ -1218,7 +1232,7 @@
             // Singularity check
             if (lu[max][col].abs().compareTo(TOO_SMALL) <= 0) {
                 lu = null;
-                throw new InvalidMatrixException("matrix is singular");
+                throw new SingularMatrixException();
             }
             
             // Pivot if necessary
@@ -1449,18 +1463,30 @@
         }
         lu = null;
     }
-    
+
     /**
-     * Tests a given coordinate as being valid or invalid
-     *
-     * @param row the row index.
-     * @param col the column index.
-     * @return true if the coordinate is with the current dimensions
+     * Check if a row index is valid.
+     * @param row row index to check
+     * @exception MatrixIndexException if index is not valid
+     */
+    private void checkRowIndex(final int row) {
+        if (row < 0 || row >= getRowDimension()) {
+            throw new MatrixIndexException("row index {0} out of allowed range [{1}, {2}]",
+                                           new Object[] { row, 0, getRowDimension() - 1});
+        }
+    }
+
+    /**
+     * Check if a column index is valid.
+     * @param column column index to check
+     * @exception MatrixIndexException if index is not valid
      */
-    private boolean isValidCoordinate(int row, int col) {
-        final int nRows = this.getRowDimension();
-        final int nCols = this.getColumnDimension();
-        return !(row < 0 || row >= nRows || col < 0 || col >= nCols);
+    private void checkColumnIndex(final int column)
+        throws MatrixIndexException {
+        if (column < 0 || column >= getColumnDimension()) {
+            throw new MatrixIndexException("column index {0} out of allowed range [{1}, {2}]",
+                                           new Object[] { column, 0, getColumnDimension() - 1});
+        }
     }
-    
+
 }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/InvalidMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/InvalidMatrixException.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/InvalidMatrixException.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/InvalidMatrixException.java Mon Nov  3 13:32:26 2008
@@ -17,30 +17,37 @@
 
 package org.apache.commons.math.linear;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /**
  * Thrown when a system attempts an operation on a matrix, and
  * that matrix does not satisfy the preconditions for the
  * aforementioned operation.
  * @version $Revision$ $Date$
  */
-public class InvalidMatrixException extends RuntimeException {
+public class InvalidMatrixException extends MathRuntimeException {
 
-    /** Serializable version identifier */
-    private static final long serialVersionUID = 5318837237354354107L;
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 1135533765052675495L;
 
     /**
-     * Default constructor.
+     * Construct an exception with the given message.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @since 2.0
      */
-    public InvalidMatrixException() {
-        this(null);
+    public InvalidMatrixException(final String pattern, final Object[] arguments) {
+        super(pattern, arguments);
     }
 
     /**
      * Construct an exception with the given message.
-     * @param message descriptive error message.
+     * @param cause the exception or error that caused this exception
+     * to be thrown.
+     * @since 2.0
      */
-    public InvalidMatrixException(String message) {
-        super(message);
+    public InvalidMatrixException(final Throwable cause) {
+        super(cause);
     }
 
 }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java Mon Nov  3 13:32:26 2008
@@ -108,7 +108,7 @@
     public void decompose(RealMatrix matrix, double singularityThreshold)
         throws InvalidMatrixException {
         if (!matrix.isSquare()) {
-            throw new InvalidMatrixException("LU decomposition requires that the matrix be square");
+            throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension());
         }
         final int m = matrix.getColumnDimension();
         lu = matrix.getData();
@@ -272,7 +272,7 @@
             throw new IllegalArgumentException("constant vector has wrong length");
         }
         if (singular) {
-            throw new InvalidMatrixException("Matrix is singular.");
+            throw new SingularMatrixException();
         }
 
         final double[] bp = new double[m];
@@ -314,7 +314,7 @@
                 throw new IllegalArgumentException("constant vector has wrong length");
             }
             if (singular) {
-                throw new InvalidMatrixException("Matrix is singular.");
+                throw new SingularMatrixException();
             }
 
             final double[] bp = new double[m];
@@ -368,7 +368,7 @@
             throw new IllegalArgumentException("Incorrect row dimension");
         }
         if (singular) {
-            throw new InvalidMatrixException("Matrix is singular.");
+            throw new SingularMatrixException();
         }
 
         final int nColB = b.getColumnDimension();

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/MatrixIndexException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/MatrixIndexException.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/MatrixIndexException.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/MatrixIndexException.java Mon Nov  3 13:32:26 2008
@@ -17,22 +17,25 @@
 
 package org.apache.commons.math.linear;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /**
- * Thrown when an operation addresses a matrix coordinate (row,col)
+ * Thrown when an operation addresses a matrix coordinate (row, col)
  * which is outside of the dimensions of a matrix.
  * @version $Revision$ $Date$
  */
-public class MatrixIndexException extends RuntimeException {
+public class MatrixIndexException extends MathRuntimeException {
 
     /** Serializable version identifier */
-    private static final long serialVersionUID = 3728473373420246054L;
+    private static final long serialVersionUID = -2382324504109300625L;
 
     /**
-     * Construct an exception with the given message and root cause.
-     * @param message descriptive error message.
+     * Constructs a new instance with specified formatted detail message.
+     * @param pattern format specifier
+     * @param arguments format arguments
      */
-    public MatrixIndexException(String message) {
-        super(message);
+    public MatrixIndexException(final String pattern, final Object[] arguments) {
+      super(pattern, arguments);
     }
 
 }

Added: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java?rev=710168&view=auto
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java (added)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java Mon Nov  3 13:32:26 2008
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.linear;
+
+/**
+ * Thrown when an operation defined only for square matrices is applied to non-square ones.
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public class NonSquareMatrixException extends InvalidMatrixException {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 8996207526636673730L;
+
+    /**
+     * Construct an exception with the given message.
+     * @param rows number of rows of the faulty matrix
+     * @param columns number of columns of the faulty matrix
+     */
+    public NonSquareMatrixException(final int rows, final int columns) {
+        super("a {0}x{1} matrix was provided instead of a square matrix",
+              new Object[] { rows, columns });
+    }
+
+}

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/NonSquareMatrixException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java Mon Nov  3 13:32:26 2008
@@ -307,7 +307,7 @@
             throw new IllegalArgumentException("Incorrect row dimension");
         }
         if (!isNonSingular()) {
-            throw new InvalidMatrixException("Matrix is rank-deficient");
+            throw new RankDeficientMatrixException();
         }
 
         final double[] x = new double[n];
@@ -381,7 +381,7 @@
             throw new IllegalArgumentException("Incorrect row dimension");
         }
         if (!isNonSingular()) {
-            throw new InvalidMatrixException("Matrix is rank-deficient");
+            throw new RankDeficientMatrixException();
         }
 
         final int cols = b.getColumnDimension();

Added: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java?rev=710168&view=auto
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java (added)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java Mon Nov  3 13:32:26 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.linear;
+
+/**
+ * Thrown when a matrix is singular.
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public class RankDeficientMatrixException extends InvalidMatrixException {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 7051890448195709736L;
+
+    /**
+     * Construct an exception with a default message.
+     */
+    public RankDeficientMatrixException() {
+        super("matrix is rank-deficient", new Object[0]);
+    }
+
+}

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealMatrixImpl.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealMatrixImpl.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealMatrixImpl.java Mon Nov  3 13:32:26 2008
@@ -382,12 +382,21 @@
     public RealMatrix getSubMatrix(int startRow, int endRow,
                                    int startColumn, int endColumn)
         throws MatrixIndexException {
-        if (startRow < 0 || startRow > endRow || endRow > data.length ||
-             startColumn < 0 || startColumn > endColumn ||
-             endColumn > data[0].length) {
-            throw new MatrixIndexException(
-                    "invalid row or column index selection");
+
+        checkRowIndex(startRow);
+        checkRowIndex(endRow);
+        if (startRow > endRow) {
+            throw new MatrixIndexException("initial row {0} after final row {1}",
+                                           new Object[] { startRow, endRow });
+        }
+
+        checkColumnIndex(startColumn);
+        checkColumnIndex(endColumn);
+        if (startColumn > endColumn) {
+            throw new MatrixIndexException("initial column {0} after final column {1}",
+                                           new Object[] { startColumn, endColumn });
         }
+
         final double[][] subMatrixData =
             new double[endRow - startRow + 1][endColumn - startColumn + 1];
         for (int i = startRow; i <= endRow; i++) {
@@ -401,10 +410,14 @@
     /** {@inheritDoc} */
     public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
         throws MatrixIndexException {
+
         if (selectedRows.length * selectedColumns.length == 0) {
-            throw new MatrixIndexException(
-                    "selected row and column index arrays must be non-empty");
+            if (selectedRows.length == 0) {
+                throw new MatrixIndexException("empty selected row index array", new Object[0]);
+            }
+            throw new MatrixIndexException("empty selected column index array", new Object[0]);
         }
+
         final double[][] subMatrixData =
             new double[selectedRows.length][selectedColumns.length];
         try  {
@@ -416,7 +429,14 @@
                 }
             }
         } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException("matrix dimension mismatch");
+            // we redo the loop with checks enabled
+            // in order to generate an appropriate message
+            for (final int row : selectedRows) {
+                checkRowIndex(row);
+            }
+            for (final int column : selectedColumns) {
+                checkColumnIndex(column);
+            }
         }
         return new RealMatrixImpl(subMatrixData, false);
     } 
@@ -450,47 +470,47 @@
      */
     public void setSubMatrix(double[][] subMatrix, int row, int column) 
         throws MatrixIndexException {
-        if ((row < 0) || (column < 0)){
-            throw new MatrixIndexException
-                ("invalid row or column index selection");          
-        }
+
         final int nRows = subMatrix.length;
         if (nRows == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one row."); 
+            throw new IllegalArgumentException("Matrix must have at least one row."); 
         }
+
         final int nCols = subMatrix[0].length;
         if (nCols == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one column."); 
+            throw new IllegalArgumentException("Matrix must have at least one column."); 
         }
+
         for (int r = 1; r < nRows; r++) {
             if (subMatrix[r].length != nCols) {
-                throw new IllegalArgumentException(
-                "All input rows must have the same length.");
+                throw new IllegalArgumentException("All input rows must have the same length.");
             }
-        }       
+        }
+
         if (data == null) {
-            if ((row > 0)||(column > 0)) throw new MatrixIndexException
-                ("matrix must be initialized to perfom this method");
+            if ((row > 0) || (column > 0)) {
+                throw new IllegalStateException("matrix must be initialized to perform this method");
+            }
             data = new double[nRows][nCols];
             System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);          
-        }   
-        if (((nRows + row) > this.getRowDimension()) ||
-            (nCols + column > this.getColumnDimension()))
-            throw new MatrixIndexException(
-                    "invalid row or column index selection");                   
+        } else {
+            checkRowIndex(row);
+            checkColumnIndex(column);
+            checkRowIndex(nRows + row - 1);
+            checkColumnIndex(nCols + column - 1);
+        }
+
         for (int i = 0; i < nRows; i++) {
             System.arraycopy(subMatrix[i], 0, data[row + i], column, nCols);
         } 
+
         lu = null;
+
     }
 
     /** {@inheritDoc} */
     public RealMatrix getRowMatrix(int row) throws MatrixIndexException {
-        if ( !isValidCoordinate( row, 0)) {
-            throw new MatrixIndexException("illegal row argument");
-        }
+        checkRowIndex(row);
         final int ncols = this.getColumnDimension();
         final double[][] out = new double[1][ncols]; 
         System.arraycopy(data[row], 0, out[0], 0, ncols);
@@ -499,9 +519,7 @@
     
     /** {@inheritDoc} */
     public RealMatrix getColumnMatrix(int column) throws MatrixIndexException {
-        if ( !isValidCoordinate( 0, column)) {
-            throw new MatrixIndexException("illegal column argument");
-        }
+        checkColumnIndex(column);
         final int nRows = this.getRowDimension();
         final double[][] out = new double[nRows][1]; 
         for (int row = 0; row < nRows; row++) {
@@ -522,9 +540,7 @@
 
     /** {@inheritDoc} */
     public double[] getRow(int row) throws MatrixIndexException {
-        if ( !isValidCoordinate( row, 0 ) ) {
-            throw new MatrixIndexException("illegal row argument");
-        }
+        checkRowIndex(row);
         final int ncols = this.getColumnDimension();
         final double[] out = new double[ncols];
         System.arraycopy(data[row], 0, out, 0, ncols);
@@ -533,9 +549,7 @@
 
     /** {@inheritDoc} */
     public double[] getColumn(int col) throws MatrixIndexException {
-        if ( !isValidCoordinate(0, col) ) {
-            throw new MatrixIndexException("illegal column argument");
-        }
+        checkColumnIndex(col);
         final int nRows = this.getRowDimension();
         final double[] out = new double[nRows];
         for (int row = 0; row < nRows; row++) {
@@ -550,7 +564,11 @@
         try {
             return data[row][column];
         } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException("matrix entry does not exist");
+            throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix",
+                                           new Object[] {
+                                               row, column,
+                                               getRowDimension(), getColumnDimension()
+                                           });
         }
     }
 
@@ -876,20 +894,32 @@
      * @throws NullPointerException if input array is null
      */
     private void copyIn(double[][] in) {
-        setSubMatrix(in,0,0);
+        setSubMatrix(in, 0, 0);
     }
 
     /**
-     * Tests a given coordinate as being valid or invalid
-     *
-     * @param row the row index.
-     * @param col the column index.
-     * @return true if the coordinate is with the current dimensions
+     * Check if a row index is valid.
+     * @param row row index to check
+     * @exception MatrixIndexException if index is not valid
      */
-    private boolean isValidCoordinate(int row, int col) {
-        final int nRows = getRowDimension();
-        final int nCols = getColumnDimension();
-        return !(row < 0 || row > nRows - 1 || col < 0 || col > nCols -1);
+    private void checkRowIndex(final int row) {
+        if (row < 0 || row >= getRowDimension()) {
+            throw new MatrixIndexException("row index {0} out of allowed range [{1}, {2}]",
+                                           new Object[] { row, 0, getRowDimension() - 1});
+        }
+    }
+
+    /**
+     * Check if a column index is valid.
+     * @param column column index to check
+     * @exception MatrixIndexException if index is not valid
+     */
+    private void checkColumnIndex(final int column)
+        throws MatrixIndexException {
+        if (column < 0 || column >= getColumnDimension()) {
+            throw new MatrixIndexException("column index {0} out of allowed range [{1}, {2}]",
+                                           new Object[] { column, 0, getColumnDimension() - 1});
+        }
     }
 
 }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealVectorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealVectorImpl.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealVectorImpl.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/RealVectorImpl.java Mon Nov  3 13:32:26 2008
@@ -1187,14 +1187,14 @@
 
     /** {@inheritDoc} */
     public RealVector get(int index, int n) {
+        RealVectorImpl out = new RealVectorImpl(n);
         try {
-            RealVectorImpl out = new RealVectorImpl(n);
             System.arraycopy(data, index, out.data, 0, n);
-
-            return out;
         } catch (IndexOutOfBoundsException e) {
-            throw new MatrixIndexException(e.getMessage());
+            checkIndex(index);
+            checkIndex(index + n - 1);
         }
+        return out;
     }
 
     /** {@inheritDoc} */
@@ -1202,7 +1202,7 @@
         try {
             data[index] = value;
         } catch (IndexOutOfBoundsException e) {
-            throw new MatrixIndexException(e.getMessage());
+            checkIndex(index);
         }
     }
 
@@ -1217,7 +1217,8 @@
                 }
             }
         } catch (IndexOutOfBoundsException e) {
-            throw new MatrixIndexException(e.getMessage());
+            checkIndex(index);
+            checkIndex(index + v.getDimension() - 1);
         }
     }
 
@@ -1226,7 +1227,8 @@
         try {
             System.arraycopy(v, 0, data, index, v.length);
         } catch (IndexOutOfBoundsException e) {
-            throw new MatrixIndexException(e.getMessage());
+            checkIndex(index);
+            checkIndex(index + v.length - 1);
         }
     }
 
@@ -1385,4 +1387,17 @@
         return MathUtils.hash(data);
     }
 
+    /**
+     * Check if an index is valid.
+     * @param index index to check
+     * @exception MatrixIndexException if index is not valid
+     */
+    private void checkIndex(final int index)
+        throws MatrixIndexException {
+        if (index < 0 || index >= getDimension()) {
+            throw new MatrixIndexException("index {0} out of allowed range [{1}, {2}]",
+                                           new Object[] { index, 0, getDimension() - 1});
+        }
+    }
+
 }

Added: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java?rev=710168&view=auto
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java (added)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java Mon Nov  3 13:32:26 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.linear;
+
+/**
+ * Thrown when a matrix is singular.
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public class SingularMatrixException extends InvalidMatrixException {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -7379143356784298432L;
+
+    /**
+     * Construct an exception with a default message.
+     */
+    public SingularMatrixException() {
+        super("matrix is singular", new Object[0]);
+    }
+
+}

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/SingularMatrixException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java Mon Nov  3 13:32:26 2008
@@ -68,7 +68,7 @@
     public TriDiagonalTransformer(RealMatrix matrix)
         throws InvalidMatrixException {
         if (!matrix.isSquare()) {
-            throw new InvalidMatrixException("transformation to tridiagonal requires that the matrix be square");
+            throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension());
         }
 
         final int m = matrix.getRowDimension();

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java Mon Nov  3 13:32:26 2008
@@ -783,7 +783,7 @@
         if (!lu.isSquare() || lowerData.length != lowerData[0].length || upperData.length != upperData[0].length ||
                 lowerData.length != upperData.length
                 || lowerData.length != lu.getRowDimension()) {
-            throw new InvalidMatrixException("incorrect dimensions");
+            throw new InvalidMatrixException("incorrect dimensions", new Object[0]);
         }    
         int n = lu.getRowDimension();
         for (int i = 0; i < n; i++) {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java Mon Nov  3 13:32:26 2008
@@ -23,20 +23,13 @@
  * @version $Revision$ $Date$
  */
 public class InvalidMatrixExceptionTest extends TestCase {
-    /**
-     * 
-     */
-    public void testConstructor(){
-        InvalidMatrixException ex = new InvalidMatrixException();
-        assertNull(ex.getMessage());
-    }
     
     /**
      * 
      */
     public void testConstructorMessage(){
         String msg = "message";
-        InvalidMatrixException ex = new InvalidMatrixException(msg);
+        InvalidMatrixException ex = new InvalidMatrixException(msg, new Object[0]);
         assertEquals(msg, ex.getMessage());
     }
 }

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java Mon Nov  3 13:32:26 2008
@@ -29,7 +29,7 @@
      */
     public void testConstructorMessage(){
         String msg = "message";
-        MatrixIndexException ex = new MatrixIndexException(msg);
+        MatrixIndexException ex = new MatrixIndexException(msg, new Object[0]);
         assertEquals(msg, ex.getMessage());
     }
 }

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java?rev=710168&r1=710167&r2=710168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java Mon Nov  3 13:32:26 2008
@@ -605,14 +605,14 @@
         RealMatrixImpl m2 = new RealMatrixImpl();
         try {
             m2.setSubMatrix(testData,0,1);
-            fail("expecting MatrixIndexException");
-        } catch (MatrixIndexException e) {
+            fail("expecting IllegalStateException");
+        } catch (IllegalStateException e) {
             // expected
         }
         try {
             m2.setSubMatrix(testData,1,0);
-            fail("expecting MatrixIndexException");
-        } catch (MatrixIndexException e) {
+            fail("expecting IllegalStateException");
+        } catch (IllegalStateException e) {
             // expected
         }
         
@@ -659,7 +659,7 @@
         if (!lu.isSquare() || lowerData.length != lowerData[0].length || upperData.length != upperData[0].length ||
                 lowerData.length != upperData.length
                 || lowerData.length != lu.getRowDimension()) {
-            throw new InvalidMatrixException("incorrect dimensions");
+            throw new InvalidMatrixException("incorrect dimensions", new Object[0]);
         }    
         int n = lu.getRowDimension();
         for (int i = 0; i < n; i++) {



Mime
View raw message