Avoid redundant array accesses (unit tests).

This commit is contained in:
Gilles Sadowski 2020-08-10 20:17:06 +02:00
parent e99434d937
commit 450dadfd59
1 changed files with 4 additions and 3 deletions

View File

@ -203,9 +203,10 @@ class OptimTestUtils {
@Override
public double value(double[] x) {
double f = 0;
for (int i = 0; i < x.length - 1; ++i) {
f += 1e2 * (x[i] * x[i] - x[i + 1]) * (x[i] * x[i] - x[i + 1])
+ (x[i] - 1.) * (x[i] - 1.);
for (int i = 0; i < x.length - 1; i++) {
final double a = x[i] * x[i] - x[i + 1];
final double b = x[i] - 1;
f += 1e2 * a * a + b * b;
}
return f;
}