MATH-425
Removed redundant exception "throws" clauses. Javadoc cleanup. Throwing "NoDataException" instead of "ZeroException" when row or column data is missing. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1038403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b1676aecb4
commit
0b3c388aeb
|
@ -37,11 +37,13 @@ import org.apache.commons.math.exception.util.LocalizedFormats;
|
|||
* <p>All the methods implemented here use {@link #getEntry(int, int)} to access
|
||||
* matrix elements. Derived class can provide faster implementations. </p>
|
||||
*
|
||||
* @param <T> the type of the field elements
|
||||
* @param <T> Type of the field elements.
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements FieldMatrix<T> {
|
||||
public abstract class AbstractFieldMatrix<T extends FieldElement<T>>
|
||||
implements FieldMatrix<T> {
|
||||
/** Field to which the elements belong. */
|
||||
private final Field<T> field;
|
||||
|
||||
|
@ -170,15 +172,13 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public abstract FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension)
|
||||
throws IllegalArgumentException;
|
||||
public abstract FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public abstract FieldMatrix<T> copy();
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> add(FieldMatrix<T> m) throws IllegalArgumentException {
|
||||
|
||||
public FieldMatrix<T> add(FieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkAdditionCompatible(m);
|
||||
|
||||
|
@ -192,12 +192,10 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> subtract(final FieldMatrix<T> m) throws IllegalArgumentException {
|
||||
|
||||
public FieldMatrix<T> subtract(final FieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkSubtractionCompatible(m);
|
||||
|
||||
|
@ -211,7 +209,6 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -227,12 +224,10 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> scalarMultiply(final T d) {
|
||||
|
||||
final int rowCount = getRowDimension();
|
||||
final int columnCount = getColumnDimension();
|
||||
final FieldMatrix<T> out = createMatrix(rowCount, columnCount);
|
||||
|
@ -243,13 +238,10 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> multiply(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public FieldMatrix<T> multiply(final FieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkMultiplicationCompatible(m);
|
||||
|
||||
|
@ -268,18 +260,15 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> preMultiply(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
public FieldMatrix<T> preMultiply(final FieldMatrix<T> m) {
|
||||
return m.multiply(this);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public T[][] getData() {
|
||||
|
||||
final T[][] data = buildArray(field, getRowDimension(), getColumnDimension());
|
||||
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
|
@ -290,13 +279,11 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldMatrix<T> getSubMatrix(final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn) {
|
||||
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
|
||||
final FieldMatrix<T> subMatrix =
|
||||
|
@ -635,8 +622,7 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public T[] operate(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
public T[] operate(final T[] v) {
|
||||
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
|
@ -657,8 +643,7 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldVector<T> operate(final FieldVector<T> v)
|
||||
throws IllegalArgumentException {
|
||||
public FieldVector<T> operate(final FieldVector<T> v) {
|
||||
try {
|
||||
return new ArrayFieldVector<T>(operate(((ArrayFieldVector<T>) v).getDataRef()), false);
|
||||
} catch (ClassCastException cce) {
|
||||
|
@ -682,8 +667,7 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public T[] preMultiply(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
public T[] preMultiply(final T[] v) {
|
||||
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
|
@ -704,12 +688,10 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public FieldVector<T> preMultiply(final FieldVector<T> v)
|
||||
throws IllegalArgumentException {
|
||||
public FieldVector<T> preMultiply(final FieldVector<T> v) {
|
||||
try {
|
||||
return new ArrayFieldVector<T>(preMultiply(((ArrayFieldVector<T>) v).getDataRef()), false);
|
||||
} catch (ClassCastException cce) {
|
||||
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
if (v.getDimension() != nRows) {
|
||||
|
|
|
@ -57,8 +57,7 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public abstract RealMatrix createMatrix(final int rowDimension, final int columnDimension)
|
||||
throws IllegalArgumentException;
|
||||
public abstract RealMatrix createMatrix(final int rowDimension, final int columnDimension);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public abstract RealMatrix copy();
|
||||
|
@ -271,7 +270,6 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
public void copySubMatrix(final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn,
|
||||
final double[][] destination) {
|
||||
|
||||
// safety checks
|
||||
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
|
||||
final int rowsCount = endRow + 1 - startRow;
|
||||
|
@ -310,7 +308,6 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination) {
|
||||
|
||||
// safety checks
|
||||
MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns);
|
||||
if ((destination.length < selectedRows.length) ||
|
||||
|
@ -552,9 +549,7 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double[] operate(final double[] v)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public double[] operate(final double[] v) {
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
if (v.length != nCols) {
|
||||
|
@ -574,8 +569,7 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealVector operate(final RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector operate(final RealVector v) {
|
||||
try {
|
||||
return new ArrayRealVector(operate(((ArrayRealVector) v).getDataRef()), false);
|
||||
} catch (ClassCastException cce) {
|
||||
|
@ -599,8 +593,7 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double[] preMultiply(final double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public double[] preMultiply(final double[] v) {
|
||||
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
|
@ -621,8 +614,7 @@ public abstract class AbstractRealMatrix implements RealMatrix {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealVector preMultiply(final RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector preMultiply(final RealVector v) {
|
||||
try {
|
||||
return new ArrayRealVector(preMultiply(((ArrayRealVector) v).getDataRef()), false);
|
||||
} catch (ClassCastException cce) {
|
||||
|
|
|
@ -39,9 +39,10 @@ public abstract class AbstractRealVector implements RealVector {
|
|||
|
||||
/**
|
||||
* Check if instance and specified vectors have the same dimension.
|
||||
* @param v vector to compare instance with
|
||||
* @exception IllegalArgumentException if the vectors do not
|
||||
* have the same dimension
|
||||
*
|
||||
* @param v Vector to compare instance with.
|
||||
* @throws DimensionMismatchException if the vectors do not
|
||||
* have the same dimension.
|
||||
*/
|
||||
protected void checkVectorDimensions(RealVector v) {
|
||||
checkVectorDimensions(v.getDimension());
|
||||
|
@ -50,12 +51,11 @@ public abstract class AbstractRealVector implements RealVector {
|
|||
/**
|
||||
* Check if instance dimension is equal to some expected value.
|
||||
*
|
||||
* @param n expected dimension.
|
||||
* @param n Expected dimension.
|
||||
* @throws DimensionMismatchException if the dimension is
|
||||
* inconsistent with vector size
|
||||
* inconsistent with the vector size.
|
||||
*/
|
||||
protected void checkVectorDimensions(int n)
|
||||
throws DimensionMismatchException {
|
||||
protected void checkVectorDimensions(int n) {
|
||||
int d = getDimension();
|
||||
if (d != n) {
|
||||
throw new DimensionMismatchException(d, n);
|
||||
|
@ -823,5 +823,4 @@ public abstract class AbstractRealVector implements RealVector {
|
|||
throw new MathUnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,8 +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.MathUserException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
|
||||
/**
|
||||
|
@ -36,11 +37,11 @@ import org.apache.commons.math.exception.util.LocalizedFormats;
|
|||
* @param <T> the type of the field elements
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T> implements Serializable {
|
||||
|
||||
public class Array2DRowFieldMatrix<T extends FieldElement<T>>
|
||||
extends AbstractFieldMatrix<T>
|
||||
implements Serializable {
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 7260756672015356458L;
|
||||
|
||||
/** Entries of the matrix */
|
||||
protected T[][] data;
|
||||
|
||||
|
@ -53,57 +54,57 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a new FieldMatrix<T> with the supplied row and column dimensions.
|
||||
* Create a new {@code FieldMatrix<T>} with the supplied row and column dimensions.
|
||||
*
|
||||
* @param field field to which the elements belong
|
||||
* @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
|
||||
* @param field Field to which the elements belong.
|
||||
* @param rowDimension Number of rows in the new matrix.
|
||||
* @param columnDimension Number of columns in the new matrix.
|
||||
* @throws org.apache.commons.math.exception.NotStrictlyPositiveException
|
||||
* if row or column dimension is not positive.
|
||||
*/
|
||||
public Array2DRowFieldMatrix(final Field<T> field,
|
||||
final int rowDimension, final int columnDimension)
|
||||
throws IllegalArgumentException {
|
||||
final int rowDimension,
|
||||
final int columnDimension) {
|
||||
super(field, rowDimension, columnDimension);
|
||||
data = buildArray(field, rowDimension, columnDimension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new FieldMatrix<T> using the input array as the underlying
|
||||
* Create a new {@code FieldMatrix<T>} using the input array as the underlying
|
||||
* data array.
|
||||
* <p>The input array is copied, not referenced. This constructor has
|
||||
* the same effect as calling {@link #Array2DRowFieldMatrix(FieldElement[][], boolean)}
|
||||
* with the second argument set to <code>true</code>.</p>
|
||||
* with the second argument set to {@code true}.</p>
|
||||
*
|
||||
* @param d data for new matrix
|
||||
* @throws IllegalArgumentException if <code>d</code> is not rectangular
|
||||
* (not all rows have the same length) or empty
|
||||
* @throws NullPointerException if <code>d</code> is null
|
||||
* @param d Data for the new matrix.
|
||||
* @throws DimensionMismatchException if {@code d} is not rectangular.
|
||||
* @throws org.apache.commons.math.exception.NullArgumentException if
|
||||
* {@code d} is {@code null}.
|
||||
* @throws NoDataException if there are not at least one row and one column.
|
||||
* @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
|
||||
*/
|
||||
public Array2DRowFieldMatrix(final T[][] d)
|
||||
throws IllegalArgumentException, NullPointerException {
|
||||
public Array2DRowFieldMatrix(final T[][] d) {
|
||||
super(extractField(d));
|
||||
copyIn(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new FieldMatrix<T> using the input array as the underlying
|
||||
* Create a new {@code FieldMatrix<T>} using the input array as the underlying
|
||||
* data array.
|
||||
* <p>If an array is built specially in order to be embedded in a
|
||||
* FieldMatrix<T> and not used directly, the <code>copyArray</code> may be
|
||||
* set to <code>false</code. This will prevent the copying and improve
|
||||
* {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
|
||||
* set to {@code false}. This will prevent the copying and improve
|
||||
* performance as no new array will be built and no data will be copied.</p>
|
||||
* @param d data for new matrix
|
||||
* @param copyArray if true, the input array will be copied, otherwise
|
||||
* it will be referenced
|
||||
* @throws IllegalArgumentException if <code>d</code> is not rectangular
|
||||
* (not all rows have the same length) or empty
|
||||
* @throws NullPointerException if <code>d</code> is null
|
||||
*
|
||||
* @param d Data for the new matrix.
|
||||
* @param copyArray Whether to copy or reference the input array.
|
||||
* @throws DimensionMismatchException if {@code d} is not rectangular.
|
||||
* @throws NoDataException if there are not at least one row and one column.
|
||||
* @throws org.apache.commons.math.exception.NullArgumentException
|
||||
* if {@code d} is {@code null}.
|
||||
* @see #Array2DRowFieldMatrix(FieldElement[][])
|
||||
*/
|
||||
public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray)
|
||||
throws IllegalArgumentException, NullPointerException {
|
||||
public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray) {
|
||||
super(extractField(d));
|
||||
if (copyArray) {
|
||||
copyIn(d);
|
||||
|
@ -113,18 +114,15 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
final int nRows = d.length;
|
||||
if (nRows == 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
}
|
||||
final int nCols = d[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 (d[r].length != nCols) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length);
|
||||
throw new DimensionMismatchException(nCols, d[r].length);
|
||||
}
|
||||
}
|
||||
data = d;
|
||||
|
@ -132,12 +130,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a new (column) FieldMatrix<T> using <code>v</code> as the
|
||||
* data for the unique column of the <code>v.length x 1</code> matrix
|
||||
* created.
|
||||
* <p>The input array is copied, not referenced.</p>
|
||||
* Create a new (column) {@code FieldMatrix<T>} using {@code v} as the
|
||||
* data for the unique column of the created matrix.
|
||||
* The input array is copied.
|
||||
*
|
||||
* @param v column vector holding data for new matrix
|
||||
* @param v Column vector holding data for new matrix.
|
||||
*/
|
||||
public Array2DRowFieldMatrix(final T[] v) {
|
||||
super(extractField(v));
|
||||
|
@ -150,8 +147,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension)
|
||||
throws IllegalArgumentException {
|
||||
public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) {
|
||||
return new Array2DRowFieldMatrix<T>(getField(), rowDimension, columnDimension);
|
||||
}
|
||||
|
||||
|
@ -161,27 +157,15 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
return new Array2DRowFieldMatrix<T>(copyOut(), false);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public FieldMatrix<T> add(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
return add((Array2DRowFieldMatrix<T>) m);
|
||||
} catch (ClassCastException cce) {
|
||||
return super.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the sum of this and <code>m</code>.
|
||||
* Add {@code m} to this matrix.
|
||||
*
|
||||
* @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 org.apache.commons.math.exception.MatrixDimensionMismatchException
|
||||
* if {@code m} is not the same size as this matrix.
|
||||
*/
|
||||
public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkAdditionCompatible(m);
|
||||
|
||||
|
@ -198,30 +182,17 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
return new Array2DRowFieldMatrix<T>(outData, false);
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public FieldMatrix<T> subtract(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
return subtract((Array2DRowFieldMatrix<T>) m);
|
||||
} catch (ClassCastException cce) {
|
||||
return super.subtract(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute this minus <code>m</code>.
|
||||
* Subtract {@code m} from this matrix.
|
||||
*
|
||||
* @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 org.apache.commons.math.exception.MatrixDimensionMismatchException
|
||||
* if {@code m} is not the same size as this matrix.
|
||||
*/
|
||||
public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkSubtractionCompatible(m);
|
||||
|
||||
|
@ -241,27 +212,15 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public FieldMatrix<T> multiply(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
return multiply((Array2DRowFieldMatrix<T>) m);
|
||||
} catch (ClassCastException cce) {
|
||||
return super.multiply(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of postmultiplying this by <code>m</code>.
|
||||
* @param m matrix to postmultiply by
|
||||
* @return this*m
|
||||
* @throws IllegalArgumentException
|
||||
* if columnDimension(this) != rowDimension(m)
|
||||
* Postmultiplying this matrix by {@code m}.
|
||||
*
|
||||
* @param m Matrix to postmultiply by.
|
||||
* @return {@code this} * m.
|
||||
* @throws DimensionMismatchException if the number of columns of this
|
||||
* matrix is not equal to the number of rows of {@code m}.
|
||||
*/
|
||||
public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m) {
|
||||
// safety check
|
||||
checkMultiplicationCompatible(m);
|
||||
|
||||
|
@ -292,11 +251,10 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the underlying data array.
|
||||
* <p>
|
||||
* Does <strong>not</strong> make a fresh copy of the underlying data.</p>
|
||||
* Get a reference to the underlying data array.
|
||||
* This methods returns internal data, <strong>not</strong> fresh copy of it.
|
||||
*
|
||||
* @return 2-dimensional array of entries
|
||||
* @return the 2-dimensional array of entries.
|
||||
*/
|
||||
public T[][] getDataRef() {
|
||||
return data;
|
||||
|
@ -307,29 +265,24 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
|
||||
if (data == null) {
|
||||
if (row > 0) {
|
||||
throw MathRuntimeException.createIllegalStateException(
|
||||
LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
|
||||
throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
|
||||
}
|
||||
if (column > 0) {
|
||||
throw MathRuntimeException.createIllegalStateException(
|
||||
LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
|
||||
throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
|
||||
}
|
||||
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);
|
||||
}
|
||||
data = buildArray(getField(), subMatrix.length, nCols);
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
if (subMatrix[i].length != nCols) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[i].length);
|
||||
throw new DimensionMismatchException(nCols, subMatrix[i].length);
|
||||
}
|
||||
System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
|
||||
}
|
||||
|
@ -389,13 +342,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public T[] operate(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
public T[] operate(final T[] v) {
|
||||
final int nRows = this.getRowDimension();
|
||||
final int nCols = this.getColumnDimension();
|
||||
if (v.length != nCols) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols);
|
||||
throw new DimensionMismatchException(v.length, nCols);
|
||||
}
|
||||
final T[] out = buildArray(getField(), nRows);
|
||||
for (int row = 0; row < nRows; row++) {
|
||||
|
@ -411,14 +362,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public T[] preMultiply(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public T[] preMultiply(final T[] v) {
|
||||
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 T[] out = buildArray(getField(), nCols);
|
||||
|
@ -431,7 +379,6 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -561,7 +508,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a fresh copy of the underlying data array.
|
||||
* Get a fresh copy of the underlying data array.
|
||||
*
|
||||
* @return a copy of the underlying data array.
|
||||
*/
|
||||
|
@ -576,17 +523,15 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>> extends AbstractFi
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces data with a fresh copy of the input array.
|
||||
* <p>
|
||||
* Verifies that the input array is rectangular and non-empty.</p>
|
||||
* Replace data with a fresh copy of the input array.
|
||||
*
|
||||
* @param in data to copy in
|
||||
* @throws IllegalArgumentException if input array is empty or not
|
||||
* rectangular
|
||||
* @throws NullPointerException if input array is null
|
||||
* @param in Data to copy.
|
||||
* @throws NoDataException if the input array is empty.
|
||||
* @throws DimensionMismatchException if the input array is not rectangular.
|
||||
* @throws org.apache.commons.math.exception.NullArgumentException if
|
||||
* the input array is {@code null}.
|
||||
*/
|
||||
private void copyIn(final T[][] in) {
|
||||
setSubMatrix(in, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.io.Serializable;
|
|||
|
||||
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math.exception.NullArgumentException;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
|
||||
|
@ -67,32 +67,30 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
/**
|
||||
* Create a new RealMatrix with the supplied row and column dimensions.
|
||||
*
|
||||
* @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
|
||||
* @param rowDimension Number of rows in the new matrix.
|
||||
* @param columnDimension Number of columns in the new matrix.
|
||||
* @throws org.apache.commons.math.exception.NotStrictlyPositiveException
|
||||
* if the row or column dimension is not positive.
|
||||
*/
|
||||
public Array2DRowRealMatrix(final int rowDimension, final int columnDimension)
|
||||
throws IllegalArgumentException {
|
||||
public Array2DRowRealMatrix(final int rowDimension, final int columnDimension) {
|
||||
super(rowDimension, columnDimension);
|
||||
data = new double[rowDimension][columnDimension];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new RealMatrix using the input array as the underlying
|
||||
* Create a new {@code RealMatrix} using the input array as the underlying
|
||||
* data array.
|
||||
* <p>The input array is copied, not referenced. This constructor has
|
||||
* the same effect as calling {@link #Array2DRowRealMatrix(double[][], boolean)}
|
||||
* with the second argument set to <code>true</code>.</p>
|
||||
* with the second argument set to {@code true}.</p>
|
||||
*
|
||||
* @param d data for new matrix
|
||||
* @throws IllegalArgumentException if <code>d</code> is not rectangular
|
||||
* (not all rows have the same length) or empty
|
||||
* @throws NullPointerException if <code>d</code> is null
|
||||
* @param d Data for the new matrix.
|
||||
* @throws DimensionMismatchException if {@code d} is not rectangular.
|
||||
* @throws NoDataException if {@code d} row or colum dimension is zero.
|
||||
* @throws NullPointerException if {@code d} is {@code null}.
|
||||
* @see #Array2DRowRealMatrix(double[][], boolean)
|
||||
*/
|
||||
public Array2DRowRealMatrix(final double[][] d)
|
||||
throws IllegalArgumentException, NullPointerException {
|
||||
public Array2DRowRealMatrix(final double[][] d) {
|
||||
copyIn(d);
|
||||
}
|
||||
|
||||
|
@ -110,7 +108,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
* @throws DimensionMismatchException if {@code d} is not rectangular
|
||||
* (not all rows have the same length) or empty.
|
||||
* @throws NullArgumentException if {@code d} is {@code null}.
|
||||
* @throws ZeroException if there are not at least one row and one column.
|
||||
* @throws NoDataException if there are not at least one row and one column.
|
||||
* @see #Array2DRowRealMatrix(double[][])
|
||||
*/
|
||||
public Array2DRowRealMatrix(final double[][] d, final boolean copyArray) {
|
||||
|
@ -122,11 +120,11 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
final int nRows = d.length;
|
||||
if (nRows == 0) {
|
||||
throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
}
|
||||
final int nCols = d[0].length;
|
||||
if (nCols == 0) {
|
||||
throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
}
|
||||
for (int r = 1; r < nRows; r++) {
|
||||
if (d[r].length != nCols) {
|
||||
|
@ -139,9 +137,8 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
|
||||
/**
|
||||
* Create a new (column) RealMatrix using {@code v} as the
|
||||
* data for the unique column of the {@code v.length x 1} matrix
|
||||
* created.
|
||||
* The input array is copied, not referenced.
|
||||
* data for the unique column of the created matrix.
|
||||
* The input array is copied.
|
||||
*
|
||||
* @param v Column vector holding data for new matrix.
|
||||
*/
|
||||
|
@ -221,13 +218,12 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the result of postmultiplying this matrix with {@code m}.
|
||||
* Postmultiplying this matrix by {@code m}.
|
||||
*
|
||||
* @param m Matrix to postmultiply by.
|
||||
* @return {@code this} * m.
|
||||
* @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
|
||||
* if the column dimension of this matrix is different from the row
|
||||
* dimension of {@code m}.
|
||||
* @throws DimensionMismatchException if the number of columns of this
|
||||
* matrix is not equal to the number of rows of {@code m}.
|
||||
*/
|
||||
public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) {
|
||||
// Safety check.
|
||||
|
@ -260,7 +256,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a reference to the underlying data array.
|
||||
* Get a reference to the underlying data array.
|
||||
*
|
||||
* @return 2-dimensional array of entries.
|
||||
*/
|
||||
|
@ -281,12 +277,12 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
final int nRows = subMatrix.length;
|
||||
if (nRows == 0) {
|
||||
throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
}
|
||||
|
||||
final int nCols = subMatrix[0].length;
|
||||
if (nCols == 0) {
|
||||
throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
}
|
||||
data = new double[subMatrix.length][nCols];
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
|
@ -510,7 +506,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a fresh copy of the underlying data array.
|
||||
* Get a fresh copy of the underlying data array.
|
||||
*
|
||||
* @return a copy of the underlying data array.
|
||||
*/
|
||||
|
@ -525,17 +521,15 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces data with a fresh copy of the input array.
|
||||
* <p>
|
||||
* Verifies that the input array is rectangular and non-empty.</p>
|
||||
* Replace data with a fresh copy of the input array.
|
||||
*
|
||||
* @param in data to copy in
|
||||
* @throws IllegalArgumentException if input array is empty or not
|
||||
* rectangular
|
||||
* @throws NullPointerException if input array is null
|
||||
* @param in Data to copy.
|
||||
* @throws NoDataException if the input array is empty.
|
||||
* @throws DimensionMismatchException if the input array is not rectangular.
|
||||
* @throws org.apache.commons.math.exception.NullArgumentException if
|
||||
* the input array is {@code null}.
|
||||
*/
|
||||
private void copyIn(final double[][] in) {
|
||||
setSubMatrix(in, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -200,8 +200,8 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Construct a vector by appending one vector to another vector.
|
||||
* @param v1 first vector (will be put in front of the new vector)
|
||||
* @param v2 second vector (will be put at back of the new vector)
|
||||
* @param v1 First vector (will be put in front of the new vector).
|
||||
* @param v2 Second vector (will be put at back of the new vector).
|
||||
*/
|
||||
public ArrayRealVector(ArrayRealVector v1, ArrayRealVector v2) {
|
||||
data = new double[v1.data.length + v2.data.length];
|
||||
|
@ -211,8 +211,8 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Construct a vector by appending one vector to another vector.
|
||||
* @param v1 first vector (will be put in front of the new vector)
|
||||
* @param v2 second vector (will be put at back of the new vector)
|
||||
* @param v1 First vector (will be put in front of the new vector).
|
||||
* @param v2 Second vector (will be put at back of the new vector).
|
||||
*/
|
||||
public ArrayRealVector(ArrayRealVector v1, RealVector v2) {
|
||||
final int l1 = v1.data.length;
|
||||
|
@ -226,8 +226,8 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Construct a vector by appending one vector to another vector.
|
||||
* @param v1 first vector (will be put in front of the new vector)
|
||||
* @param v2 second vector (will be put at back of the new vector)
|
||||
* @param v1 First vector (will be put in front of the new vector).
|
||||
* @param v2 Second vector (will be put at back of the new vector).
|
||||
*/
|
||||
public ArrayRealVector(RealVector v1, ArrayRealVector v2) {
|
||||
final int l1 = v1.getDimension();
|
||||
|
@ -241,8 +241,8 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Construct a vector by appending one vector to another vector.
|
||||
* @param v1 first vector (will be put in front of the new vector)
|
||||
* @param v2 second vector (will be put at back of the new vector)
|
||||
* @param v1 First vector (will be put in front of the new vector).
|
||||
* @param v2 Second vector (will be put at back of the new vector).
|
||||
*/
|
||||
public ArrayRealVector(ArrayRealVector v1, double[] v2) {
|
||||
final int l1 = v1.getDimension();
|
||||
|
@ -254,8 +254,8 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Construct a vector by appending one vector to another vector.
|
||||
* @param v1 first vector (will be put in front of the new vector)
|
||||
* @param v2 second vector (will be put at back of the new vector)
|
||||
* @param v1 First vector (will be put in front of the new vector).
|
||||
* @param v2 Second vector (will be put at back of the new vector).
|
||||
*/
|
||||
public ArrayRealVector(double[] v1, ArrayRealVector v2) {
|
||||
final int l1 = v1.length;
|
||||
|
@ -286,8 +286,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector add(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector add(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return add((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -304,8 +303,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector add(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector add(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double[] out = data.clone();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -315,20 +313,20 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the sum of this and v.
|
||||
* @param v vector to be added
|
||||
* @return this + v
|
||||
* @throws IllegalArgumentException if v is not the same size as this
|
||||
* Add {@code v} to this vector.
|
||||
*
|
||||
* @param v Vector to be added
|
||||
* @return {@code this} + v.
|
||||
* @throws DimensionMismatchException if {@code v} is not the same
|
||||
* size as this vector.
|
||||
*/
|
||||
public ArrayRealVector add(ArrayRealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public ArrayRealVector add(ArrayRealVector v) {
|
||||
return (ArrayRealVector) add(v.data);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector subtract(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector subtract(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return subtract((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -345,8 +343,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector subtract(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector subtract(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double[] out = data.clone();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -356,13 +353,14 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute this minus v.
|
||||
* @param v vector to be subtracted
|
||||
* @return this + v
|
||||
* @throws IllegalArgumentException if v is not the same size as this
|
||||
* Subtract {@code v} from this vector.
|
||||
*
|
||||
* @param v Vector to be subtracted.
|
||||
* @return {@code this} - v.
|
||||
* @throws DimensionMismatchException if {@code v} is not the
|
||||
* same size as this vector.
|
||||
*/
|
||||
public ArrayRealVector subtract(ArrayRealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public ArrayRealVector subtract(ArrayRealVector v) {
|
||||
return (ArrayRealVector) subtract(v.data);
|
||||
}
|
||||
|
||||
|
@ -619,8 +617,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealVector ebeMultiply(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector ebeMultiply(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return ebeMultiply((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -635,8 +632,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector ebeMultiply(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector ebeMultiply(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double[] out = data.clone();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -647,18 +643,17 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Element-by-element multiplication.
|
||||
* @param v vector by which instance elements must be multiplied
|
||||
* @return a vector containing this[i] * v[i] for all i
|
||||
* @exception IllegalArgumentException if v is not the same size as this
|
||||
* @param v Vector by which instance elements must be multiplied.
|
||||
* @return a Vector containing {@code this[i] * v[i]} for all {@code i}.
|
||||
* @exception DimensionMismatchException if {@code v} is not the same
|
||||
* size as this vector.
|
||||
*/
|
||||
public ArrayRealVector ebeMultiply(ArrayRealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public ArrayRealVector ebeMultiply(ArrayRealVector v) {
|
||||
return (ArrayRealVector) ebeMultiply(v.data);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealVector ebeDivide(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector ebeDivide(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return ebeDivide((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -673,8 +668,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealVector ebeDivide(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector ebeDivide(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double[] out = data.clone();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -685,12 +679,13 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Element-by-element division.
|
||||
* @param v vector by which instance elements must be divided
|
||||
* @return a vector containing this[i] / v[i] for all i
|
||||
* @throws IllegalArgumentException if v is not the same size as this
|
||||
*
|
||||
* @param v Vector by which instance elements must be divided.
|
||||
* @return a vector containing {@code this[i] / v[i]} for all {@code i}.
|
||||
* @exception DimensionMismatchException if {@code v} is not the same
|
||||
* size as this vector.
|
||||
*/
|
||||
public ArrayRealVector ebeDivide(ArrayRealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public ArrayRealVector ebeDivide(ArrayRealVector v) {
|
||||
return (ArrayRealVector) ebeDivide(v.data);
|
||||
}
|
||||
|
||||
|
@ -701,9 +696,10 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the underlying data array.
|
||||
* <p>Does not make a fresh copy of the underlying data.</p>
|
||||
* @return array of entries
|
||||
* Get a reference to the underlying data array.
|
||||
* This method does not make a fresh copy of the underlying data.
|
||||
*
|
||||
* @return the array of entries.
|
||||
*/
|
||||
public double[] getDataRef() {
|
||||
return data;
|
||||
|
@ -711,8 +707,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double dotProduct(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public double dotProduct(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return dotProduct((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -729,8 +724,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double dotProduct(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public double dotProduct(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double dot = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -783,8 +777,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double getDistance(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public double getDistance(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return getDistance((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -800,8 +793,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double getDistance(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public double getDistance(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double sum = 0;
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
|
@ -817,7 +809,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
* L<sub>2</sub> norm, i.e. the square root of the sum of
|
||||
* elements differences, or euclidian distance.
|
||||
*
|
||||
* @param v vector to which distance is requested
|
||||
* @param v Vector to which distance is requested.
|
||||
* @return the distance between two vectors.
|
||||
* @throws DimensionMismatchException if {@code v} is not the same size as
|
||||
* this vector.
|
||||
|
@ -848,8 +840,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double getL1Distance(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public double getL1Distance(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double sum = 0;
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
|
@ -896,8 +887,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double getLInfDistance(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public double getLInfDistance(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
double max = 0;
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
|
@ -970,8 +960,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealMatrix outerProduct(RealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealMatrix outerProduct(RealVector v) {
|
||||
if (v instanceof ArrayRealVector) {
|
||||
return outerProduct((ArrayRealVector) v);
|
||||
} else {
|
||||
|
@ -989,19 +978,18 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
|
||||
/**
|
||||
* Compute the outer product.
|
||||
* @param v vector with which outer product should be computed
|
||||
* @return the square matrix outer product between instance and v
|
||||
* @exception IllegalArgumentException if v is not the same size as this
|
||||
* @param v Vector with which outer product should be computed.
|
||||
* @return the square matrix outer product between this instance and {@code v}.
|
||||
* @throws DimensionMismatchException if {@code v} is not the same
|
||||
* size as this vector.
|
||||
*/
|
||||
public RealMatrix outerProduct(ArrayRealVector v)
|
||||
throws IllegalArgumentException {
|
||||
public RealMatrix outerProduct(ArrayRealVector v) {
|
||||
return outerProduct(v.data);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealMatrix outerProduct(double[] v)
|
||||
throws IllegalArgumentException {
|
||||
public RealMatrix outerProduct(double[] v) {
|
||||
checkVectorDimensions(v.length);
|
||||
final int m = data.length;
|
||||
final RealMatrix out = MatrixUtils.createRealMatrix(m, m);
|
||||
|
@ -1084,7 +1072,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
set(index, (ArrayRealVector) v);
|
||||
} catch (ClassCastException cce) {
|
||||
for (int i = index; i < index + v.getDimension(); ++i) {
|
||||
data[i] = v.getEntry(i-index);
|
||||
data[i] = v.getEntry(i - index);
|
||||
}
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
|
@ -1110,7 +1098,7 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
|
|||
* @param index Index of first element to be set.
|
||||
* @param v Vector containing the values to set.
|
||||
* @throws org.apache.commons.math.exception.OutOfRangeException
|
||||
* if the index is inconsistent with vector size.
|
||||
* if the index is inconsistent with the vector size.
|
||||
*/
|
||||
public void set(int index, ArrayRealVector v) {
|
||||
setSubVector(index, v.data);
|
||||
|
|
|
@ -370,8 +370,7 @@ public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public FieldMatrix<T> subtract(final FieldMatrix<T> m)
|
||||
throws IllegalArgumentException {
|
||||
public FieldMatrix<T> subtract(final FieldMatrix<T> m) {
|
||||
try {
|
||||
return subtract((BlockFieldMatrix<T>) m);
|
||||
} catch (ClassCastException cce) {
|
||||
|
@ -1229,9 +1228,7 @@ public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public T[] operate(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
public T[] operate(final T[] v) {
|
||||
if (v.length != columns) {
|
||||
throw new DimensionMismatchException(v.length, columns);
|
||||
}
|
||||
|
@ -1272,8 +1269,7 @@ public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public T[] preMultiply(final T[] v)
|
||||
throws IllegalArgumentException {
|
||||
public T[] preMultiply(final T[] v) {
|
||||
|
||||
if (v.length != rows) {
|
||||
throw new DimensionMismatchException(v.length, rows);
|
||||
|
|
|
@ -86,8 +86,8 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
|
|||
*
|
||||
* @param rows the number of rows in the new matrix
|
||||
* @param columns the number of columns in the new matrix
|
||||
* @throws IllegalArgumentException if row or column dimension is not
|
||||
* positive.
|
||||
* @throws org.apache.commons.math.exception.NotStrictlyPositiveException
|
||||
* if row or column dimension is not positive.
|
||||
*/
|
||||
public BlockRealMatrix(final int rows, final int columns) {
|
||||
super(rows, columns);
|
||||
|
@ -109,28 +109,26 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
|
|||
* <pre>matrix = new BlockRealMatrix(rawData.length, rawData[0].length,
|
||||
* toBlocksLayout(rawData), false);</pre>
|
||||
* </p>
|
||||
* @param rawData data for new matrix, in raw layout
|
||||
*
|
||||
* @exception IllegalArgumentException if <code>blockData</code> shape is
|
||||
* inconsistent with block layout
|
||||
* @param rawData data for new matrix, in raw layout
|
||||
* @throws DimensionMismatchException if the shape of {@code blockData} is
|
||||
* inconsistent with block layout.
|
||||
* @see #BlockRealMatrix(int, int, double[][], boolean)
|
||||
*/
|
||||
public BlockRealMatrix(final double[][] rawData)
|
||||
throws IllegalArgumentException {
|
||||
public BlockRealMatrix(final double[][] rawData) {
|
||||
this(rawData.length, rawData[0].length, toBlocksLayout(rawData), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new dense matrix copying entries from block layout data.
|
||||
* <p>The input array <em>must</em> already be in blocks layout.</p>
|
||||
* @param rows the number of rows in the new matrix
|
||||
* @param columns the number of columns in the new matrix
|
||||
* @param blockData data for new matrix
|
||||
* @param copyArray if true, the input array will be copied, otherwise
|
||||
* it will be referenced
|
||||
*
|
||||
* @exception IllegalArgumentException if <code>blockData</code> shape is
|
||||
* inconsistent with block layout
|
||||
* @param rows Number of rows in the new matrix.
|
||||
* @param columns Number of columns in the new matrix.
|
||||
* @param blockData data for new matrix
|
||||
* @param copyArray Whether the input array will be copied or referenced.
|
||||
* @throws DimensionMismatchException if the shape of {@code blockData} is
|
||||
* inconsistent with block layout.
|
||||
* @see #createBlocksLayout(int, int)
|
||||
* @see #toBlocksLayout(double[][])
|
||||
* @see #BlockRealMatrix(double[][])
|
||||
|
@ -183,10 +181,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
|
|||
* It can be used to provide the array argument of the {@link
|
||||
* #BlockRealMatrix(int, int, double[][], boolean)} constructor.
|
||||
* </p>
|
||||
* @param rawData data array in raw layout
|
||||
* @return a new data array containing the same entries but in blocks layout
|
||||
* @exception IllegalArgumentException if <code>rawData</code> is not rectangular
|
||||
* (not all rows have the same length)
|
||||
* @param rawData Data array in raw layout.
|
||||
* @return a new data array containing the same entries but in blocks layout.
|
||||
* @throws DimensionMismatchException if {@code rawData} is not rectangular.
|
||||
* @see #createBlocksLayout(int, int)
|
||||
* @see #BlockRealMatrix(int, int, double[][], boolean)
|
||||
*/
|
||||
|
@ -239,9 +236,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
|
|||
* This method can be used to create the array argument of the {@link
|
||||
* #BlockRealMatrix(int, int, double[][], boolean)} constructor.
|
||||
* </p>
|
||||
* @param rows the number of rows in the new matrix
|
||||
* @param columns the number of columns in the new matrix
|
||||
* @return a new data array in blocks layout
|
||||
* @param rows Number of rows in the new matrix.
|
||||
* @param columns Number of columns in the new matrix.
|
||||
* @return a new data array in blocks layout.
|
||||
* @see #toBlocksLayout(double[][])
|
||||
* @see #BlockRealMatrix(int, int, double[][], boolean)
|
||||
*/
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.FieldElement;
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link FieldMatrixChangingVisitor} interface.
|
||||
|
@ -33,7 +32,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
*/
|
||||
public class DefaultFieldMatrixChangingVisitor<T extends FieldElement<T>>
|
||||
implements FieldMatrixChangingVisitor<T> {
|
||||
|
||||
/** Zero element of the field. */
|
||||
private final T zero;
|
||||
|
||||
|
@ -58,5 +56,4 @@ public class DefaultFieldMatrixChangingVisitor<T extends FieldElement<T>>
|
|||
public T end() {
|
||||
return zero;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.FieldElement;
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link FieldMatrixPreservingVisitor} interface.
|
||||
|
@ -33,7 +32,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
*/
|
||||
public class DefaultFieldMatrixPreservingVisitor<T extends FieldElement<T>>
|
||||
implements FieldMatrixPreservingVisitor<T> {
|
||||
|
||||
/** Zero element of the field. */
|
||||
private final T zero;
|
||||
|
||||
|
@ -56,5 +54,4 @@ public class DefaultFieldMatrixPreservingVisitor<T extends FieldElement<T>>
|
|||
public T end() {
|
||||
return zero;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link RealMatrixChangingVisitor} interface.
|
||||
* <p>
|
||||
|
@ -30,7 +28,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public class DefaultRealMatrixChangingVisitor implements RealMatrixChangingVisitor {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void start(int rows, int columns,
|
||||
int startRow, int endRow, int startColumn, int endColumn) {
|
||||
|
@ -45,5 +42,4 @@ public class DefaultRealMatrixChangingVisitor implements RealMatrixChangingVisit
|
|||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link RealMatrixPreservingVisitor} interface.
|
||||
* <p>
|
||||
|
@ -30,7 +28,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public class DefaultRealMatrixPreservingVisitor implements RealMatrixPreservingVisitor {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void start(int rows, int columns,
|
||||
int startRow, int endRow, int startColumn, int endColumn) {
|
||||
|
@ -43,5 +40,4 @@ public class DefaultRealMatrixPreservingVisitor implements RealMatrixPreservingV
|
|||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.commons.math.linear;
|
|||
|
||||
import org.apache.commons.math.Field;
|
||||
import org.apache.commons.math.FieldElement;
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Interface defining field-valued matrix with basic algebraic operations.
|
||||
|
@ -32,7 +31,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix {
|
||||
|
||||
/**
|
||||
* Get the type of field elements of the matrix.
|
||||
*
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.FieldElement;
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Interface defining a visitor for matrix entries.
|
||||
|
@ -28,7 +27,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public interface FieldMatrixChangingVisitor<T extends FieldElement<?>> {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.FieldElement;
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Interface defining a visitor for matrix entries.
|
||||
|
@ -28,7 +27,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public interface FieldMatrixPreservingVisitor<T extends FieldElement<?>> {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
|
|
|
@ -25,11 +25,12 @@ 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.OutOfRangeException;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math.exception.NullArgumentException;
|
||||
import org.apache.commons.math.exception.MatrixDimensionMismatchException;
|
||||
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.fraction.BigFraction;
|
||||
import org.apache.commons.math.fraction.Fraction;
|
||||
|
@ -102,7 +103,7 @@ public class MatrixUtils {
|
|||
* @return RealMatrix containing the values of the array
|
||||
* @throws org.apache.commons.math.exception.DimensionMismatchException
|
||||
* if {@code data} is not rectangular (not all rows have the same length).
|
||||
* @throws ZeroException if a row or column is empty.
|
||||
* @throws NoDataException if a row or column is empty.
|
||||
* @throws NullArgumentException if either {@code data} or {@code data[0]}
|
||||
* is {@code null}.
|
||||
* @see #createRealMatrix(int, int)
|
||||
|
@ -129,7 +130,7 @@ public class MatrixUtils {
|
|||
* @return a matrix containing the values of the array.
|
||||
* @throws org.apache.commons.math.exception.DimensionMismatchException
|
||||
* if {@code data} is not rectangular (not all rows have the same length).
|
||||
* @throws ZeroException if a row or column is empty.
|
||||
* @throws NoDataException if a row or column is empty.
|
||||
* @throws NullArgumentException if either {@code data} or {@code data[0]}
|
||||
* is {@code null}.
|
||||
* @see #createFieldMatrix(Field, int, int)
|
||||
|
@ -224,7 +225,7 @@ public class MatrixUtils {
|
|||
*
|
||||
* @param data the input data
|
||||
* @return a data.length RealVector
|
||||
* @throws ZeroException if {@code data} is empty.
|
||||
* @throws NoDataException if {@code data} is empty.
|
||||
* @throws NullArgumentException if {@code data} is {@code null}.
|
||||
*/
|
||||
public static RealVector createRealVector(double[] data) {
|
||||
|
@ -240,7 +241,7 @@ public class MatrixUtils {
|
|||
* @param <T> the type of the field elements
|
||||
* @param data the input data
|
||||
* @return a data.length FieldVector
|
||||
* @throws ZeroException if {@code data} is empty.
|
||||
* @throws NoDataException if {@code data} is empty.
|
||||
* @throws NullArgumentException if {@code data} is {@code null}.
|
||||
*/
|
||||
public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data) {
|
||||
|
@ -256,7 +257,7 @@ public class MatrixUtils {
|
|||
*
|
||||
* @param rowData the input row data
|
||||
* @return a 1 x rowData.length RealMatrix
|
||||
* @throws ZeroException if {@code rowData} is empty.
|
||||
* @throws NoDataException if {@code rowData} is empty.
|
||||
* @throws NullArgumentException if {@code rowData} is {@code null}.
|
||||
*/
|
||||
public static RealMatrix createRowRealMatrix(double[] rowData) {
|
||||
|
@ -278,7 +279,7 @@ public class MatrixUtils {
|
|||
* @param <T> the type of the field elements
|
||||
* @param rowData the input row data
|
||||
* @return a 1 x rowData.length FieldMatrix
|
||||
* @throws ZeroException if {@code rowData} is empty.
|
||||
* @throws NoDataException if {@code rowData} is empty.
|
||||
* @throws NullArgumentException if {@code rowData} is {@code null}.
|
||||
*/
|
||||
public static <T extends FieldElement<T>> FieldMatrix<T>
|
||||
|
@ -288,7 +289,7 @@ public class MatrixUtils {
|
|||
}
|
||||
final int nCols = rowData.length;
|
||||
if (nCols == 0) {
|
||||
throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
|
||||
}
|
||||
final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols);
|
||||
for (int i = 0; i < nCols; ++i) {
|
||||
|
@ -303,7 +304,7 @@ public class MatrixUtils {
|
|||
*
|
||||
* @param columnData the input column data
|
||||
* @return a columnData x 1 RealMatrix
|
||||
* @throws ZeroException if {@code columnData} is empty.
|
||||
* @throws NoDataException if {@code columnData} is empty.
|
||||
* @throws NullArgumentException if {@code columnData} is {@code null}.
|
||||
*/
|
||||
public static RealMatrix createColumnRealMatrix(double[] columnData) {
|
||||
|
@ -325,7 +326,7 @@ public class MatrixUtils {
|
|||
* @param <T> the type of the field elements
|
||||
* @param columnData the input column data
|
||||
* @return a columnData x 1 FieldMatrix
|
||||
* @throws ZeroException if {@code data} is empty.
|
||||
* @throws NoDataException if {@code data} is empty.
|
||||
* @throws NullArgumentException if {@code columnData} is {@code null}.
|
||||
*/
|
||||
public static <T extends FieldElement<T>> FieldMatrix<T>
|
||||
|
@ -335,7 +336,7 @@ public class MatrixUtils {
|
|||
}
|
||||
final int nRows = columnData.length;
|
||||
if (nRows == 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
|
||||
}
|
||||
final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1);
|
||||
for (int i = 0; i < nRows; ++i) {
|
||||
|
@ -430,7 +431,7 @@ public class MatrixUtils {
|
|||
* @param selectedColumns Array of column indices.
|
||||
* @throws NullArgumentException if {@code selectedRows} or
|
||||
* {@code selectedColumns} are {@code null}.
|
||||
* @throws ZeroException if the row or column selections are empty (zero
|
||||
* @throws NoDataException if the row or column selections are empty (zero
|
||||
* length).
|
||||
* @throws OutOfRangeException if row or column selections are not valid.
|
||||
*/
|
||||
|
@ -444,10 +445,10 @@ public class MatrixUtils {
|
|||
throw new NullArgumentException();
|
||||
}
|
||||
if (selectedRows.length == 0) {
|
||||
throw new ZeroException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
|
||||
throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
|
||||
}
|
||||
if (selectedColumns.length == 0) {
|
||||
throw new ZeroException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
|
||||
throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
|
||||
}
|
||||
|
||||
for (final int row : selectedRows) {
|
||||
|
@ -459,59 +460,53 @@ public class MatrixUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if matrices are addition compatible
|
||||
* @param left left hand side matrix
|
||||
* @param right right hand side matrix
|
||||
* @exception IllegalArgumentException if matrices are not addition compatible
|
||||
* Check if matrices are addition compatible.
|
||||
*
|
||||
* @param left Left hand side matrix.
|
||||
* @param right Right hand side matrix.
|
||||
* @throws MatrixDimensionMismatchException if the matrices are not addition compatible.
|
||||
*/
|
||||
public static void checkAdditionCompatible(final AnyMatrix left, final AnyMatrix right)
|
||||
throws IllegalArgumentException {
|
||||
public static void checkAdditionCompatible(final AnyMatrix left, final AnyMatrix right) {
|
||||
if ((left.getRowDimension() != right.getRowDimension()) ||
|
||||
(left.getColumnDimension() != right.getColumnDimension())) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.NOT_ADDITION_COMPATIBLE_MATRICES,
|
||||
left.getRowDimension(), left.getColumnDimension(),
|
||||
right.getRowDimension(), right.getColumnDimension());
|
||||
throw new MatrixDimensionMismatchException(left.getRowDimension(), left.getColumnDimension(),
|
||||
right.getRowDimension(), right.getColumnDimension());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matrices are subtraction compatible
|
||||
* @param left left hand side matrix
|
||||
* @param right right hand side matrix
|
||||
* @exception IllegalArgumentException if matrices are not subtraction compatible
|
||||
*
|
||||
* @param left Left hand side matrix.
|
||||
* @param right Right hand side matrix.
|
||||
* @throws MatrixDimensionMismatchException if the matrices are not addition compatible.
|
||||
*/
|
||||
public static void checkSubtractionCompatible(final AnyMatrix left, final AnyMatrix right)
|
||||
throws IllegalArgumentException {
|
||||
public static void checkSubtractionCompatible(final AnyMatrix left, final AnyMatrix right) {
|
||||
if ((left.getRowDimension() != right.getRowDimension()) ||
|
||||
(left.getColumnDimension() != right.getColumnDimension())) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.NOT_SUBTRACTION_COMPATIBLE_MATRICES,
|
||||
left.getRowDimension(), left.getColumnDimension(),
|
||||
right.getRowDimension(), right.getColumnDimension());
|
||||
throw new MatrixDimensionMismatchException(left.getRowDimension(), left.getColumnDimension(),
|
||||
right.getRowDimension(), right.getColumnDimension());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matrices are multiplication compatible
|
||||
* @param left left hand side matrix
|
||||
* @param right right hand side matrix
|
||||
* @exception IllegalArgumentException if matrices are not multiplication compatible
|
||||
*
|
||||
* @param left Left hand side matrix.
|
||||
* @param right Right hand side matrix.
|
||||
* @throws DimensionMismatchException if matrices are not multiplication compatible.
|
||||
*/
|
||||
public static void checkMultiplicationCompatible(final AnyMatrix left, final AnyMatrix right)
|
||||
throws IllegalArgumentException {
|
||||
public static void checkMultiplicationCompatible(final AnyMatrix left, final AnyMatrix right) {
|
||||
if (left.getColumnDimension() != right.getRowDimension()) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
LocalizedFormats.NOT_MULTIPLICATION_COMPATIBLE_MATRICES,
|
||||
left.getRowDimension(), left.getColumnDimension(),
|
||||
right.getRowDimension(), right.getColumnDimension());
|
||||
throw new DimensionMismatchException(left.getColumnDimension(),
|
||||
right.getRowDimension());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link FieldMatrix}/{@link Fraction} matrix to a {@link RealMatrix}.
|
||||
* @param m matrix to convert
|
||||
* @return converted matrix
|
||||
* @param m Matrix to convert.
|
||||
* @return the converted matrix.
|
||||
*/
|
||||
public static Array2DRowRealMatrix fractionMatrixToRealMatrix(final FieldMatrix<Fraction> m) {
|
||||
final FractionMatrixConverter converter = new FractionMatrixConverter();
|
||||
|
@ -521,10 +516,8 @@ public class MatrixUtils {
|
|||
|
||||
/** Converter for {@link FieldMatrix}/{@link Fraction}. */
|
||||
private static class FractionMatrixConverter extends DefaultFieldMatrixPreservingVisitor<Fraction> {
|
||||
|
||||
/** Converted array. */
|
||||
private double[][] data;
|
||||
|
||||
/** Simple constructor. */
|
||||
public FractionMatrixConverter() {
|
||||
super(Fraction.ZERO);
|
||||
|
@ -543,8 +536,10 @@ public class MatrixUtils {
|
|||
data[row][column] = value.doubleValue();
|
||||
}
|
||||
|
||||
/** Get the converted matrix.
|
||||
* @return converted matrix
|
||||
/**
|
||||
* Get the converted matrix.
|
||||
*
|
||||
* @return the converted matrix.
|
||||
*/
|
||||
Array2DRowRealMatrix getConvertedMatrix() {
|
||||
return new Array2DRowRealMatrix(data, false);
|
||||
|
@ -554,8 +549,9 @@ public class MatrixUtils {
|
|||
|
||||
/**
|
||||
* Convert a {@link FieldMatrix}/{@link BigFraction} matrix to a {@link RealMatrix}.
|
||||
* @param m matrix to convert
|
||||
* @return converted matrix
|
||||
*
|
||||
* @param m Matrix to convert.
|
||||
* @return the converted matrix.
|
||||
*/
|
||||
public static Array2DRowRealMatrix bigFractionMatrixToRealMatrix(final FieldMatrix<BigFraction> m) {
|
||||
final BigFractionMatrixConverter converter = new BigFractionMatrixConverter();
|
||||
|
@ -565,10 +561,8 @@ public class MatrixUtils {
|
|||
|
||||
/** Converter for {@link FieldMatrix}/{@link BigFraction}. */
|
||||
private static class BigFractionMatrixConverter extends DefaultFieldMatrixPreservingVisitor<BigFraction> {
|
||||
|
||||
/** Converted array. */
|
||||
private double[][] data;
|
||||
|
||||
/** Simple constructor. */
|
||||
public BigFractionMatrixConverter() {
|
||||
super(BigFraction.ZERO);
|
||||
|
@ -587,13 +581,14 @@ public class MatrixUtils {
|
|||
data[row][column] = value.doubleValue();
|
||||
}
|
||||
|
||||
/** Get the converted matrix.
|
||||
* @return converted matrix
|
||||
/**
|
||||
* Get the converted matrix.
|
||||
*
|
||||
* @return the converted matrix.
|
||||
*/
|
||||
Array2DRowRealMatrix getConvertedMatrix() {
|
||||
return new Array2DRowRealMatrix(data, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Serialize a {@link RealVector}.
|
||||
|
@ -803,7 +798,5 @@ public class MatrixUtils {
|
|||
ioe.initCause(iae);
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,8 +107,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public OpenMapRealMatrix subtract(final RealMatrix m)
|
||||
throws IllegalArgumentException {
|
||||
public OpenMapRealMatrix subtract(final RealMatrix m) {
|
||||
try {
|
||||
return subtract((OpenMapRealMatrix) m);
|
||||
} catch (ClassCastException cce) {
|
||||
|
@ -141,8 +140,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealMatrix multiply(final RealMatrix m)
|
||||
throws IllegalArgumentException {
|
||||
public RealMatrix multiply(final RealMatrix m) {
|
||||
try {
|
||||
return multiply((OpenMapRealMatrix) m);
|
||||
} catch (ClassCastException cce) {
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
|
||||
/**
|
||||
* Interface defining a real-valued matrix with basic algebraic operations.
|
||||
* <p>
|
||||
|
@ -29,7 +26,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public interface RealMatrix extends AnyMatrix {
|
||||
|
||||
/**
|
||||
* Create a new RealMatrix of the same type as the instance with the supplied
|
||||
* row and column dimensions.
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Interface defining a visitor for matrix entries.
|
||||
*
|
||||
|
@ -27,7 +25,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public interface RealMatrixChangingVisitor {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.MathUserException;
|
||||
|
||||
/**
|
||||
* Interface defining a visitor for matrix entries.
|
||||
*
|
||||
|
@ -27,7 +25,6 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
* @since 2.0
|
||||
*/
|
||||
public interface RealMatrixPreservingVisitor {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
|
|
|
@ -111,7 +111,7 @@ public interface SingularValueDecomposition {
|
|||
* @exception IllegalArgumentException if minSingularValue is larger than
|
||||
* the largest singular value, meaning all singular values are ignored
|
||||
*/
|
||||
RealMatrix getCovariance(double minSingularValue) throws IllegalArgumentException;
|
||||
RealMatrix getCovariance(double minSingularValue);
|
||||
|
||||
/**
|
||||
* Returns the L<sub>2</sub> norm of the matrix.
|
||||
|
|
|
@ -34,38 +34,29 @@ import org.apache.commons.math.util.FastMath;
|
|||
* @version $Revision$ $Date$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SingularValueDecompositionImpl implements
|
||||
SingularValueDecomposition {
|
||||
|
||||
public class SingularValueDecompositionImpl implements SingularValueDecomposition {
|
||||
/** Number of rows of the initial matrix. */
|
||||
private int m;
|
||||
|
||||
/** Number of columns of the initial matrix. */
|
||||
private int n;
|
||||
|
||||
/** Eigen decomposition of the tridiagonal matrix. */
|
||||
private EigenDecomposition eigenDecomposition;
|
||||
|
||||
/** Singular values. */
|
||||
private double[] singularValues;
|
||||
|
||||
/** Cached value of U. */
|
||||
private RealMatrix cachedU;
|
||||
|
||||
/** Cached value of U<sup>T</sup>. */
|
||||
private RealMatrix cachedUt;
|
||||
|
||||
/** Cached value of S. */
|
||||
private RealMatrix cachedS;
|
||||
|
||||
/** Cached value of V. */
|
||||
private RealMatrix cachedV;
|
||||
|
||||
/** Cached value of V<sup>T</sup>. */
|
||||
private RealMatrix cachedVt;
|
||||
|
||||
/**
|
||||
* Calculates the compact Singular Value Decomposition of the given matrix.
|
||||
*
|
||||
* @param matrix Matrix to decompose.
|
||||
*/
|
||||
public SingularValueDecompositionImpl(final RealMatrix matrix) {
|
||||
|
@ -88,7 +79,7 @@ public class SingularValueDecompositionImpl implements
|
|||
for (int k = 0; k < m; k++) {
|
||||
matATA[i][j] += localcopy[k][i] * localcopy[k][j];
|
||||
}
|
||||
matATA[j][i]=matATA[i][j];
|
||||
matATA[j][i] = matATA[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,33 +93,33 @@ public class SingularValueDecompositionImpl implements
|
|||
for (int k = 0; k < n; k++) {
|
||||
matAAT[i][j] += localcopy[i][k] * localcopy[j][k];
|
||||
}
|
||||
matAAT[j][i]=matAAT[i][j];
|
||||
matAAT[j][i] = matAAT[i][j];
|
||||
}
|
||||
}
|
||||
int p;
|
||||
if (m>=n) {
|
||||
p=n;
|
||||
if (m >= n) {
|
||||
p = n;
|
||||
// compute eigen decomposition of A^T*A
|
||||
eigenDecomposition = new EigenDecompositionImpl(
|
||||
new Array2DRowRealMatrix(matATA),1.0);
|
||||
eigenDecomposition
|
||||
= new EigenDecompositionImpl(new Array2DRowRealMatrix(matATA), 1);
|
||||
singularValues = eigenDecomposition.getRealEigenvalues();
|
||||
cachedV = eigenDecomposition.getV();
|
||||
// compute eigen decomposition of A*A^T
|
||||
eigenDecomposition = new EigenDecompositionImpl(
|
||||
new Array2DRowRealMatrix(matAAT),1.0);
|
||||
eigenDecomposition
|
||||
= new EigenDecompositionImpl(new Array2DRowRealMatrix(matAAT), 1);
|
||||
cachedU = eigenDecomposition.getV().getSubMatrix(0, m - 1, 0, p - 1);
|
||||
} else {
|
||||
p=m;
|
||||
p = m;
|
||||
// compute eigen decomposition of A*A^T
|
||||
eigenDecomposition = new EigenDecompositionImpl(
|
||||
new Array2DRowRealMatrix(matAAT),1.0);
|
||||
eigenDecomposition
|
||||
= new EigenDecompositionImpl(new Array2DRowRealMatrix(matAAT), 1);
|
||||
singularValues = eigenDecomposition.getRealEigenvalues();
|
||||
cachedU = eigenDecomposition.getV();
|
||||
|
||||
// compute eigen decomposition of A^T*A
|
||||
eigenDecomposition = new EigenDecompositionImpl(
|
||||
new Array2DRowRealMatrix(matATA),1.0);
|
||||
cachedV = eigenDecomposition.getV().getSubMatrix(0,n-1,0,p-1);
|
||||
eigenDecomposition
|
||||
= new EigenDecompositionImpl(new Array2DRowRealMatrix(matATA), 1);
|
||||
cachedV = eigenDecomposition.getV().getSubMatrix(0, n - 1 , 0, p - 1);
|
||||
}
|
||||
for (int i = 0; i < p; i++) {
|
||||
singularValues[i] = FastMath.sqrt(FastMath.abs(singularValues[i]));
|
||||
|
@ -138,11 +129,11 @@ public class SingularValueDecompositionImpl implements
|
|||
// The sign is set such that A.V_i=sigma_i.U_i (i<=p)
|
||||
// The right sign corresponds to a positive dot product of A.V_i and U_i
|
||||
for (int i = 0; i < p; i++) {
|
||||
RealVector tmp = cachedU.getColumnVector(i);
|
||||
double product=matrix.operate(cachedV.getColumnVector(i)).dotProduct(tmp);
|
||||
if (product<0) {
|
||||
cachedU.setColumnVector(i, tmp.mapMultiply(-1.0));
|
||||
}
|
||||
RealVector tmp = cachedU.getColumnVector(i);
|
||||
double product=matrix.operate(cachedV.getColumnVector(i)).dotProduct(tmp);
|
||||
if (product < 0) {
|
||||
cachedU.setColumnVector(i, tmp.mapMultiply(-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,24 +146,18 @@ public class SingularValueDecompositionImpl implements
|
|||
|
||||
/** {@inheritDoc} */
|
||||
public RealMatrix getUT() {
|
||||
|
||||
if (cachedUt == null) {
|
||||
cachedUt = getU().transpose();
|
||||
}
|
||||
|
||||
// return the cached matrix
|
||||
return cachedUt;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealMatrix getS() {
|
||||
|
||||
if (cachedS == null) {
|
||||
|
||||
// cache the matrix for subsequent calls
|
||||
cachedS = MatrixUtils.createRealDiagonalMatrix(singularValues);
|
||||
|
||||
}
|
||||
return cachedS;
|
||||
}
|
||||
|
@ -186,24 +171,19 @@ public class SingularValueDecompositionImpl implements
|
|||
public RealMatrix getV() {
|
||||
// return the cached matrix
|
||||
return cachedV;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealMatrix getVT() {
|
||||
|
||||
if (cachedVt == null) {
|
||||
cachedVt = getV().transpose();
|
||||
}
|
||||
|
||||
// return the cached matrix
|
||||
return cachedVt;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public RealMatrix getCovariance(final double minSingularValue) {
|
||||
|
||||
// get the number of singular values to consider
|
||||
final int p = singularValues.length;
|
||||
int dimension = 0;
|
||||
|
@ -229,7 +209,6 @@ public class SingularValueDecompositionImpl implements
|
|||
|
||||
RealMatrix jv = new Array2DRowRealMatrix(data, false);
|
||||
return jv.transpose().multiply(jv);
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -243,8 +222,7 @@ public class SingularValueDecompositionImpl implements
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int getRank() throws IllegalStateException {
|
||||
|
||||
public int getRank() {
|
||||
final double threshold = FastMath.max(m, n) * FastMath.ulp(singularValues[0]);
|
||||
|
||||
for (int i = singularValues.length - 1; i >= 0; --i) {
|
||||
|
@ -253,44 +231,37 @@ public class SingularValueDecompositionImpl implements
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public DecompositionSolver getSolver() {
|
||||
return new Solver(singularValues, getUT(), getV(), getRank() == Math
|
||||
.max(m, n));
|
||||
return new Solver(singularValues, getUT(), getV(), getRank() == Math.max(m, n));
|
||||
}
|
||||
|
||||
/** Specialized solver. */
|
||||
private static class Solver implements DecompositionSolver {
|
||||
|
||||
/** Pseudo-inverse of the initial matrix. */
|
||||
private final RealMatrix pseudoInverse;
|
||||
|
||||
/** Singularity indicator. */
|
||||
private boolean nonSingular;
|
||||
|
||||
/**
|
||||
* Build a solver from decomposed matrix.
|
||||
* @param singularValues
|
||||
* singularValues
|
||||
* @param uT
|
||||
* U<sup>T</sup> matrix of the decomposition
|
||||
* @param v
|
||||
* V matrix of the decomposition
|
||||
* @param nonSingular
|
||||
* singularity indicator
|
||||
*
|
||||
* @param singularValues Singular values.
|
||||
* @param uT U<sup>T</sup> matrix of the decomposition.
|
||||
* @param v V matrix of the decomposition.
|
||||
* @param nonSingular Singularity indicator.
|
||||
*/
|
||||
private Solver(final double[] singularValues, final RealMatrix uT,
|
||||
final RealMatrix v, final boolean nonSingular) {
|
||||
final RealMatrix v, final boolean nonSingular) {
|
||||
double[][] suT = uT.getData();
|
||||
for (int i = 0; i < singularValues.length; ++i) {
|
||||
final double a;
|
||||
if (singularValues[i]>0) {
|
||||
a=1.0 / singularValues[i];
|
||||
if (singularValues[i] > 0) {
|
||||
a = 1 / singularValues[i];
|
||||
} else {
|
||||
a=0.0;
|
||||
a = 0;
|
||||
}
|
||||
final double[] suTi = suT[i];
|
||||
for (int j = 0; j < suTi.length; ++j) {
|
||||
|
@ -307,13 +278,12 @@ public class SingularValueDecompositionImpl implements
|
|||
* The m×n matrix A may not be square, the solution X is such that
|
||||
* ||A × X - B|| is minimal.
|
||||
* </p>
|
||||
* @param b
|
||||
* right-hand side of the equation A × X = B
|
||||
* @param b Right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException
|
||||
* if matrices dimensions don't match
|
||||
* @throws org.apache.commons.math.exception.DimensionMismatchException
|
||||
* if the matrices dimensions do not match.
|
||||
*/
|
||||
public double[] solve(final double[] b) throws IllegalArgumentException {
|
||||
public double[] solve(final double[] b) {
|
||||
return pseudoInverse.operate(b);
|
||||
}
|
||||
|
||||
|
@ -323,14 +293,12 @@ public class SingularValueDecompositionImpl implements
|
|||
* The m×n matrix A may not be square, the solution X is such that
|
||||
* ||A × X - B|| is minimal.
|
||||
* </p>
|
||||
* @param b
|
||||
* right-hand side of the equation A × X = B
|
||||
* @param b Right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException
|
||||
* if matrices dimensions don't match
|
||||
* @throws org.apache.commons.math.exception.DimensionMismatchException
|
||||
* if the matrices dimensions do not match.
|
||||
*/
|
||||
public RealVector solve(final RealVector b)
|
||||
throws IllegalArgumentException {
|
||||
public RealVector solve(final RealVector b) {
|
||||
return pseudoInverse.operate(b);
|
||||
}
|
||||
|
||||
|
@ -340,20 +308,20 @@ public class SingularValueDecompositionImpl implements
|
|||
* The m×n matrix A may not be square, the solution X is such that
|
||||
* ||A × X - B|| is minimal.
|
||||
* </p>
|
||||
* @param b
|
||||
* right-hand side of the equation A × X = B
|
||||
*
|
||||
* @param b Right-hand side of the equation A × X = B
|
||||
* @return a matrix X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException
|
||||
* if matrices dimensions don't match
|
||||
* @throws org.apache.commons.math.exception.DimensionMismatchException
|
||||
* if the matrices dimensions do not match.
|
||||
*/
|
||||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException {
|
||||
public RealMatrix solve(final RealMatrix b) {
|
||||
return pseudoInverse.multiply(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the decomposed matrix is non-singular.
|
||||
* @return true if the decomposed matrix is non-singular
|
||||
*
|
||||
* @return {@code true} if the decomposed matrix is non-singular.
|
||||
*/
|
||||
public boolean isNonSingular() {
|
||||
return nonSingular;
|
||||
|
@ -361,12 +329,11 @@ public class SingularValueDecompositionImpl implements
|
|||
|
||||
/**
|
||||
* Get the pseudo-inverse of the decomposed matrix.
|
||||
* @return inverse matrix
|
||||
*
|
||||
* @return the inverse matrix.
|
||||
*/
|
||||
public RealMatrix getInverse() {
|
||||
return pseudoInverse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
import org.apache.commons.math.util.FastMath;
|
||||
import org.apache.commons.math.exception.MatrixDimensionMismatchException;
|
||||
import org.apache.commons.math.exception.OutOfRangeException;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math.exception.NonSquareMatrixException;
|
||||
|
||||
|
@ -399,7 +399,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
|
||||
assertEquals(new Array2DRowRealMatrix(reference), sub);
|
||||
if (mustFail) {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (!mustFail) {
|
||||
|
@ -409,7 +409,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
|
||||
assertEquals(new Array2DRowRealMatrix(reference), sub);
|
||||
if (mustFail) {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (!mustFail) {
|
||||
|
@ -433,7 +433,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
|
||||
assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
|
||||
if (mustFail) {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (!mustFail) {
|
||||
|
@ -480,7 +480,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
m.copySubMatrix(selectedRows, selectedColumns, sub);
|
||||
assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
|
||||
if (mustFail) {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (!mustFail) {
|
||||
|
@ -507,7 +507,7 @@ public final class Array2DRowRealMatrixTest extends TestCase {
|
|||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (!mustFail) {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.commons.math.exception.MathUserException;
|
|||
import org.apache.commons.math.util.FastMath;
|
||||
import org.apache.commons.math.exception.MatrixDimensionMismatchException;
|
||||
import org.apache.commons.math.exception.OutOfRangeException;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math.exception.NonSquareMatrixException;
|
||||
|
||||
|
@ -499,7 +499,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
assertEquals(new BlockRealMatrix(reference), sub);
|
||||
} else {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (reference != null) {
|
||||
|
@ -509,7 +509,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
assertEquals(new BlockRealMatrix(reference), sub);
|
||||
} else {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallExceptiono r ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallExceptiono r NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (reference != null) {
|
||||
|
@ -533,7 +533,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
|
||||
} else {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (reference != null) {
|
||||
|
@ -599,7 +599,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -616,7 +616,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
|
||||
} else {
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or ZeroException");
|
||||
fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
|
||||
}
|
||||
} catch (OutOfRangeException e) {
|
||||
if (reference != null) {
|
||||
|
@ -626,7 +626,7 @@ public final class BlockRealMatrixTest extends TestCase {
|
|||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ZeroException e) {
|
||||
} catch (NoDataException e) {
|
||||
if (reference != null) {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import junit.framework.TestCase;
|
|||
|
||||
import org.apache.commons.math.TestUtils;
|
||||
import org.apache.commons.math.exception.OutOfRangeException;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NoDataException;
|
||||
import org.apache.commons.math.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math.exception.NonSquareMatrixException;
|
||||
|
||||
|
@ -436,8 +436,8 @@ public final class SparseRealMatrixTest extends TestCase {
|
|||
}
|
||||
try {
|
||||
m.getSubMatrix(new int[] {}, new int[] { 0 });
|
||||
fail("Expecting ZeroException");
|
||||
} catch (ZeroException ex) {
|
||||
fail("Expecting NoDataException");
|
||||
} catch (NoDataException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue