This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-math.git
The following commit(s) were added to refs/heads/master by this push: new 199648a8a MATH-1569: Manual array copy. (#219) 199648a8a is described below commit 199648a8a1db107fb4c35f270c6983ca2173b846 Author: Arturo Bernal <arturobern...@gmail.com> AuthorDate: Tue Oct 25 22:34:17 2022 +0200 MATH-1569: Manual array copy. (#219) --- .../java/org/apache/commons/math4/legacy/core/dfp/Dfp.java | 12 +++++------- .../math4/legacy/analysis/solvers/LaguerreSolver.java | 5 +---- .../fitting/leastsquares/LevenbergMarquardtOptimizer.java | 4 +--- .../commons/math4/legacy/linear/HessenbergTransformer.java | 4 +--- .../legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java | 6 +++--- .../optim/nonlinear/scalar/noderiv/CMAESOptimizer.java | 4 ++-- .../commons/math4/neuralnet/twod/NeuronSquareMesh2D.java | 4 +--- .../resources/checkstyle/checkstyle-suppressions-legacy.xml | 2 +- 8 files changed, 15 insertions(+), 26 deletions(-) diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java index c94ccb594..f960635ae 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java @@ -663,8 +663,8 @@ public class Dfp implements RealFieldElement<Dfp> { /** Shift the mantissa left, and adjust the exponent to compensate. */ protected void shiftLeft() { - for (int i = mant.length - 1; i > 0; i--) { - mant[i] = mant[i - 1]; + if (mant.length - 1 > 0) { + System.arraycopy(mant, 0, mant, 1, mant.length - 1); } mant[0] = 0; exp--; @@ -675,8 +675,8 @@ public class Dfp implements RealFieldElement<Dfp> { /** Shift the mantissa right, and adjust the exponent to compensate. */ protected void shiftRight() { - for (int i = 0; i < mant.length - 1; i++) { - mant[i] = mant[i + 1]; + if (mant.length - 1 > 0) { + System.arraycopy(mant, 1, mant, 0, mant.length - 1); } mant[mant.length - 1] = 0; exp++; @@ -1849,9 +1849,7 @@ public class Dfp implements RealFieldElement<Dfp> { /* move the remainder into the dividend while left shifting */ dividend[0] = 0; - for (int i = 0; i < mant.length; i++) { - dividend[i + 1] = remainder[i]; - } + System.arraycopy(remainder, 0, dividend, 1, mant.length); } /* Find the most sig digit */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java index 00ffaa8cd..193427414 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java @@ -273,10 +273,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver { throw new NoDataException(LocalizedFormats.POLYNOMIAL); } // Coefficients for deflated polynomial. - final Complex[] c = new Complex[n + 1]; - for (int i = 0; i <= n; i++) { - c[i] = coefficients[i]; - } + final Complex[] c = coefficients.clone(); // Solve individual roots successively. final Complex[] root = new Complex[n]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java index c0751be8d..9fdbaf954 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java @@ -349,9 +349,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { //residuals already have weights applied double[] weightedResidual = currentResiduals; - for (int i = 0; i < nR; i++) { - qtf[i] = weightedResidual[i]; - } + System.arraycopy(weightedResidual, 0, qtf, 0, nR); // compute Qt.res qTy(qtf, internalData); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java index 8de71cc08..1474cfc40 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java @@ -150,9 +150,7 @@ class HessenbergTransformer { } // copy upper triangular part of the matrix - for (int j = i; j < m; ++j) { - h[i][j] = householderVectors[i][j]; - } + System.arraycopy(householderVectors[i], i, h[i], i, m - i); } cachedH = MatrixUtils.createRealMatrix(h); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java index 49d686bb4..f1c2c58ba 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java @@ -170,9 +170,9 @@ public final class AdamsNordsieckFieldTransformer<T extends RealFieldElement<T>> // Nordsieck to multistep, then shifting rows to represent step advance // then applying inverse transform T[][] shiftedP = bigP.getData(); - for (int i = shiftedP.length - 1; i > 0; --i) { - // shift rows - shiftedP[i] = shiftedP[i - 1]; + // shift rows + if (shiftedP.length - 1 > 0){ + System.arraycopy(shiftedP, 0, shiftedP, 1, shiftedP.length - 1); } shiftedP[0] = MathArrays.buildArray(field, rows); Arrays.fill(shiftedP[0], field.getZero()); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java index e61d2baef..1a6bf5c04 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java @@ -752,8 +752,8 @@ public class CMAESOptimizer * @param val Current best fitness value. */ private static void push(double[] vals, double val) { - for (int i = vals.length-1; i > 0; i--) { - vals[i] = vals[i-1]; + if (vals.length - 1 > 0) { + System.arraycopy(vals, 0, vals, 1, vals.length - 1); } vals[0] = val; } diff --git a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java index 92439ee48..a8e964945 100644 --- a/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java +++ b/commons-math-neuralnet/src/main/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2D.java @@ -235,9 +235,7 @@ public class NeuronSquareMesh2D public synchronized NeuronSquareMesh2D copy() { final long[][] idGrid = new long[numberOfRows][numberOfColumns]; for (int r = 0; r < numberOfRows; r++) { - for (int c = 0; c < numberOfColumns; c++) { - idGrid[r][c] = identifiers[r][c]; - } + System.arraycopy(identifiers[r], 0, idGrid[r], 0, numberOfColumns); } return new NeuronSquareMesh2D(wrapRows, diff --git a/src/main/resources/checkstyle/checkstyle-suppressions-legacy.xml b/src/main/resources/checkstyle/checkstyle-suppressions-legacy.xml index 041435200..49d94eb47 100644 --- a/src/main/resources/checkstyle/checkstyle-suppressions-legacy.xml +++ b/src/main/resources/checkstyle/checkstyle-suppressions-legacy.xml @@ -44,7 +44,7 @@ <suppress checks="UnnecessaryParentheses" files=".*[/\\]SparseGradient\.java$" lines="385,396" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]DerivativeStructure\.java$" lines="468,481" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleCurveFitter\.java$" lines="321-322" /> - <suppress checks="UnnecessaryParentheses" files=".*[/\\]LevenbergMarquardtOptimizer\.java$" lines="527,741" /> + <suppress checks="UnnecessaryParentheses" files=".*[/\\]LevenbergMarquardtOptimizer\.java$" lines="525,739" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]EnumeratedDistribution\.java$" lines="128-129" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleRegression\.java$" lines="823" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]MillerUpdatingRegression\.java$" lines="172-173" />