commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-math] 01/04: Use "Arrays.copyOf" from JDK.
Date Tue, 17 Dec 2019 01:35:51 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit ed6b06d02ff341a93d848fa34da23b9cb25c611f
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Tue Dec 17 01:59:57 2019 +0100

    Use "Arrays.copyOf" from JDK.
---
 .../org/apache/commons/math4/analysis/function/StepFunction.java | 4 ++--
 .../math4/distribution/MultivariateNormalDistribution.java       | 6 +++---
 .../MultivariateNormalMixtureExpectationMaximization.java        | 2 +-
 .../math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java     | 7 +++----
 .../math4/optim/nonlinear/scalar/noderiv/PowellOptimizer.java    | 4 ++--
 src/main/java/org/apache/commons/math4/special/BesselJ.java      | 9 +++++----
 .../apache/commons/math4/stat/descriptive/rank/Percentile.java   | 2 +-
 .../commons/math4/stat/inference/KolmogorovSmirnovTest.java      | 8 ++++----
 .../commons/math4/stat/regression/MillerUpdatingRegression.java  | 5 ++---
 .../apache/commons/math4/stat/regression/RegressionResults.java  | 6 +++---
 .../apache/commons/math4/transform/FastFourierTransformer.java   | 4 ++--
 11 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java b/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java
index 08461cb..3c3e5ad 100644
--- a/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java
+++ b/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java
@@ -75,8 +75,8 @@ public class StepFunction implements UnivariateFunction {
         }
         MathArrays.checkOrder(x);
 
-        abscissa = MathArrays.copyOf(x);
-        ordinate = MathArrays.copyOf(y);
+        abscissa = Arrays.copyOf(x, x.length);
+        ordinate = Arrays.copyOf(y, y.length);
     }
 
     /** {@inheritDoc} */
diff --git a/src/main/java/org/apache/commons/math4/distribution/MultivariateNormalDistribution.java
b/src/main/java/org/apache/commons/math4/distribution/MultivariateNormalDistribution.java
index 76046a8..0eb0d19 100644
--- a/src/main/java/org/apache/commons/math4/distribution/MultivariateNormalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/MultivariateNormalDistribution.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math4.distribution;
 
+import java.util.Arrays;
 import org.apache.commons.statistics.distribution.ContinuousDistribution;
 import org.apache.commons.statistics.distribution.NormalDistribution;
 import org.apache.commons.math4.exception.DimensionMismatchException;
@@ -26,7 +27,6 @@ import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.linear.SingularMatrixException;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * Implementation of the multivariate normal (Gaussian) distribution.
@@ -88,7 +88,7 @@ public class MultivariateNormalDistribution
             }
         }
 
-        this.means = MathArrays.copyOf(means);
+        this.means = Arrays.copyOf(means, means.length);
 
         covarianceMatrix = new Array2DRowRealMatrix(covariances);
 
@@ -135,7 +135,7 @@ public class MultivariateNormalDistribution
      * @return the mean vector.
      */
     public double[] getMeans() {
-        return MathArrays.copyOf(means);
+        return Arrays.copyOf(means, means.length);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/math4/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
b/src/main/java/org/apache/commons/math4/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
index 499a3df..7a7333b 100644
--- a/src/main/java/org/apache/commons/math4/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
+++ b/src/main/java/org/apache/commons/math4/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
@@ -103,7 +103,7 @@ public class MultivariateNormalMixtureExpectationMaximization {
                 throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_TOO_SMALL,
                                                     data[i].length, 2, true);
             }
-            this.data[i] = MathArrays.copyOf(data[i], data[i].length);
+            this.data[i] = Arrays.copyOf(data[i], data[i].length);
         }
     }
 
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 d207845..ffc2dd4 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
@@ -39,7 +39,6 @@ import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.statistics.distribution.ContinuousDistribution;
 import org.apache.commons.statistics.distribution.NormalDistribution;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * An implementation of the active Covariance Matrix Adaptation Evolution Strategy (CMA-ES)
@@ -433,9 +432,9 @@ public class CMAESOptimizer
             final int[] arindex = sortedIndices(fitness);
             // Calculate new xmean, this is selection and recombination
             final RealMatrix xold = xmean; // for speed up of Eq. (2) and (3)
-            final RealMatrix bestArx = selectColumns(arx, MathArrays.copyOf(arindex, mu));
+            final RealMatrix bestArx = selectColumns(arx, Arrays.copyOf(arindex, mu));
             xmean = bestArx.multiply(weights);
