Slightly faster "add" method (due to Arne Plöse).


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1148952 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-07-20 22:09:17 +00:00
parent 0d0c461e6e
commit 7133fb43b7
1 changed files with 7 additions and 5 deletions

View File

@ -304,12 +304,14 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public RealVector add(double[] v) { public RealVector add(double[] v) {
checkVectorDimensions(v.length); final int dim = v.length;
double[] out = data.clone(); checkVectorDimensions(dim);
for (int i = 0; i < data.length; i++) { ArrayRealVector result = new ArrayRealVector(dim);
out[i] += v[i]; double[] resultData = result.data;
for (int i = 0; i < dim; i++) {
resultData[i] = data[i] + v[i];
} }
return new ArrayRealVector(out, false); return result;
} }
/** /**