MATH-1589: Remove spurious "throws" clause.

This commit is contained in:
Gilles Sadowski 2023-03-06 02:30:45 +01:00
parent 5f76f8384d
commit 6c493a4f20
1 changed files with 24 additions and 51 deletions

View File

@ -22,10 +22,7 @@ import java.io.Serializable;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
/** /**
@ -49,12 +46,11 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* *
* @param rowDimension Number of rows in the new matrix. * @param rowDimension Number of rows in the new matrix.
* @param columnDimension Number of columns in the new matrix. * @param columnDimension Number of columns in the new matrix.
* @throws NotStrictlyPositiveException if the row or column dimension is * @throws org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException
* not positive. * if the row or column dimension is not positive.
*/ */
public Array2DRowRealMatrix(final int rowDimension, public Array2DRowRealMatrix(final int rowDimension,
final int columnDimension) final int columnDimension) {
throws NotStrictlyPositiveException {
super(rowDimension, columnDimension); super(rowDimension, columnDimension);
data = new double[rowDimension][columnDimension]; data = new double[rowDimension][columnDimension];
} }
@ -72,8 +68,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws NullArgumentException if {@code d} is {@code null}. * @throws NullArgumentException if {@code d} is {@code null}.
* @see #Array2DRowRealMatrix(double[][], boolean) * @see #Array2DRowRealMatrix(double[][], boolean)
*/ */
public Array2DRowRealMatrix(final double[][] d) public Array2DRowRealMatrix(final double[][] d) {
throws DimensionMismatchException, NoDataException, NullArgumentException {
copyIn(d); copyIn(d);
} }
@ -93,9 +88,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws NullArgumentException if {@code d} is {@code null}. * @throws NullArgumentException if {@code d} is {@code null}.
* @see #Array2DRowRealMatrix(double[][]) * @see #Array2DRowRealMatrix(double[][])
*/ */
public Array2DRowRealMatrix(final double[][] d, final boolean copyArray) public Array2DRowRealMatrix(final double[][] d, final boolean copyArray) {
throws DimensionMismatchException, NoDataException,
NullArgumentException {
if (copyArray) { if (copyArray) {
copyIn(d); copyIn(d);
} else { } else {
@ -137,8 +130,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public RealMatrix createMatrix(final int rowDimension, public RealMatrix createMatrix(final int rowDimension,
final int columnDimension) final int columnDimension) {
throws NotStrictlyPositiveException {
return new Array2DRowRealMatrix(rowDimension, columnDimension); return new Array2DRowRealMatrix(rowDimension, columnDimension);
} }
@ -156,8 +148,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws MatrixDimensionMismatchException if {@code m} is not the same * @throws MatrixDimensionMismatchException if {@code m} is not the same
* size as {@code this}. * size as {@code this}.
*/ */
public Array2DRowRealMatrix add(final Array2DRowRealMatrix m) public Array2DRowRealMatrix add(final Array2DRowRealMatrix m) {
throws MatrixDimensionMismatchException {
// Safety check. // Safety check.
checkAdd(m); checkAdd(m);
@ -184,8 +175,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws MatrixDimensionMismatchException if {@code m} is not the same * @throws MatrixDimensionMismatchException if {@code m} is not the same
* size as {@code this}. * size as {@code this}.
*/ */
public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) {
throws MatrixDimensionMismatchException {
checkAdd(m); checkAdd(m);
final int rowCount = getRowDimension(); final int rowCount = getRowDimension();
@ -211,8 +201,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws DimensionMismatchException if * @throws DimensionMismatchException if
* {@code columnDimension(this) != rowDimension(m)} * {@code columnDimension(this) != rowDimension(m)}
*/ */
public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) {
throws DimensionMismatchException {
checkMultiply(m); checkMultiply(m);
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
@ -263,9 +252,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setSubMatrix(final double[][] subMatrix, final int row, public void setSubMatrix(final double[][] subMatrix, final int row,
final int column) final int column) {
throws NoDataException, OutOfRangeException,
DimensionMismatchException, NullArgumentException {
if (data == null) { if (data == null) {
if (row > 0) { if (row > 0) {
throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
@ -297,8 +284,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double getEntry(final int row, final int column) public double getEntry(final int row, final int column) {
throws OutOfRangeException {
try { try {
return data[row][column]; return data[row][column];
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
@ -311,8 +297,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setEntry(final int row, final int column, final double value) public void setEntry(final int row, final int column, final double value) {
throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
data[row][column] = value; data[row][column] = value;
} }
@ -320,8 +305,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void addToEntry(final int row, final int column, public void addToEntry(final int row, final int column,
final double increment) final double increment) {
throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
data[row][column] += increment; data[row][column] += increment;
} }
@ -329,8 +313,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void multiplyEntry(final int row, final int column, public void multiplyEntry(final int row, final int column,
final double factor) final double factor) {
throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
data[row][column] *= factor; data[row][column] *= factor;
} }
@ -349,8 +332,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double[] operate(final double[] v) public double[] operate(final double[] v) {
throws DimensionMismatchException {
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
final int nCols = this.getColumnDimension(); final int nCols = this.getColumnDimension();
if (v.length != nCols) { if (v.length != nCols) {
@ -370,8 +352,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double[] preMultiply(final double[] v) public double[] preMultiply(final double[] v) {
throws DimensionMismatchException {
final int nRows = getRowDimension(); final int nRows = getRowDimension();
final int nCols = getColumnDimension(); final int nCols = getColumnDimension();
if (v.length != nRows) { if (v.length != nRows) {
@ -393,8 +374,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public RealMatrix getSubMatrix(final int startRow, final int endRow, public RealMatrix getSubMatrix(final int startRow, final int endRow,
final int startColumn, final int endColumn) final int startColumn, final int endColumn) {
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
final int rowCount = endRow - startRow + 1; final int rowCount = endRow - startRow + 1;
final int columnCount = endColumn - startColumn + 1; final int columnCount = endColumn - startColumn + 1;
@ -442,8 +422,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
@Override @Override
public double walkInRowOrder(final RealMatrixChangingVisitor visitor, public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) final int startColumn, final int endColumn) {
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -460,8 +439,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
@Override @Override
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor, public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) final int startColumn, final int endColumn) {
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -507,8 +485,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
@Override @Override
public double walkInColumnOrder(final RealMatrixChangingVisitor visitor, public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) final int startColumn, final int endColumn) {
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -525,8 +502,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
@Override @Override
public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor, public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) final int startColumn, final int endColumn) {
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -561,15 +537,13 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @throws DimensionMismatchException if the input array is not rectangular. * @throws DimensionMismatchException if the input array is not rectangular.
* @throws NullArgumentException if the input array is {@code null}. * @throws NullArgumentException if the input array is {@code null}.
*/ */
private void copyIn(final double[][] in) private void copyIn(final double[][] in) {
throws DimensionMismatchException, NoDataException, NullArgumentException {
setSubMatrix(in, 0, 0); setSubMatrix(in, 0, 0);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double[] getRow(final int row) public double[] getRow(final int row) {
throws OutOfRangeException {
MatrixUtils.checkRowIndex(this, row); MatrixUtils.checkRowIndex(this, row);
final int nCols = getColumnDimension(); final int nCols = getColumnDimension();
final double[] out = new double[nCols]; final double[] out = new double[nCols];
@ -580,8 +554,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setRow(final int row, public void setRow(final int row,
final double[] array) final double[] array) {
throws OutOfRangeException, MatrixDimensionMismatchException {
MatrixUtils.checkRowIndex(this, row); MatrixUtils.checkRowIndex(this, row);
final int nCols = getColumnDimension(); final int nCols = getColumnDimension();
if (array.length != nCols) { if (array.length != nCols) {