-            final RealMatrix bestArz = selectColumns(arz, MathArrays.copyOf(arindex, mu));
+            final RealMatrix bestArz = selectColumns(arz, Arrays.copyOf(arindex, mu));
             final RealMatrix zmean = bestArz.multiply(weights);
             final boolean hsig = updateEvolutionPaths(zmean, xold);
             if (diagonalOnly <= 0) {
@@ -731,7 +730,7 @@ public class CMAESOptimizer
                 final double negalphaold = 0.5;
                 // prepare vectors, compute negative updating matrix Cneg
                 final int[] arReverseIndex = reverse(arindex);
-                RealMatrix arzneg = selectColumns(arz, MathArrays.copyOf(arReverseIndex,
mu));
+                RealMatrix arzneg = selectColumns(arz, Arrays.copyOf(arReverseIndex, mu));
                 RealMatrix arnorms = sqrt(sumRows(square(arzneg)));
                 final int[] idxnorms = sortedIndices(arnorms.getRow(0));
                 final RealMatrix arnormsSorted = selectColumns(arnorms, idxnorms);
diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/PowellOptimizer.java
b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/PowellOptimizer.java
index f4d5fed..e4f7ef6 100644
--- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/PowellOptimizer.java
+++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/PowellOptimizer.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math4.optim.nonlinear.scalar.noderiv;
 
+import java.util.Arrays;
 import org.apache.commons.math4.exception.MathUnsupportedOperationException;
 import org.apache.commons.math4.exception.NotStrictlyPositiveException;
 import org.apache.commons.math4.exception.NumberIsTooSmallException;
@@ -27,7 +28,6 @@ import org.apache.commons.math4.optim.nonlinear.scalar.LineSearch;
 import org.apache.commons.math4.optim.nonlinear.scalar.MultivariateOptimizer;
 import org.apache.commons.math4.optim.univariate.UnivariatePointValuePair;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * Powell's algorithm.
@@ -192,7 +192,7 @@ public class PowellOptimizer
             double alphaMin = 0;
 
             for (int i = 0; i < n; i++) {
-                final double[] d = MathArrays.copyOf(direc[i]);
+                final double[] d = Arrays.copyOf(direc[i], direc[i].length);
 
                 fX2 = fVal;
 
diff --git a/src/main/java/org/apache/commons/math4/special/BesselJ.java b/src/main/java/org/apache/commons/math4/special/BesselJ.java
index 0e25eff..d91bc8b 100644
--- a/src/main/java/org/apache/commons/math4/special/BesselJ.java
+++ b/src/main/java/org/apache/commons/math4/special/BesselJ.java
@@ -17,6 +17,7 @@
 
 package org.apache.commons.math4.special;
 
+import java.util.Arrays;
 import org.apache.commons.numbers.gamma.Gamma;
 import org.apache.commons.math4.analysis.UnivariateFunction;
 import org.apache.commons.math4.exception.ConvergenceException;
@@ -205,7 +206,7 @@ public class BesselJ
          * @param n count of valid values
          */
         public BesselJResult(double[] b, int n) {
-            vals = MathArrays.copyOf(b, b.length);
+            vals = Arrays.copyOf(b, b.length);
             nVals = n;
         }
 
@@ -213,7 +214,7 @@ public class BesselJ
          * @return the computed function values
          */
         public double[] getVals() {
-            return MathArrays.copyOf(vals, vals.length);
+            return Arrays.copyOf(vals, vals.length);
         }
 
         /**
@@ -373,7 +374,7 @@ public class BesselJ
                     capq = (capq + 1) * ((gnu * gnu) - 1) * (0.125 / x);
                     b[i - 1] = xc * (capp * vcos - capq * vsin);
                     if (nb == 1) {
-                        return new BesselJResult(MathArrays.copyOf(b, b.length),
+                        return new BesselJResult(Arrays.copyOf(b, b.length),
                                                  ncalc);
                     }
                     t = vsin;
@@ -644,6 +645,6 @@ public class BesselJ
             }
             ncalc = FastMath.min(nb, 0) - 1;
         }
-        return new BesselJResult(MathArrays.copyOf(b, b.length), ncalc);
+        return new BesselJResult(Arrays.copyOf(b, b.length), ncalc);
     }
 }
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java
b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java
index c05d782..2015d7c 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java
@@ -434,7 +434,7 @@ public class Percentile extends AbstractUnivariateStatistic implements
Serializa
      */
     private static double[] copyOf(final double[] values, final int begin, final int length)
{
         MathArrays.verifyValues(values, begin, length);
-        return MathArrays.copyOfRange(values, begin, begin + length);
+        return Arrays.copyOfRange(values, begin, begin + length);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
index 18dbf8c..d62371a 100644
--- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
+++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
@@ -207,8 +207,8 @@ public class KolmogorovSmirnovTest {
         double[] xa = null;
         double[] ya = null;
         if (lengthProduct < LARGE_SAMPLE_PRODUCT && hasTies(x,y)) {
-            xa = MathArrays.copyOf(x);
-            ya = MathArrays.copyOf(y);
+            xa = Arrays.copyOf(x, x.length);
+            ya = Arrays.copyOf(y, y.length);
             fixTies(xa, ya);
         } else {
             xa = x;
@@ -276,8 +276,8 @@ public class KolmogorovSmirnovTest {
         checkArray(x);
         checkArray(y);
         // Copy and sort the sample arrays
-        final double[] sx = MathArrays.copyOf(x);
-        final double[] sy = MathArrays.copyOf(y);
+        final double[] sx = Arrays.copyOf(x, x.length);
+        final double[] sy = Arrays.copyOf(y, y.length);
         Arrays.sort(sx);
         Arrays.sort(sy);
         final int n = sx.length;
diff --git a/src/main/java/org/apache/commons/math4/stat/regression/MillerUpdatingRegression.java
b/src/main/java/org/apache/commons/math4/stat/regression/MillerUpdatingRegression.java
index e3b563b..c35d629 100644
--- a/src/main/java/org/apache/commons/math4/stat/regression/MillerUpdatingRegression.java
+++ b/src/main/java/org/apache/commons/math4/stat/regression/MillerUpdatingRegression.java
@@ -20,7 +20,6 @@ import java.util.Arrays;
 
 import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.numbers.core.Precision;
 
 /**
@@ -176,7 +175,7 @@ public class MillerUpdatingRegression implements UpdatingMultipleLinearRegressio
                     x.length, nvars);
         }
         if (!this.hasIntercept) {
-            include(MathArrays.copyOf(x, x.length), 1.0, y);
+            include(Arrays.copyOf(x, x.length), 1.0, y);
         } else {
             final double[] tmp = new double[x.length + 1];
             System.arraycopy(x, 0, tmp, 1, x.length);
@@ -897,7 +896,7 @@ public class MillerUpdatingRegression implements UpdatingMultipleLinearRegressio
      * @return int[] with the current order of the regressors
      */
     public int[] getOrderOfRegressors(){
-        return MathArrays.copyOf(vorder);
+        return Arrays.copyOf(vorder, vorder.length);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/math4/stat/regression/RegressionResults.java
b/src/main/java/org/apache/commons/math4/stat/regression/RegressionResults.java
index 8a2a7fa..28e05fc 100644
--- a/src/main/java/org/apache/commons/math4/stat/regression/RegressionResults.java
+++ b/src/main/java/org/apache/commons/math4/stat/regression/RegressionResults.java
@@ -98,10 +98,10 @@ public class RegressionResults implements Serializable {
             final boolean containsConstant,
             final boolean copyData) {
         if (copyData) {
-            this.parameters = MathArrays.copyOf(parameters);
+            this.parameters = Arrays.copyOf(parameters, parameters.length);
             this.varCovData = new double[varcov.length][];
             for (int i = 0; i < varcov.length; i++) {
-                this.varCovData[i] = MathArrays.copyOf(varcov[i]);
+                this.varCovData[i] = Arrays.copyOf(varcov[i], varcov[i].length);
             }
         } else {
             this.parameters = parameters;
@@ -171,7 +171,7 @@ public class RegressionResults implements Serializable {
         if (this.parameters == null) {
             return null;
         }
-        return MathArrays.copyOf(parameters);
+        return Arrays.copyOf(parameters, parameters.length);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java
b/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java
index bd97ea8..2f69580 100644
--- a/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java
+++ b/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java
@@ -17,6 +17,7 @@
 package org.apache.commons.math4.transform;
 
 import java.io.Serializable;
+import java.util.Arrays;
 import org.apache.commons.numbers.complex.Complex;
 import org.apache.commons.numbers.core.ArithmeticUtils;
 import org.apache.commons.math4.analysis.FunctionUtils;
@@ -26,7 +27,6 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.MathIllegalStateException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * Implements the Fast Fourier Transform for transformation of one-dimensional
@@ -365,7 +365,7 @@ public class FastFourierTransformer implements Serializable {
      */
     public Complex[] transform(final double[] f, final TransformType type) {
         final double[][] dataRI = new double[][] {
-            MathArrays.copyOf(f, f.length), new double[f.length]
+            Arrays.copyOf(f, f.length), new double[f.length]
         };
 
         transformInPlace(dataRI, normalization, type);


Mime
View raw message