added a specialized implementation of premultiply

removed unneeded signatures with RelVectorImpl already handled efficiently by base class

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@729173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-12-23 23:27:52 +00:00
parent 13583c53fa
commit ef8ee92f48
1 changed files with 27 additions and 18 deletions

View File

@ -414,7 +414,11 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable {
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
final int nCols = this.getColumnDimension(); final int nCols = this.getColumnDimension();
if (v.length != nCols) { if (v.length != nCols) {
throw new IllegalArgumentException("vector has wrong length"); throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
" got {0} but expected {1}",
new Object[] {
v.length, nCols
});
} }
final double[] out = new double[nRows]; final double[] out = new double[nRows];
for (int row = 0; row < nRows; row++) { for (int row = 0; row < nRows; row++) {
@ -429,25 +433,30 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public RealVector operate(final RealVector v) public double[] preMultiply(final double[] v)
throws IllegalArgumentException { throws IllegalArgumentException {
try {
return operate((RealVectorImpl) v); final int nRows = getRowDimension();
} catch (ClassCastException cce) { final int nCols = getColumnDimension();
return super.operate(v); if (v.length != nRows) {
} throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
" got {0} but expected {1}",
new Object[] {
v.length, nRows
});
} }
/** final double[] out = new double[nCols];
* Returns the result of multiplying this by the vector <code>v</code>. for (int col = 0; col < nCols; ++col) {
* double sum = 0;
* @param v the vector to operate on for (int i = 0; i < nRows; ++i) {
* @return this*v sum += data[i][col] * v[i];
* @throws IllegalArgumentException if columnDimension != v.size() }
*/ out[col] = sum;
public RealVectorImpl operate(final RealVectorImpl v) }
throws IllegalArgumentException {
return new RealVectorImpl(operate(v.getDataRef()), false); return out;
} }
/** /**