From 450dadfd59a442eed6db0080ff30727836fdf97c Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Mon, 10 Aug 2020 20:17:06 +0200 Subject: [PATCH] Avoid redundant array accesses (unit tests). --- .../optim/nonlinear/scalar/noderiv/OptimTestUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/OptimTestUtils.java b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/OptimTestUtils.java index df6cd1f1d..d759e4bbb 100644 --- a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/OptimTestUtils.java +++ b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/OptimTestUtils.java @@ -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; }