use direct array access where possible
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@729172 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a20be3af18
commit
13583c53fa
|
@ -606,28 +606,30 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public RealVector operate(final RealVector v)
|
public RealVector operate(final RealVector v)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
try {
|
||||||
final int nRows = getRowDimension();
|
return new RealVectorImpl(operate(((RealVectorImpl) v).getDataRef()), false);
|
||||||
final int nCols = getColumnDimension();
|
} catch (ClassCastException cce) {
|
||||||
if (v.getDimension() != nCols) {
|
final int nRows = getRowDimension();
|
||||||
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
|
final int nCols = getColumnDimension();
|
||||||
" got {0} but expected {1}",
|
if (v.getDimension() != nCols) {
|
||||||
new Object[] {
|
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
|
||||||
v.getDimension(), nCols
|
" got {0} but expected {1}",
|
||||||
});
|
new Object[] {
|
||||||
}
|
v.getDimension(), nCols
|
||||||
|
});
|
||||||
final double[] out = new double[nRows];
|
|
||||||
for (int row = 0; row < nRows; ++row) {
|
|
||||||
double sum = 0;
|
|
||||||
for (int i = 0; i < nCols; ++i) {
|
|
||||||
sum += getEntry(row, i) * v.getEntry(i);
|
|
||||||
}
|
}
|
||||||
out[row] = sum;
|
|
||||||
|
final double[] out = new double[nRows];
|
||||||
|
for (int row = 0; row < nRows; ++row) {
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < nCols; ++i) {
|
||||||
|
sum += getEntry(row, i) * v.getEntry(i);
|
||||||
|
}
|
||||||
|
out[row] = sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RealVectorImpl(out, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RealVectorImpl(out, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -660,28 +662,32 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public RealVector preMultiply(final RealVector v)
|
public RealVector preMultiply(final RealVector v)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
try {
|
||||||
|
return new RealVectorImpl(preMultiply(((RealVectorImpl) v).getDataRef()), false);
|
||||||
|
} catch (ClassCastException cce) {
|
||||||
|
|
||||||
final int nRows = getRowDimension();
|
final int nRows = getRowDimension();
|
||||||
final int nCols = getColumnDimension();
|
final int nCols = getColumnDimension();
|
||||||
if (v.getDimension() != nRows) {
|
if (v.getDimension() != nRows) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
|
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
|
||||||
" got {0} but expected {1}",
|
" got {0} but expected {1}",
|
||||||
new Object[] {
|
new Object[] {
|
||||||
v.getDimension(), nRows
|
v.getDimension(), nRows
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
final double[] out = new double[nCols];
|
|
||||||
for (int col = 0; col < nCols; ++col) {
|
|
||||||
double sum = 0;
|
|
||||||
for (int i = 0; i < nRows; ++i) {
|
|
||||||
sum += getEntry(i, col) * v.getEntry(i);
|
|
||||||
}
|
}
|
||||||
out[col] = sum;
|
|
||||||
|
final double[] out = new double[nCols];
|
||||||
|
for (int col = 0; col < nCols; ++col) {
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < nRows; ++i) {
|
||||||
|
sum += getEntry(i, col) * v.getEntry(i);
|
||||||
|
}
|
||||||
|
out[col] = sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RealVectorImpl(out);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RealVectorImpl(out);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
Loading…
Reference in New Issue