From d1123894d33922e7c8ca838f9dac9bdceefa3f7a Mon Sep 17 00:00:00 2001
From: Gilles
Date: Tue, 29 Dec 2015 01:49:36 +0100
Subject: [PATCH 1/6] Minor change.
Make method parameter names consistent (cf. MATH-1307).
---
.../commons/math4/random/BaseRandomGenerator.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
index da801b03b..bc6442e41 100644
--- a/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
@@ -228,17 +228,17 @@ public abstract class BaseRandomGenerator
*
*
* @param bytes Array in which to put the generated bytes. Cannot be {@code null}.
- * @param position Index at which to start inserting the generated bytes.
- * @param length Number of bytes to insert.
+ * @param start Index at which to start inserting the generated bytes.
+ * @param len Number of bytes to insert.
*/
private void nextBytesFill(byte[] bytes,
- int position,
- int length) {
- int index = position; // Index of first insertion.
+ int start,
+ int len) {
+ int index = start; // Index of first insertion.
// Index of first insertion plus multiple 4 part of length (i.e. length
// with two least significant bits unset).
- final int indexLoopLimit = index + (length & 0x7ffffffc);
+ final int indexLoopLimit = index + (len & 0x7ffffffc);
// Start filling in the byte array, 4 bytes at a time.
while (index < indexLoopLimit) {
@@ -249,7 +249,7 @@ public abstract class BaseRandomGenerator
bytes[index++] = (byte) (random >>> 24);
}
- final int indexLimit = position + length; // Index of last insertion + 1.
+ final int indexLimit = start + len; // Index of last insertion + 1.
// Fill in the remaining bytes.
if (index < indexLimit) {
From fb83ba3fdb46537a36832a900f124d4c400f7ed9 Mon Sep 17 00:00:00 2001
From: Dave Brosius
Date: Tue, 29 Dec 2015 13:52:48 -0500
Subject: [PATCH 2/6] push down allocations/calculations to where they are
needed
---
.../optim/nonlinear/scalar/noderiv/CMAESOptimizer.java | 10 ++++++----
.../math4/stat/interval/ClopperPearsonInterval.java | 4 ++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
index f76958563..727fd1848 100644
--- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
+++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
@@ -556,14 +556,16 @@ public class CMAESOptimizer
* Checks dimensions and values of boundaries and inputSigma if defined.
*/
private void checkParameters() {
- final double[] init = getStartPoint();
- final double[] lB = getLowerBound();
- final double[] uB = getUpperBound();
-
if (inputSigma != null) {
+ final double[] init = getStartPoint();
+
if (inputSigma.length != init.length) {
throw new DimensionMismatchException(inputSigma.length, init.length);
}
+
+ final double[] lB = getLowerBound();
+ final double[] uB = getUpperBound();
+
for (int i = 0; i < init.length; i++) {
if (inputSigma[i] > uB[i] - lB[i]) {
throw new OutOfRangeException(inputSigma[i], 0, uB[i] - lB[i]);
diff --git a/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java b/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
index 17dc9f55d..bf5d6ad6a 100644
--- a/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
+++ b/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
@@ -39,16 +39,16 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
final FDistribution distributionLowerBound = new FDistribution(2 * (numberOfTrials - numberOfSuccesses + 1),
2 * numberOfSuccesses);
- final double fValueLowerBound = distributionLowerBound.inverseCumulativeProbability(1 - alpha);
if (numberOfSuccesses > 0) {
+ final double fValueLowerBound = distributionLowerBound.inverseCumulativeProbability(1 - alpha);
lowerBound = numberOfSuccesses /
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
}
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
2 * (numberOfTrials - numberOfSuccesses));
- final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
if (numberOfSuccesses > 0) {
+ final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
}
From e779883b29a67d411493f985de984ffb8088ca05 Mon Sep 17 00:00:00 2001
From: Dave Brosius
Date: Tue, 29 Dec 2015 14:21:42 -0500
Subject: [PATCH 3/6] simplify: instanceof checks for nulls
---
.../math4/stat/descriptive/rank/PSquarePercentile.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java
index 79bdc5ead..7ba2d16ae 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java
@@ -159,7 +159,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
boolean result = false;
if (this == o) {
result = true;
- } else if (o != null && o instanceof PSquarePercentile) {
+ } else if (o instanceof PSquarePercentile) {
PSquarePercentile that = (PSquarePercentile) o;
boolean isNotNull = markers != null && that.markers != null;
boolean isNull = markers == null && that.markers == null;
@@ -410,7 +410,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
boolean result = false;
if (this == o) {
result = true;
- } else if (o != null && o instanceof Markers) {
+ } else if (o instanceof Markers) {
Markers that = (Markers) o;
result = Arrays.deepEquals(markerArray, that.markerArray);
}
@@ -802,7 +802,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
boolean result = false;
if (this == o) {
result = true;
- } else if (o != null && o instanceof Marker) {
+ } else if (o instanceof Marker) {
Marker that = (Marker) o;
result = Double.compare(markerHeight, that.markerHeight) == 0;
From a71c820baeb91025eaa7f07b172a39500c6f5692 Mon Sep 17 00:00:00 2001
From: Dave Brosius
Date: Tue, 29 Dec 2015 14:26:06 -0500
Subject: [PATCH 4/6] use short-circuiting ops
---
.../java/org/apache/commons/math4/util/ArithmeticUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java b/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java
index 4b5487536..bab02d371 100644
--- a/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java
+++ b/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java
@@ -650,7 +650,7 @@ public final class ArithmeticUtils {
*/
private static long addAndCheck(long a, long b, Localizable pattern) throws MathArithmeticException {
final long result = a + b;
- if (!((a ^ b) < 0 | (a ^ result) >= 0)) {
+ if (!((a ^ b) < 0 || (a ^ result) >= 0)) {
throw new MathArithmeticException(pattern, a, b);
}
return result;
From a4eff51bedd73a0ea56afc23b1021187dd03561b Mon Sep 17 00:00:00 2001
From: Dave Brosius
Date: Tue, 29 Dec 2015 14:31:35 -0500
Subject: [PATCH 5/6] simplify: remove dead params
---
.../commons/math4/analysis/solvers/LaguerreSolver.java | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java b/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java
index f233d42a0..b038abb96 100644
--- a/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java
+++ b/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java
@@ -113,7 +113,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
// Reduce interval if min and initial bracket the root.
if (yInitial * yMin < 0) {
- return laguerre(min, initial, yMin, yInitial);
+ return laguerre(min, initial);
}
// Return the second endpoint if it is good enough.
@@ -124,7 +124,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
// Reduce interval if initial and max bracket the root.
if (yInitial * yMax < 0) {
- return laguerre(initial, max, yInitial, yMax);
+ return laguerre(initial, max);
}
throw new NoBracketingException(min, max, yMin, yMax);
@@ -144,12 +144,9 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
*
* @param lo Lower bound of the search interval.
* @param hi Higher bound of the search interval.
- * @param fLo Function value at the lower bound of the search interval.
- * @param fHi Function value at the higher bound of the search interval.
* @return the point at which the function value is zero.
*/
- private double laguerre(double lo, double hi,
- double fLo, double fHi) {
+ private double laguerre(double lo, double hi) {
final Complex c[] = ComplexUtils.convertToComplex(getCoefficients());
final Complex initial = new Complex(0.5 * (lo + hi), 0);
From 8f6bedeb724fa78583c26423aaece05cfddc04c9 Mon Sep 17 00:00:00 2001
From: Gilles
Date: Thu, 31 Dec 2015 01:31:24 +0100
Subject: [PATCH 6/6] MATH-1309
Constructors should not call overridable methods, even indirectly.
---
.../java/org/apache/commons/math4/random/AbstractWell.java | 2 +-
.../java/org/apache/commons/math4/random/ISAACRandom.java | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/random/AbstractWell.java b/src/main/java/org/apache/commons/math4/random/AbstractWell.java
index 88cb2bbee..461e54747 100644
--- a/src/main/java/org/apache/commons/math4/random/AbstractWell.java
+++ b/src/main/java/org/apache/commons/math4/random/AbstractWell.java
@@ -134,7 +134,7 @@ public abstract class AbstractWell
*/
private void setSeedInternal(final int[] seed) {
if (seed == null) {
- setSeed(System.currentTimeMillis() + System.identityHashCode(this));
+ setSeedInternal(System.currentTimeMillis() + System.identityHashCode(this));
return;
}
diff --git a/src/main/java/org/apache/commons/math4/random/ISAACRandom.java b/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
index 185710f70..47597495f 100644
--- a/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
+++ b/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
@@ -131,7 +131,7 @@ public class ISAACRandom
* @param seed Seed.
*/
private void setSeedInternal(int seed) {
- setSeed(new int[]{seed});
+ setSeedInternal(new int[] { seed });
}
/**
@@ -140,7 +140,7 @@ public class ISAACRandom
* @param seed Seed.
*/
private void setSeedInternal(long seed) {
- setSeed(new int[]{(int) (seed >>> 32), (int) (seed & 0xffffffffL)});
+ setSeedInternal(new int[] { (int) (seed >>> 32), (int) (seed & 0xffffffffL) });
}
/**
@@ -150,7 +150,7 @@ public class ISAACRandom
*/
private void setSeedInternal(int[] seed) {
if (seed == null) {
- setSeed(System.currentTimeMillis() + System.identityHashCode(this));
+ setSeedInternal(System.currentTimeMillis() + System.identityHashCode(this));
return;
}
final int seedLen = seed.length;