Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 91028 invoked from network); 24 Sep 2010 23:13:08 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 24 Sep 2010 23:13:08 -0000 Received: (qmail 46882 invoked by uid 500); 24 Sep 2010 23:13:07 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 46812 invoked by uid 500); 24 Sep 2010 23:13:07 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 46805 invoked by uid 99); 24 Sep 2010 23:13:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Sep 2010 23:13:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Sep 2010 23:12:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A4FB62388999; Fri, 24 Sep 2010 23:12:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1001107 [1/2] - 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/ site/xdoc/ te... Date: Fri, 24 Sep 2010 23:12:35 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100924231235.A4FB62388999@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: erans Date: Fri Sep 24 23:12:34 2010 New Revision: 1001107 URL: http://svn.apache.org/viewvc?rev=1001107&view=rev Log: Introduced "MatrixDimensionMismatchException" to replace "InvalidMatrixException" whenever it was used to signal a row or column dimension mismatch. "MessageFactory": Fixed wrong order of appearance of general and specific messages. Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java (with props) commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MatrixDimensionMismatchExceptionTest.java (with props) Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealMatrix.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealMatrixImplTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java Fri Sep 24 23:12:34 2010 @@ -40,7 +40,9 @@ public class DimensionMismatchException */ public DimensionMismatchException(int wrong, int expected) { - super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, wrong, expected); + super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, + LocalizedFormats.DIMENSIONS_MISMATCH, + wrong, expected); dimension = expected; } Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java?rev=1001107&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java Fri Sep 24 23:12:34 2010 @@ -0,0 +1,73 @@ +/* + * 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.exception; + +import org.apache.commons.math.exception.util.LocalizedFormats; + +/** + * Exception to be thrown when either the number of rows or the number of + * columns of a matrix do not match the expected values. + * + * @since 3.0 + * @version $Revision$ $Date$ + */ +public class MatrixDimensionMismatchException extends MultiDimensionMismatchException { + /** Serializable version Id. */ + private static final long serialVersionUID = -8415396756375798143L; + + /** + * Construct an exception from the mismatched dimensions. + * + * @param wrongRowDim Wrong row dimension. + * @param wrongColDim Wrong column dimension. + * @param expectedRowDim Expected row dimension. + * @param expectedColDim Expected column dimension. + */ + public MatrixDimensionMismatchException(int wrongRowDim, + int wrongColDim, + int expectedRowDim, + int expectedColDim) { + super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2, + new Integer[] { wrongRowDim, wrongColDim }, + new Integer[] { expectedRowDim, expectedColDim }); + } + + /** + * @return the expected row dimension. + */ + public int getWrongRowDimension() { + return getWrongDimensions()[0]; + } + /** + * @return the expected row dimension. + */ + public int getExpectedRowDimension() { + return getExpectedDimensions()[0]; + } + /** + * @return the wrong column dimension. + */ + public int getWrongColumnDimension() { + return getWrongDimensions()[1]; + } + /** + * @return the expected column dimension. + */ + public int getExpectedColumnDimension() { + return getExpectedDimensions()[1]; + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java?rev=1001107&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java Fri Sep 24 23:12:34 2010 @@ -0,0 +1,76 @@ +/* + * 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.exception; + +import org.apache.commons.math.exception.util.Localizable; +import org.apache.commons.math.exception.util.LocalizedFormats; + +/** + * Exception to be thrown when two sets of dimensions differ. + * + * @since 3.0 + * @version $Revision$ $Date$ + */ +public class MultiDimensionMismatchException extends MathIllegalArgumentException { + /** Serializable version Id. */ + private static final long serialVersionUID = -8415396756375798143L; + + /** Wrong dimensions. */ + private final Integer[] wrong; + /** Correct dimensions. */ + private final Integer[] expected; + + /** + * Construct an exception from the mismatched dimensions. + * + * @param wrong Wrong dimensionq. + * @param expected Expected dimensionq. + */ + public MultiDimensionMismatchException(Integer[] wrong, + Integer[] expected) { + this(null, wrong, expected); + } + + /** + * Construct an exception from the mismatched dimensions. + * + * @param specific Message pattern providing the specific context of + * the error. + * @param wrong Wrong dimensions. + * @param expected Expected dimensions. + */ + public MultiDimensionMismatchException(Localizable specific, + Integer[] wrong, + Integer[] expected) { + super(specific, LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected); + this.wrong = wrong.clone(); + this.expected = expected.clone(); + } + + /** + * @return a reference to the array containing the wrong dimensions. + */ + public Integer[] getWrongDimensions() { + return wrong; + } + /** + * @return a reference to the array containing the expected dimensions. + */ + public Integer[] getExpectedDimensions() { + return expected; + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Fri Sep 24 23:12:34 2010 @@ -79,8 +79,9 @@ public enum LocalizedFormats implements CUMULATIVE_PROBABILITY_RETURNED_NAN("Cumulative probability function returned NaN for argument {0} p = {1}"), DIFFERENT_ROWS_LENGTHS("some rows have length {0} while others have length {1}"), DIGEST_NOT_INITIALIZED("digest not initialized"), - DIMENSIONS_MISMATCH_2x2("dimensions mismatch: got {0}x{1} but expected {2}x{3}"), - DIMENSIONS_MISMATCH_SIMPLE("dimensions mismatch {0} != {1}"), /* keep */ + DIMENSIONS_MISMATCH_2x2("got {0}x{1} but expected {2}x{3}"), /* keep */ + DIMENSIONS_MISMATCH_SIMPLE("{0} != {1}"), /* keep */ + DIMENSIONS_MISMATCH("dimensions mismatch"), /* keep */ DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN("Discrete cumulative probability function returned NaN for argument {0}"), DISTRIBUTION_NOT_LOADED("distribution not loaded"), DUPLICATED_ABSCISSA("Abscissa {0} is duplicated at both indices {1} and {2}"), Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java Fri Sep 24 23:12:34 2010 @@ -63,13 +63,13 @@ public class MessageFactory { Object ... arguments) { final StringBuilder sb = new StringBuilder(); MessageFormat fmt = null; + fmt = new MessageFormat(general.getLocalizedString(locale), locale); + sb.append(fmt.format(arguments)); if (specific != null) { + sb.append(": "); fmt = new MessageFormat(specific.getLocalizedString(locale), locale); sb.append(fmt.format(arguments)); - sb.append(": "); } - fmt = new MessageFormat(general.getLocalizedString(locale), locale); - sb.append(fmt.format(arguments)); return sb.toString(); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java Fri Sep 24 23:12:34 2010 @@ -23,6 +23,7 @@ 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.MatrixDimensionMismatchException; import org.apache.commons.math.exception.util.LocalizedFormats; /** @@ -445,16 +446,14 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setRowMatrix(final int row, final FieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + public void setRowMatrix(final int row, final FieldMatrix matrix) { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); @@ -478,16 +477,14 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setColumnMatrix(final int column, final FieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumnMatrix(final int column, final FieldMatrix matrix) { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); @@ -502,15 +499,12 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setRowVector(final int row, final FieldVector vector) - throws MatrixIndexException, InvalidMatrixException { - + public void setRowVector(final int row, final FieldVector vector) { checkRowIndex(row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - 1, vector.getDimension(), 1, nCols); + throw new MatrixDimensionMismatchException(1, vector.getDimension(), + 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); @@ -525,15 +519,12 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setColumnVector(final int column, final FieldVector vector) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumnVector(final int column, final FieldVector vector) { checkColumnIndex(column); final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - vector.getDimension(), 1, nRows, 1); + throw new MatrixDimensionMismatchException(vector.getDimension(), 1, + nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, vector.getEntry(i)); @@ -557,15 +548,11 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setRow(final int row, final T[] array) - throws MatrixIndexException, InvalidMatrixException { - + public void setRow(final int row, final T[] array) { checkRowIndex(row); final int nCols = getColumnDimension(); if (array.length != nCols) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - 1, array.length, 1, nCols); + throw new MatrixDimensionMismatchException(1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); @@ -589,20 +576,15 @@ public abstract class AbstractFieldMatri } /** {@inheritDoc} */ - public void setColumn(final int column, final T[] array) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumn(final int column, final T[] array) { checkColumnIndex(column); final int nRows = getRowDimension(); if (array.length != nRows) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - array.length, 1, nRows, 1); + throw new MatrixDimensionMismatchException(array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, array[i]); } - } /** {@inheritDoc} */ @@ -623,22 +605,18 @@ public abstract class AbstractFieldMatri /** {@inheritDoc} */ public FieldMatrix transpose() { - final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final FieldMatrix out = createMatrix(nCols, nRows); walkInOptimizedOrder(new DefaultFieldMatrixPreservingVisitor(field.getZero()) { - /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final T value) { out.setEntry(column, row, value); } - }); return out; - } /** {@inheritDoc} */ @@ -689,7 +667,6 @@ public abstract class AbstractFieldMatri } return out; - } /** {@inheritDoc} */ @@ -741,7 +718,6 @@ public abstract class AbstractFieldMatri } return out; - } /** {@inheritDoc} */ @@ -769,7 +745,6 @@ public abstract class AbstractFieldMatri } return new ArrayFieldVector(out); - } } @@ -958,7 +933,6 @@ public abstract class AbstractFieldMatri res.append("}"); return res.toString(); - } /** @@ -1063,8 +1037,6 @@ public abstract class AbstractFieldMatri throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN, startColumn, endColumn); } - - } /** @@ -1134,5 +1106,4 @@ public abstract class AbstractFieldMatri m.getRowDimension(), m.getColumnDimension()); } } - } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java Fri Sep 24 23:12:34 2010 @@ -17,7 +17,10 @@ package org.apache.commons.math.linear; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NotStrictlyPositiveException; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.MatrixDimensionMismatchException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.FastMath; @@ -51,17 +54,14 @@ public abstract class AbstractRealMatrix * * @param rowDimension the number of rows in the new matrix * @param columnDimension the number of columns in the new matrix - * @throws IllegalArgumentException if row or column dimension is not positive + * @throws NotStrictlyPositiveException if row or column dimension is not positive */ - protected AbstractRealMatrix(final int rowDimension, final int columnDimension) - throws IllegalArgumentException { - if (rowDimension < 1 ) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.INSUFFICIENT_DIMENSION, rowDimension, 1); - } - if (columnDimension <= 0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.INSUFFICIENT_DIMENSION, columnDimension, 1); + protected AbstractRealMatrix(final int rowDimension, final int columnDimension) { + if (rowDimension < 1) { + throw new NotStrictlyPositiveException(rowDimension); + } + if (columnDimension < 1) { + throw new NotStrictlyPositiveException(columnDimension); } lu = null; } @@ -89,7 +89,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -108,7 +107,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -124,7 +122,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -140,7 +137,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -165,7 +161,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -187,7 +182,6 @@ public abstract class AbstractRealMatrix } return data; - } /** {@inheritDoc} */ @@ -225,7 +219,6 @@ public abstract class AbstractRealMatrix public double end() { return maxColSum; } - }); } @@ -252,7 +245,6 @@ public abstract class AbstractRealMatrix public double end() { return FastMath.sqrt(sum); } - }); } @@ -272,7 +264,6 @@ public abstract class AbstractRealMatrix } return subMatrix; - } /** {@inheritDoc} */ @@ -296,7 +287,6 @@ public abstract class AbstractRealMatrix }); return subMatrix; - } /** {@inheritDoc} */ @@ -310,10 +300,8 @@ public abstract class AbstractRealMatrix final int rowsCount = endRow + 1 - startRow; final int columnsCount = endColumn + 1 - startColumn; if ((destination.length < rowsCount) || (destination[0].length < columnsCount)) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - destination.length, destination[0].length, - rowsCount, columnsCount); + throw new MatrixDimensionMismatchException(destination.length, destination[0].length, + rowsCount, columnsCount); } // copy entries @@ -341,21 +329,17 @@ public abstract class AbstractRealMatrix } }, startRow, endRow, startColumn, endColumn); - } /** {@inheritDoc} */ - public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination) - throws MatrixIndexException, IllegalArgumentException { + public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination) { // safety checks MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - destination.length, destination[0].length, - selectedRows.length, selectedColumns.length); + throw new MatrixDimensionMismatchException(destination.length, destination[0].length, + selectedRows.length, selectedColumns.length); } // copy entries @@ -365,7 +349,6 @@ public abstract class AbstractRealMatrix destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]); } } - } /** {@inheritDoc} */ @@ -374,19 +357,17 @@ public abstract class AbstractRealMatrix final int nRows = subMatrix.length; if (nRows == 0) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); + throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); + throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIFFERENT_ROWS_LENGTHS, - nCols, subMatrix[r].length); + throw new DimensionMismatchException(nCols, subMatrix[r].length); } } @@ -402,7 +383,6 @@ public abstract class AbstractRealMatrix } lu = null; - } /** {@inheritDoc} */ @@ -417,25 +397,21 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ - public void setRowMatrix(final int row, final RealMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + public void setRowMatrix(final int row, final RealMatrix matrix) { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } - } /** {@inheritDoc} */ @@ -450,25 +426,21 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ - public void setColumnMatrix(final int column, final RealMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumnMatrix(final int column, final RealMatrix matrix) { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); } - } /** {@inheritDoc} */ @@ -478,20 +450,16 @@ public abstract class AbstractRealMatrix } /** {@inheritDoc} */ - public void setRowVector(final int row, final RealVector vector) - throws MatrixIndexException, InvalidMatrixException { - + public void setRowVector(final int row, final RealVector vector) { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - 1, vector.getDimension(), 1, nCols); + throw new MatrixDimensionMismatchException(1, vector.getDimension(), + 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } - } /** {@inheritDoc} */ @@ -501,20 +469,16 @@ public abstract class AbstractRealMatrix } /** {@inheritDoc} */ - public void setColumnVector(final int column, final RealVector vector) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumnVector(final int column, final RealVector vector) { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - vector.getDimension(), 1, nRows, 1); + throw new MatrixDimensionMismatchException(vector.getDimension(), 1, + nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, vector.getEntry(i)); } - } /** {@inheritDoc} */ @@ -529,24 +493,18 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ - public void setRow(final int row, final double[] array) - throws MatrixIndexException, InvalidMatrixException { - + public void setRow(final int row, final double[] array) { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (array.length != nCols) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - 1, array.length, 1, nCols); + throw new MatrixDimensionMismatchException(1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); } - } /** {@inheritDoc} */ @@ -561,24 +519,18 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ - public void setColumn(final int column, final double[] array) - throws MatrixIndexException, InvalidMatrixException { - + public void setColumn(final int column, final double[] array) { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (array.length != nRows) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - array.length, 1, nRows, 1); + throw new MatrixDimensionMismatchException(array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, array[i]); } - } /** {@inheritDoc} */ @@ -614,7 +566,6 @@ public abstract class AbstractRealMatrix }); return out; - } /** {@inheritDoc} */ @@ -676,9 +627,7 @@ public abstract class AbstractRealMatrix final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nCols) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.VECTOR_LENGTH_MISMATCH, - v.length, nCols); + throw new DimensionMismatchException(v.length, nCols); } final double[] out = new double[nRows]; @@ -691,7 +640,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -703,9 +651,7 @@ public abstract class AbstractRealMatrix final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nCols) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.VECTOR_LENGTH_MISMATCH, - v.getDimension(), nCols); + throw new DimensionMismatchException(v.getDimension(), nCols); } final double[] out = new double[nRows]; @@ -728,9 +674,7 @@ public abstract class AbstractRealMatrix final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.VECTOR_LENGTH_MISMATCH, - v.length, nRows); + throw new DimensionMismatchException(v.length, nRows); } final double[] out = new double[nCols]; @@ -743,7 +687,6 @@ public abstract class AbstractRealMatrix } return out; - } /** {@inheritDoc} */ @@ -756,9 +699,7 @@ public abstract class AbstractRealMatrix final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nRows) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.VECTOR_LENGTH_MISMATCH, - v.getDimension(), nRows); + throw new DimensionMismatchException(v.getDimension(), nRows); } final double[] out = new double[nCols]; @@ -771,7 +712,6 @@ public abstract class AbstractRealMatrix } return new ArrayRealVector(out); - } } @@ -1011,7 +951,6 @@ public abstract class AbstractRealMatrix res.append("}"); return res.toString(); - } /** @@ -1066,5 +1005,4 @@ public abstract class AbstractRealMatrix } return ret; } - } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java Fri Sep 24 23:12:34 2010 @@ -21,7 +21,9 @@ import java.io.Serializable; import org.apache.commons.math.Field; import org.apache.commons.math.FieldElement; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.MatrixDimensionMismatchException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; @@ -171,9 +173,8 @@ public class BlockFieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { + public void setRowMatrix(final int row, final FieldMatrix matrix) { try { setRowMatrix(row, (BlockFieldMatrix) matrix); } catch (ClassCastException cce) { @@ -908,20 +904,17 @@ public class BlockFieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + public void setRowMatrix(final int row, final BlockFieldMatrix matrix) { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), - 1, nCols); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + 1, nCols); } // perform copy block-wise, to ensure good cache behavior @@ -980,8 +973,7 @@ public class BlockFieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { + public void setColumnMatrix(final int column, final FieldMatrix matrix) { try { setColumnMatrix(column, (BlockFieldMatrix) matrix); } catch (ClassCastException cce) { @@ -997,20 +989,17 @@ public class BlockFieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException { - + void setColumnMatrix(final int column, final BlockFieldMatrix matrix) { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { - throw new InvalidMatrixException( - LocalizedFormats.DIMENSIONS_MISMATCH_2x2, - matrix.getRowDimension(), matrix.getColumnDimension(), - nRows, 1); + throw new MatrixDimensionMismatchException(matrix.getRowDimension(), + matrix.getColumnDimension(), + nRows, 1); } // perform copy block-wise, to ensure good cache behavior @@ -1031,7 +1020,6 @@ public class BlockFieldMatrix vector) - throws MatrixIndexException, InvalidMatrixException { + public void setRowVector(final int row, final FieldVector vector) { try { setRow(row, ((ArrayFieldVector) vector).getDataRef()); } catch (ClassCastException cce) { @@ -1095,8 +1082,7 @@ public class BlockFieldMatrix vector) - throws MatrixIndexException, InvalidMatrixException { + public void setColumnVector(final int column, final FieldVector vector) { try { setColumn(column, ((ArrayFieldVector) vector).getDataRef()); } catch (ClassCastException cce) { @@ -1129,15 +1115,11 @@ public class BlockFieldMatrix add(FieldMatrix m) throws IllegalArgumentException; + FieldMatrix add(FieldMatrix m); /** * Compute this minus m. @@ -73,7 +73,7 @@ public interface FieldMatrix subtract(FieldMatrix m) throws IllegalArgumentException; + FieldMatrix subtract(FieldMatrix m); /** * Returns the result of adding d to each entry of this. @@ -99,7 +99,7 @@ public interface FieldMatrix multiply(FieldMatrix m) throws IllegalArgumentException; + FieldMatrix multiply(FieldMatrix m); /** * Returns the result premultiplying this by m. @@ -108,7 +108,7 @@ public interface FieldMatrix preMultiply(FieldMatrix m) throws IllegalArgumentException; + FieldMatrix preMultiply(FieldMatrix m); /** * Returns matrix entries as a two-dimensional array. @@ -129,8 +129,7 @@ public interface FieldMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException; + FieldMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn); /** * Gets a submatrix. Rows and columns are indicated @@ -142,8 +141,7 @@ public interface FieldMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns) - throws MatrixIndexException; + FieldMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns); /** * Copy a submatrix. Rows and columns are indicated @@ -159,8 +157,7 @@ public interface FieldMatrixrow, column using data in @@ -203,8 +199,7 @@ public interface FieldMatrixsubMatrix is null * @since 2.0 */ - void setSubMatrix(T[][] subMatrix, int row, int column) - throws MatrixIndexException; + void setSubMatrix(T[][] subMatrix, int row, int column); /** * Returns the entries in row number row @@ -214,7 +209,7 @@ public interface FieldMatrix getRowMatrix(int row) throws MatrixIndexException; + FieldMatrix getRowMatrix(int row); /** * Sets the entries in row number row @@ -224,11 +219,10 @@ public interface FieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException; + void setRowMatrix(int row, FieldMatrix matrix); /** * Returns the entries in column number column @@ -238,7 +232,7 @@ public interface FieldMatrix getColumnMatrix(int column) throws MatrixIndexException; + FieldMatrix getColumnMatrix(int column); /** * Sets the entries in column number column @@ -248,11 +242,10 @@ public interface FieldMatrix matrix) - throws MatrixIndexException, InvalidMatrixException; + void setColumnMatrix(int column, FieldMatrix matrix); /** * Returns the entries in row number row @@ -262,7 +255,7 @@ public interface FieldMatrix getRowVector(int row) throws MatrixIndexException; + FieldVector getRowVector(int row); /** * Sets the entries in row number row @@ -272,11 +265,10 @@ public interface FieldMatrix vector) - throws MatrixIndexException, InvalidMatrixException; + void setRowVector(int row, FieldVector vector); /** * Returns the entries in column number column @@ -286,7 +278,7 @@ public interface FieldMatrix getColumnVector(int column) throws MatrixIndexException; + FieldVector getColumnVector(int column); /** * Sets the entries in column number column @@ -295,23 +287,22 @@ public interface FieldMatrix vector) - throws MatrixIndexException, InvalidMatrixException; + void setColumnVector(int column, FieldVector vector); /** * Returns the entries in row number row as an array. *

