Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.0
-
None
-
None
-
all
Description
As discussed in the mailing list, things like ArrayRealVector#add:
double[] out = new double[data.length]; for (int i = 0; i < data.length; i++) { out[i] = data[i] + v.getEntry(i); } return new ArrayRealVector(out);
can be improved in the inner loop by simply
double[] out = out.clone(); for (int i = 0; i < data.length; i++) { out[i] += v.getEntry(i); } return new ArrayRealVector(out);
Which cuts down on array accesses.
Even more importantly, the last return line should pass in the boolean false, for "shallow copy", or else this whole temporary array is being copied again and then the original discarded.
return new ArrayRealVector(out, false);