From 3aab6312722297daddc34e5f5de9a0762d040563 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Fri, 6 Aug 2021 07:38:21 +0200 Subject: [PATCH 1/2] MATH-1573 - Redundant local variable --- .../commons/math4/legacy/core/jdkmath/AccurateMath.java | 4 +--- .../math4/legacy/analysis/differentiation/SparseGradient.java | 3 +-- .../PiecewiseBicubicSplineInterpolatingFunction.java | 4 +--- .../apache/commons/math4/legacy/genetics/BinaryMutation.java | 3 +-- .../math4/legacy/optim/nonlinear/scalar/LineSearch.java | 3 +-- .../math4/legacy/stat/inference/KolmogorovSmirnovTest.java | 4 +--- 6 files changed, 6 insertions(+), 15 deletions(-) diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java index cf86c9327..a65b3c736 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java @@ -2792,9 +2792,7 @@ public final class AccurateMath { } // Call atan - final double result = atan(ra, rb, x < 0); - - return result; + return atan(ra, rb, x < 0); } /** Compute the arc sine of a number. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java index 035ac36aa..7e71c6dcb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java @@ -178,8 +178,7 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient add(final double c) { - final SparseGradient out = new SparseGradient(value + c, derivatives); - return out; + return new SparseGradient(value + c, derivatives); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java index 587310d9a..941dd6869 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java @@ -142,9 +142,7 @@ public class PiecewiseBicubicSplineInterpolatingFunction final PolynomialSplineFunction spline = interpolator.interpolate(yArray, interpArray); - double returnValue = spline.value(y); - - return returnValue; + return spline.value(y); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryMutation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryMutation.java index d3f6a2370..ce2347190 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryMutation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryMutation.java @@ -50,8 +50,7 @@ public class BinaryMutation implements MutationPolicy { // and change it newRepr.set(geneIndex, origChrom.getRepresentation().get(geneIndex) == 0 ? 1 : 0); - Chromosome newChrom = origChrom.newFixedLengthChromosome(newRepr); - return newChrom; + return origChrom.newFixedLengthChromosome(newRepr); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/LineSearch.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/LineSearch.java index 4622df45a..1dab36529 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/LineSearch.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/LineSearch.java @@ -119,8 +119,7 @@ public class LineSearch { for (int i = 0; i < n; i++) { x[i] = startPoint[i] + alpha * direction[i]; } - final double obj = mainOptimizer.computeObjectiveValue(x); - return obj; + return mainOptimizer.computeObjectiveValue(x); } }; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/KolmogorovSmirnovTest.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/KolmogorovSmirnovTest.java index 44cb2c607..741b4ca58 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/KolmogorovSmirnovTest.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/KolmogorovSmirnovTest.java @@ -961,9 +961,7 @@ public class KolmogorovSmirnovTest { * \(D_{n,m}\) greater than {@code d} */ public double approximateP(double d, int n, int m) { - final double dm = m; - final double dn = n; - return 1 - ksSum(d * AccurateMath.sqrt((dm * dn) / (dm + dn)), + return 1 - ksSum(d * AccurateMath.sqrt(((double) m * (double) n) / ((double) m + (double) n)), KS_SUM_CAUCHY_CRITERION, MAXIMUM_PARTIAL_SUM_COUNT); } From dd294d7c919e7ae88641768f6ba710dcaa5a87eb Mon Sep 17 00:00:00 2001 From: Alex Herbert Date: Sat, 7 Aug 2021 13:39:12 +0100 Subject: [PATCH 2/2] Track changes Closes #194 --- src/changes/changes.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 04714991c..409bc3beb 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -97,6 +97,9 @@ Caveat: nightmare was one of the main reasons for creating more focused components.] "> + + Remove redundant local variables. + Simplify conditional expressions.