* Row indices start at 0. A MatrixIndexException is thrown - * unless 0 <= row < rowDimension.

+ * unless {@code 0 <= row < rowDimension}.

* * @param row the row to be fetched * @return array of entries in the row * @throws MatrixIndexException if the specified row index is not valid */ - T[] getRow(int row) throws MatrixIndexException; + T[] getRow(int row); /** * Sets the entries in row number row @@ -320,23 +311,22 @@ public interface FieldMatrixcol as an array. *

* Column indices start at 0. A MatrixIndexException is thrown - * unless 0 <= column < columnDimension.

+ * unless {@code 0 <= column < columnDimension}.

* * @param column the column to be fetched * @return array of entries in the column * @throws MatrixIndexException if the specified column index is not valid */ - T[] getColumn(int column) throws MatrixIndexException; + T[] getColumn(int column); /** * Sets the entries in column number column @@ -345,19 +335,18 @@ public interface FieldMatrix * Row and column indices start at 0 and must satisfy *
    - *
  • 0 <= row < rowDimension
  • - *
  • 0 <= column < columnDimension
  • + *
  • {@code 0 <= row < rowDimension}
  • + *
  • {@code 0 <= column < columnDimension}
  • *
* otherwise a MatrixIndexException is thrown.

* @@ -366,15 +355,15 @@ public interface FieldMatrix * Row and column indices start at 0 and must satisfy *
    - *
  • 0 <= row < rowDimension
  • - *
  • 0 <= column < columnDimension
  • + *
  • {@code 0 <= row < rowDimension}
  • + *
  • {@code 0 <= column < columnDimension}
  • *
* otherwise a MatrixIndexException is thrown.

* @@ -384,15 +373,15 @@ public interface FieldMatrix * Row and column indices start at 0 and must satisfy *
    - *
  • 0 <= row < rowDimension
  • - *
  • 0 <= column < columnDimension
  • + *
  • {@code 0 <= row < rowDimension}
  • + *
  • {@code 0 <= column < columnDimension}
  • *
* otherwise a MatrixIndexException is thrown.

* @@ -409,8 +398,8 @@ public interface FieldMatrix * Row and column indices start at 0 and must satisfy *
    - *
  • 0 <= row < rowDimension
  • - *
  • 0 <= column < columnDimension
  • + *
  • {@code 0 <= row < rowDimension}
  • + *
  • {@code 0 <= column < columnDimension}
  • *
* otherwise a MatrixIndexException is thrown.

* @@ -420,7 +409,7 @@ public interface FieldMatrixv. @@ -445,7 +434,7 @@ public interface FieldMatrixv. @@ -454,7 +443,7 @@ public interface FieldMatrix operate(FieldVector v) throws IllegalArgumentException; + FieldVector operate(FieldVector v); /** * Returns the (row) vector result of premultiplying this by the vector v. @@ -463,7 +452,7 @@ public interface FieldMatrixv. @@ -472,7 +461,7 @@ public interface FieldMatrix preMultiply(FieldVector v) throws IllegalArgumentException; + FieldVector preMultiply(FieldVector v); /** * Visit (and possibly change) all matrix entries in row order. @@ -495,8 +484,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInRowOrder(FieldMatrixChangingVisitor visitor); /** * Visit (but don't change) all matrix entries in row order. @@ -519,8 +507,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInRowOrder(FieldMatrixPreservingVisitor visitor); /** * Visit (and possibly change) some matrix entries in row order. @@ -549,8 +536,7 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; + int startRow, int endRow, int startColumn, int endColumn); /** * Visit (but don't change) some matrix entries in row order. @@ -579,8 +565,7 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; + int startRow, int endRow, int startColumn, int endColumn); /** * Visit (and possibly change) all matrix entries in column order. @@ -603,8 +588,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInColumnOrder(FieldMatrixChangingVisitor visitor); /** * Visit (but don't change) all matrix entries in column order. @@ -627,8 +611,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInColumnOrder(FieldMatrixPreservingVisitor visitor); /** * Visit (and possibly change) some matrix entries in column order. @@ -657,8 +640,7 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; + int startRow, int endRow, int startColumn, int endColumn); /** * Visit (but don't change) some matrix entries in column order. @@ -687,8 +669,7 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; + int startRow, int endRow, int startColumn, int endColumn); /** * Visit (and possibly change) all matrix entries using the fastest possible order. @@ -710,8 +691,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInOptimizedOrder(FieldMatrixChangingVisitor visitor); /** * Visit (but don't change) all matrix entries using the fastest possible order. @@ -733,8 +713,7 @@ public interface FieldMatrix visitor) - throws MatrixVisitorException; + T walkInOptimizedOrder(FieldMatrixPreservingVisitor visitor); /** * Visit (and possibly change) some matrix entries using the fastest possible order. @@ -762,8 +741,7 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; + int startRow, int endRow, int startColumn, int endColumn); /** * Visit (but don't change) some matrix entries using the fastest possible order. @@ -791,7 +769,5 @@ public interface FieldMatrix visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws MatrixIndexException, MatrixVisitorException; - + int startRow, int endRow, int startColumn, int endColumn); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java?rev=1001107&r1=1001106&r2=1001107&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/InvalidMatrixException.java Fri Sep 24 23:12:34 2010 @@ -26,6 +26,8 @@ import org.apache.commons.math.exception * that matrix does not satisfy the preconditions for the * aforementioned operation. * @version $Revision$ $Date$ + * @deprecated since 2.2. Please use the classes in the + * {@link org.apache.commons.math.exception} package. */ public class InvalidMatrixException extends MathRuntimeException {