- filled the "throws" clause of Array2DRowRealMatrix,
  - corrected some method signatures in RealMatrix and AbstractRealMatrix accordingly,
  - in AbstractRealMatrix, removed "abstract implementations" of some methods specified in interface RealMatrix, as they serve no purpose.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1388154 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-09-20 18:50:45 +00:00
parent 7a74137904
commit b2cea08e85
3 changed files with 64 additions and 55 deletions

View File

@ -73,9 +73,6 @@ public abstract class AbstractRealMatrix
} }
} }
/** {@inheritDoc} */
public abstract RealMatrix createMatrix(final int rowDimension, final int columnDimension);
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract RealMatrix copy(); public abstract RealMatrix copy();
@ -585,12 +582,6 @@ public abstract class AbstractRealMatrix
} }
} }
/** {@inheritDoc} */
public abstract double getEntry(int row, int column);
/** {@inheritDoc} */
public abstract void setEntry(int row, int column, double value);
/** {@inheritDoc} */ /** {@inheritDoc} */
public void addToEntry(int row, int column, double increment) public void addToEntry(int row, int column, double increment)
throws OutOfRangeException { throws OutOfRangeException {

View File

@ -20,9 +20,12 @@ package org.apache.commons.math3.linear;
import java.io.Serializable; import java.io.Serializable;
import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.NoDataException;
import org.apache.commons.math3.exception.MathIllegalStateException; import org.apache.commons.math3.exception.MathIllegalStateException;
import org.apache.commons.math3.exception.NoDataException;
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.exception.util.LocalizedFormats;
import org.apache.commons.math3.util.MathUtils; import org.apache.commons.math3.util.MathUtils;
@ -49,10 +52,12 @@ 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 org.apache.commons.math3.exception.NotStrictlyPositiveException * @throws NotStrictlyPositiveException if the row or column dimension is
* if the row or column dimension is not positive. * not positive.
*/ */
public Array2DRowRealMatrix(final int rowDimension, final int columnDimension) { public Array2DRowRealMatrix(final int rowDimension,
final int columnDimension)
throws NotStrictlyPositiveException {
super(rowDimension, columnDimension); super(rowDimension, columnDimension);
data = new double[rowDimension][columnDimension]; data = new double[rowDimension][columnDimension];
} }
@ -86,13 +91,14 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @param d Data for new matrix. * @param d Data for new matrix.
* @param copyArray if {@code true}, the input array will be copied, * @param copyArray if {@code true}, the input array will be copied,
* otherwise it will be referenced. * otherwise it will be referenced.
* @throws DimensionMismatchException if {@code d} is not rectangular * @throws DimensionMismatchException if {@code d} is not rectangular.
* (not all rows have the same length) or empty. * @throws NoDataException if {@code d} row or colum dimension is zero.
* @throws NullArgumentException if {@code d} is {@code null}. * @throws NullArgumentException if {@code d} is {@code null}.
* @throws NoDataException if there are not at least one row and one column.
* @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 {
@ -132,9 +138,9 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@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);
} }
@ -145,14 +151,15 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
} }
/** /**
* Compute the sum of this matrix with {@code m}. * Compute the sum of {@code this} and {@code m}.
* *
* @param m Matrix to be added. * @param m Matrix to be added.
* @return {@code this} + m. * @return {@code this + m}.
* @throws MatrixDimensionMismatchException * @throws MatrixDimensionMismatchException if {@code m} is not the same
* if {@code m} is not the same size as this matrix. * size as {@code this}.
*/ */
public Array2DRowRealMatrix add(final Array2DRowRealMatrix m) { public Array2DRowRealMatrix add(final Array2DRowRealMatrix m)
throws MatrixDimensionMismatchException {
// Safety check. // Safety check.
MatrixUtils.checkAdditionCompatible(this, m); MatrixUtils.checkAdditionCompatible(this, m);
@ -172,15 +179,15 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
} }
/** /**
* Subtract {@code m} from this matrix. * Returns {@code this} minus {@code m}.
* *
* @param m Matrix to be subtracted. * @param m Matrix to be subtracted.
* @return {@code this} - m. * @return {@code this - m}
* @throws MatrixDimensionMismatchException * @throws MatrixDimensionMismatchException if {@code m} is not the same
* if {@code m} is not the same size as this matrix. * size as {@code this}.
*/ */
public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) { public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m)
// Safety check. throws MatrixDimensionMismatchException {
MatrixUtils.checkSubtractionCompatible(this, m); MatrixUtils.checkSubtractionCompatible(this, m);
final int rowCount = getRowDimension(); final int rowCount = getRowDimension();
@ -199,15 +206,15 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
} }
/** /**
* Postmultiplying this matrix by {@code m}. * Returns the result of postmultiplying {@code this} by {@code m}.
* *
* @param m Matrix to postmultiply by. * @param m matrix to postmultiply by
* @return {@code this} * m. * @return {@code this * m}
* @throws DimensionMismatchException if the number of columns of this * @throws DimensionMismatchException if
* matrix is not equal to the number of rows of {@code m}. * {@code columnDimension(this) != rowDimension(m)}
*/ */
public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) { public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m)
// Safety check. throws DimensionMismatchException {
MatrixUtils.checkMultiplicationCompatible(this, m); MatrixUtils.checkMultiplicationCompatible(this, m);
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
@ -257,8 +264,10 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setSubMatrix(final double[][] subMatrix, public void setSubMatrix(final double[][] subMatrix, final int row,
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);
@ -290,29 +299,33 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public double getEntry(final int row, final int column)
public double getEntry(final int row, final int column) { throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
return data[row][column]; return data[row][column];
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@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;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void addToEntry(final int row, final int column, final double increment) { public void addToEntry(final int row, final int column,
final double increment)
throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
data[row][column] += increment; data[row][column] += increment;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void multiplyEntry(final int row, final int column, final double factor) { public void multiplyEntry(final int row, final int column,
final double factor)
throws OutOfRangeException {
MatrixUtils.checkMatrixIndex(this, row, column); MatrixUtils.checkMatrixIndex(this, row, column);
data[row][column] *= factor; data[row][column] *= factor;
} }
@ -331,7 +344,8 @@ 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) {
@ -351,7 +365,8 @@ 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) {
@ -405,7 +420,8 @@ 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);
@ -422,7 +438,8 @@ 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);
@ -468,7 +485,8 @@ 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);
@ -485,7 +503,8 @@ 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);
@ -518,8 +537,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
* @param in Data to copy. * @param in Data to copy.
* @throws NoDataException if the input array is empty. * @throws NoDataException if the input array is empty.
* @throws DimensionMismatchException if the input array is not rectangular. * @throws DimensionMismatchException if the input array is not rectangular.
* @throws NullArgumentException if * @throws NullArgumentException if the input array is {@code null}.
* the input array is {@code null}.
*/ */
private void copyIn(final double[][] in) private void copyIn(final double[][] in)
throws DimensionMismatchException, NoDataException, NullArgumentException { throws DimensionMismatchException, NoDataException, NullArgumentException {

View File

@ -69,7 +69,7 @@ public interface RealMatrix extends AnyMatrix {
throws MatrixDimensionMismatchException; throws MatrixDimensionMismatchException;
/** /**
* Computes {@code this} minus {@code m}. * Returns {@code this} minus {@code m}.
* *
* @param m matrix to be subtracted * @param m matrix to be subtracted
* @return {@code this - m} * @return {@code this - m}