You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2012/10/08 07:16:27 UTC
svn commit: r1395452 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear:
AbstractFieldMatrix.java BlockFieldMatrix.java FieldMatrix.java
Author: celestin
Date: Mon Oct 8 05:16:27 2012
New Revision: 1395452
URL: http://svn.apache.org/viewvc?rev=1395452&view=rev
Log:
MATH-854: populated throws clause of BlockFieldMatrix.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/AbstractFieldMatrix.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/BlockFieldMatrix.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/AbstractFieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/AbstractFieldMatrix.java?rev=1395452&r1=1395451&r2=1395452&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/AbstractFieldMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/AbstractFieldMatrix.java Mon Oct 8 05:16:27 2012
@@ -461,13 +461,11 @@ public abstract class AbstractFieldMatri
}
- /**
- * {@inheritDoc}
- *
- */
- public void setSubMatrix(final T[][] subMatrix, final int row, final int column)
- throws DimensionMismatchException, NoDataException, NullArgumentException,
- OutOfRangeException {
+ /** {@inheritDoc} */
+ public void setSubMatrix(final T[][] subMatrix, final int row,
+ final int column)
+ throws DimensionMismatchException, OutOfRangeException,
+ NoDataException, NullArgumentException, NumberIsTooSmallException {
if (subMatrix == null) {
throw new NullArgumentException();
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/BlockFieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/BlockFieldMatrix.java?rev=1395452&r1=1395451&r2=1395452&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/BlockFieldMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/BlockFieldMatrix.java Mon Oct 8 05:16:27 2012
@@ -23,6 +23,10 @@ import org.apache.commons.math3.Field;
import org.apache.commons.math3.FieldElement;
import org.apache.commons.math3.exception.NoDataException;
import org.apache.commons.math3.exception.DimensionMismatchException;
+import org.apache.commons.math3.exception.NotStrictlyPositiveException;
+import org.apache.commons.math3.exception.NullArgumentException;
+import org.apache.commons.math3.exception.NumberIsTooSmallException;
+import org.apache.commons.math3.exception.OutOfRangeException;
import org.apache.commons.math3.exception.util.LocalizedFormats;
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.util.MathUtils;
@@ -89,10 +93,12 @@ public class BlockFieldMatrix<T extends
* @param field Field to which the elements belong.
* @param rows Number of rows in the new matrix.
* @param columns Number of columns in the new matrix.
- * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException
- * if row or column dimension is not positive.
+ * @throws NotStrictlyPositiveException if row or column dimension is not
+ * positive.
*/
- public BlockFieldMatrix(final Field<T> field, final int rows, final int columns) {
+ public BlockFieldMatrix(final Field<T> field, final int rows,
+ final int columns)
+ throws NotStrictlyPositiveException {
super(field, rows, columns);
this.rows = rows;
this.columns = columns;
@@ -112,13 +118,14 @@ public class BlockFieldMatrix<T extends
* <pre>matrix = new BlockFieldMatrix<T>(getField(), rawData.length, rawData[0].length,
* toBlocksLayout(rawData), false);</pre>
* </p>
- * @param rawData Data for the new matrix, in raw layout.
*
- * @exception DimensionMismatchException if the {@code blockData} shape is
+ * @param rawData Data for the new matrix, in raw layout.
+ * @throws DimensionMismatchException if the {@code blockData} shape is
* inconsistent with block layout.
* @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
*/
- public BlockFieldMatrix(final T[][] rawData) {
+ public BlockFieldMatrix(final T[][] rawData)
+ throws DimensionMismatchException {
this(rawData.length, rawData[0].length, toBlocksLayout(rawData), false);
}
@@ -131,14 +138,17 @@ public class BlockFieldMatrix<T extends
* @param copyArray if true, the input array will be copied, otherwise
* it will be referenced
*
- * @exception DimensionMismatchException if the {@code blockData} shape is
+ * @throws DimensionMismatchException if the {@code blockData} shape is
* inconsistent with block layout.
+ * @throws NotStrictlyPositiveException if row or column dimension is not
+ * positive.
* @see #createBlocksLayout(Field, int, int)
* @see #toBlocksLayout(FieldElement[][])
* @see #BlockFieldMatrix(FieldElement[][])
*/
public BlockFieldMatrix(final int rows, final int columns,
- final T[][] blockData, final boolean copyArray) {
+ final T[][] blockData, final boolean copyArray)
+ throws DimensionMismatchException, NotStrictlyPositiveException {
super(extractField(blockData), rows, columns);
this.rows = rows;
this.columns = columns;
@@ -194,7 +204,8 @@ public class BlockFieldMatrix<T extends
* @see #createBlocksLayout(Field, int, int)
* @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
*/
- public static <T extends FieldElement<T>> T[][] toBlocksLayout(final T[][] rawData) {
+ public static <T extends FieldElement<T>> T[][] toBlocksLayout(final T[][] rawData)
+ throws DimensionMismatchException {
final int rows = rawData.length;
final int columns = rawData[0].length;
@@ -280,8 +291,11 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) {
- return new BlockFieldMatrix<T>(getField(), rowDimension, columnDimension);
+ public FieldMatrix<T> createMatrix(final int rowDimension,
+ final int columnDimension)
+ throws NotStrictlyPositiveException {
+ return new BlockFieldMatrix<T>(getField(), rowDimension,
+ columnDimension);
}
/** {@inheritDoc} */
@@ -301,7 +315,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> add(final FieldMatrix<T> m) {
+ public FieldMatrix<T> add(final FieldMatrix<T> m)
+ throws MatrixDimensionMismatchException {
try {
return add((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
@@ -342,13 +357,15 @@ public class BlockFieldMatrix<T extends
}
/**
- * Compute the sum of this and <code>m</code>.
+ * Compute the sum of {@code this} and {@code m}.
*
- * @param m matrix to be added
- * @return this + m
- * @throws IllegalArgumentException if m is not the same size as this
+ * @param m matrix to be added
+ * @return {@code this + m}
+ * @throws MatrixDimensionMismatchException if {@code m} is not the same
+ * size as {@code this}
*/
- public BlockFieldMatrix<T> add(final BlockFieldMatrix<T> m) {
+ public BlockFieldMatrix<T> add(final BlockFieldMatrix<T> m)
+ throws MatrixDimensionMismatchException {
// safety check
checkAdditionCompatible(m);
@@ -370,7 +387,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> subtract(final FieldMatrix<T> m) {
+ public FieldMatrix<T> subtract(final FieldMatrix<T> m)
+ throws MatrixDimensionMismatchException {
try {
return subtract((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
@@ -411,13 +429,14 @@ public class BlockFieldMatrix<T extends
}
/**
- * Compute this minus <code>m</code>.
+ * Compute {@code this - m}.
*
- * @param m matrix to be subtracted
- * @return this - m
- * @throws IllegalArgumentException if m is not the same size as this
+ * @param m matrix to be subtracted
+ * @return {@code this - m}
+ * @throws MatrixDimensionMismatchException if {@code m} is not the same
+ * size as {@code this}
*/
- public BlockFieldMatrix<T> subtract(final BlockFieldMatrix<T> m) {
+ public BlockFieldMatrix<T> subtract(final BlockFieldMatrix<T> m) throws MatrixDimensionMismatchException {
// safety check
checkSubtractionCompatible(m);
@@ -473,7 +492,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> multiply(final FieldMatrix<T> m) {
+ public FieldMatrix<T> multiply(final FieldMatrix<T> m)
+ throws DimensionMismatchException {
try {
return multiply((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
@@ -532,14 +552,14 @@ public class BlockFieldMatrix<T extends
}
/**
- * Returns the result of postmultiplying this by m.
+ * Returns the result of postmultiplying {@code this} by {@code m}.
*
- * @param m matrix to postmultiply by
- * @return this * m
- * @throws IllegalArgumentException
- * if columnDimension(this) != rowDimension(m)
+ * @param m matrix to postmultiply by
+ * @return {@code this * m}
+ * @throws DimensionMismatchException if the matrices are not compatible.
*/
- public BlockFieldMatrix<T> multiply(BlockFieldMatrix<T> m) {
+ public BlockFieldMatrix<T> multiply(BlockFieldMatrix<T> m)
+ throws DimensionMismatchException {
// safety check
checkMultiplicationCompatible(m);
@@ -635,7 +655,9 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
public FieldMatrix<T> getSubMatrix(final int startRow, final int endRow,
- final int startColumn, final int endColumn) {
+ final int startColumn,
+ final int endColumn)
+ throws OutOfRangeException, NumberIsTooSmallException {
// safety checks
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
@@ -758,7 +780,10 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
+ public void setSubMatrix(final T[][] subMatrix, final int row,
+ final int column)
+ throws DimensionMismatchException, OutOfRangeException,
+ NoDataException, NullArgumentException, NumberIsTooSmallException {
// safety checks
MathUtils.checkNotNull(subMatrix);
final int refLength = subMatrix[0].length;
@@ -808,7 +833,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> getRowMatrix(final int row) {
+ public FieldMatrix<T> getRowMatrix(final int row)
+ throws OutOfRangeException {
checkRowIndex(row);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), 1, columns);
@@ -838,7 +864,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setRowMatrix(final int row, final FieldMatrix<T> matrix) {
+ public void setRowMatrix(final int row, final FieldMatrix<T> matrix)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
try {
setRowMatrix(row, (BlockFieldMatrix<T>) matrix);
} catch (ClassCastException cce) {
@@ -853,12 +880,12 @@ public class BlockFieldMatrix<T extends
* @param row the row to be set
* @param matrix row matrix (must have one row and the same number of columns
* as the instance)
- * @throws org.apache.commons.math3.exception.OutOfRangeException if the
- * specified row index is invalid.
* @throws MatrixDimensionMismatchException if the matrix dimensions do
* not match one instance row.
+ * @throws OutOfRangeException if the specified row index is invalid.
*/
- public void setRowMatrix(final int row, final BlockFieldMatrix<T> matrix) {
+ public void setRowMatrix(final int row, final BlockFieldMatrix<T> matrix)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
checkRowIndex(row);
final int nCols = getColumnDimension();
if ((matrix.getRowDimension() != 1) ||
@@ -892,7 +919,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldMatrix<T> getColumnMatrix(final int column) {
+ public FieldMatrix<T> getColumnMatrix(final int column)
+ throws OutOfRangeException {
checkColumnIndex(column);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, 1);
@@ -920,7 +948,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setColumnMatrix(final int column, final FieldMatrix<T> matrix) {
+ public void setColumnMatrix(final int column, final FieldMatrix<T> matrix)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
try {
setColumnMatrix(column, (BlockFieldMatrix<T>) matrix);
} catch (ClassCastException cce) {
@@ -935,12 +964,12 @@ public class BlockFieldMatrix<T extends
* @param column Column to be set.
* @param matrix Column matrix (must have one column and the same number of rows
* as the instance).
- * @throws org.apache.commons.math3.exception.OutOfRangeException if
- * the specified column index is invalid.
* @throws MatrixDimensionMismatchException if the matrix dimensions do
* not match one instance column.
+ * @throws OutOfRangeException if the specified column index is invalid.
*/
- void setColumnMatrix(final int column, final BlockFieldMatrix<T> matrix) {
+ void setColumnMatrix(final int column, final BlockFieldMatrix<T> matrix)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
checkColumnIndex(column);
final int nRows = getRowDimension();
if ((matrix.getRowDimension() != nRows) ||
@@ -972,7 +1001,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldVector<T> getRowVector(final int row) {
+ public FieldVector<T> getRowVector(final int row)
+ throws OutOfRangeException {
checkRowIndex(row);
final T[] outData = buildArray(getField(), columns);
@@ -992,7 +1022,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setRowVector(final int row, final FieldVector<T> vector) {
+ public void setRowVector(final int row, final FieldVector<T> vector)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
try {
setRow(row, ((ArrayFieldVector<T>) vector).getDataRef());
} catch (ClassCastException cce) {
@@ -1002,7 +1033,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public FieldVector<T> getColumnVector(final int column) {
+ public FieldVector<T> getColumnVector(final int column)
+ throws OutOfRangeException {
checkColumnIndex(column);
final T[] outData = buildArray(getField(), rows);
@@ -1024,7 +1056,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setColumnVector(final int column, final FieldVector<T> vector) {
+ public void setColumnVector(final int column, final FieldVector<T> vector)
+ throws OutOfRangeException, MatrixDimensionMismatchException {
try {
setColumn(column, ((ArrayFieldVector<T>) vector).getDataRef());
} catch (ClassCastException cce) {
@@ -1034,7 +1067,7 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public T[] getRow(final int row) {
+ public T[] getRow(final int row) throws OutOfRangeException {
checkRowIndex(row);
final T[] out = buildArray(getField(), columns);
@@ -1054,7 +1087,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setRow(final int row, final T[] array) {
+ public void setRow(final int row, final T[] array)
+ throws OutOfRangeException, MatrixDimensionMismatchException {
checkRowIndex(row);
final int nCols = getColumnDimension();
if (array.length != nCols) {
@@ -1075,7 +1109,7 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public T[] getColumn(final int column) {
+ public T[] getColumn(final int column) throws OutOfRangeException {
checkColumnIndex(column);
final T[] out = buildArray(getField(), rows);
@@ -1097,7 +1131,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setColumn(final int column, final T[] array) {
+ public void setColumn(final int column, final T[] array)
+ throws MatrixDimensionMismatchException, OutOfRangeException {
checkColumnIndex(column);
final int nRows = getRowDimension();
if (array.length != nRows) {
@@ -1120,7 +1155,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public T getEntry(final int row, final int column) {
+ public T getEntry(final int row, final int column)
+ throws OutOfRangeException {
checkRowIndex(row);
checkColumnIndex(column);
@@ -1134,7 +1170,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void setEntry(final int row, final int column, final T value) {
+ public void setEntry(final int row, final int column, final T value)
+ throws OutOfRangeException {
checkRowIndex(row);
checkColumnIndex(column);
@@ -1148,7 +1185,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void addToEntry(final int row, final int column, final T increment) {
+ public void addToEntry(final int row, final int column, final T increment)
+ throws OutOfRangeException {
checkRowIndex(row);
checkColumnIndex(column);
@@ -1163,7 +1201,8 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public void multiplyEntry(final int row, final int column, final T factor) {
+ public void multiplyEntry(final int row, final int column, final T factor)
+ throws OutOfRangeException {
checkRowIndex(row);
checkColumnIndex(column);
@@ -1229,7 +1268,7 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public T[] operate(final T[] v) {
+ public T[] operate(final T[] v) throws DimensionMismatchException {
if (v.length != columns) {
throw new DimensionMismatchException(v.length, columns);
}
@@ -1270,7 +1309,7 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
- public T[] preMultiply(final T[] v) {
+ public T[] preMultiply(final T[] v) throws DimensionMismatchException {
if (v.length != rows) {
throw new DimensionMismatchException(v.length, rows);
@@ -1367,7 +1406,8 @@ public class BlockFieldMatrix<T extends
@Override
public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor,
final int startRow, final int endRow,
- final int startColumn, final int endColumn) {
+ final int startColumn, final int endColumn)
+ throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
@@ -1396,7 +1436,8 @@ public class BlockFieldMatrix<T extends
@Override
public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor,
final int startRow, final int endRow,
- final int startColumn, final int endColumn) {
+ final int startColumn, final int endColumn)
+ throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
@@ -1474,8 +1515,9 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn) {
+ final int startRow, final int endRow,
+ final int startColumn, final int endColumn)
+ throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
@@ -1503,8 +1545,9 @@ public class BlockFieldMatrix<T extends
/** {@inheritDoc} */
@Override
public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor,
- final int startRow, final int endRow,
- final int startColumn, final int endColumn) {
+ final int startRow, final int endRow,
+ final int startColumn, final int endColumn)
+ throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java?rev=1395452&r1=1395451&r2=1395452&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java Mon Oct 8 05:16:27 2012
@@ -250,12 +250,14 @@ public interface FieldMatrix<T extends F
* @throws NoDataException if a row or column of {@code subMatrix} is empty.
* @throws DimensionMismatchException if {@code subMatrix} is not
* rectangular (not all rows have the same length).
+ * @throws NumberIsTooSmallException if {@code endRow < startRow} or
+ * {@code endColumn < startColumn}.
* @throws NullArgumentException if {@code subMatrix} is {@code null}.
* @since 2.0
*/
void setSubMatrix(T[][] subMatrix, int row, int column)
throws DimensionMismatchException, OutOfRangeException,
- NullArgumentException, NoDataException;
+ NoDataException, NullArgumentException, NumberIsTooSmallException;
/**
* Get the entries in row number {@code row}