You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/12/17 01:35:50 UTC

[commons-math] branch master updated (49f3afd -> f7e0d74)

This is an automated email from the ASF dual-hosted git repository.

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


    from 49f3afd  Method "ofReal" was removed from the API.
     new ed6b06d  Use "Arrays.copyOf" from JDK.
     new f4dd17a  Use "Arrays.copyOf" from JDK.
     new 6e5577a  Removed obsolete "copyOf" method.
     new f7e0d74  Unused "import" statements.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../math4/analysis/function/StepFunction.java      |   4 +-
 .../MultivariateNormalDistribution.java            |   6 +-
 ...ariateNormalMixtureExpectationMaximization.java |   2 +-
 .../field/linalg/FieldDecompositionSolver.java     |   2 -
 .../math4/field/linalg/FieldLUDecomposition.java   |   3 -
 .../geometry/euclidean/threed/FieldVector3D.java   |   1 -
 .../ode/nonstiff/AdamsNordsieckTransformer.java    |   4 -
 .../nonlinear/scalar/noderiv/CMAESOptimizer.java   |   7 +-
 .../nonlinear/scalar/noderiv/PowellOptimizer.java  |   4 +-
 .../org/apache/commons/math4/special/BesselJ.java  |  10 +-
 .../math4/stat/descriptive/rank/Percentile.java    |   2 +-
 .../stat/inference/KolmogorovSmirnovTest.java      |   9 +-
 .../stat/regression/MillerUpdatingRegression.java  |   5 +-
 .../math4/stat/regression/RegressionResults.java   |   7 +-
 .../math4/transform/FastFourierTransformer.java    |   4 +-
 .../org/apache/commons/math4/util/MathArrays.java  |  65 -----------
 .../leastsquares/StatisticalReferenceDataset.java  |  10 +-
 .../math4/linear/RealVectorAbstractTest.java       |   4 +-
 .../stat/descriptive/rank/PercentileTest.java      |   3 +-
 .../stat/inference/KolmogorovSmirnovTestTest.java  |  12 +-
 .../apache/commons/math4/util/MathArraysTest.java  | 128 +--------------------
 21 files changed, 43 insertions(+), 249 deletions(-)


[commons-math] 04/04: Unused "import" statements.

Posted by er...@apache.org.
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 f7e0d743526a9af68233a21e4af01810c1ded2b8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Dec 17 02:34:03 2019 +0100

    Unused "import" statements.
---
 .../apache/commons/math4/field/linalg/FieldDecompositionSolver.java   | 2 --
 .../org/apache/commons/math4/field/linalg/FieldLUDecomposition.java   | 3 ---
 .../apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java | 1 -
 .../apache/commons/math4/ode/nonstiff/AdamsNordsieckTransformer.java  | 4 ----
 src/main/java/org/apache/commons/math4/special/BesselJ.java           | 1 -
 .../apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java    | 1 -
 .../org/apache/commons/math4/stat/regression/RegressionResults.java   | 1 -
 7 files changed, 13 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/field/linalg/FieldDecompositionSolver.java b/src/main/java/org/apache/commons/math4/field/linalg/FieldDecompositionSolver.java
index 0136062..677ae06 100644
--- a/src/main/java/org/apache/commons/math4/field/linalg/FieldDecompositionSolver.java
+++ b/src/main/java/org/apache/commons/math4/field/linalg/FieldDecompositionSolver.java
@@ -17,8 +17,6 @@
 
 package org.apache.commons.math4.field.linalg;
 
-import java.util.List;
-
 /**
  * Interface handling decomposition algorithms that can solve {@code A X = B}.
  *
diff --git a/src/main/java/org/apache/commons/math4/field/linalg/FieldLUDecomposition.java b/src/main/java/org/apache/commons/math4/field/linalg/FieldLUDecomposition.java
index 137bcbd..0790979 100644
--- a/src/main/java/org/apache/commons/math4/field/linalg/FieldLUDecomposition.java
+++ b/src/main/java/org/apache/commons/math4/field/linalg/FieldLUDecomposition.java
@@ -17,11 +17,8 @@
 
 package org.apache.commons.math4.field.linalg;
 
-import java.util.List;
-import java.util.ArrayList;
 import org.apache.commons.numbers.field.Field;
 import org.apache.commons.math4.linear.SingularMatrixException;
-import org.apache.commons.math4.exception.DimensionMismatchException;
 
 /**
  * Calculates the LUP-decomposition of a square matrix.
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java
index 74d4d6f..5942ef5 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java
@@ -18,7 +18,6 @@
 package org.apache.commons.math4.geometry.euclidean.threed;
 
 import java.io.Serializable;
-import java.text.NumberFormat;
 
 import org.apache.commons.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math4.RealFieldElement;
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckTransformer.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckTransformer.java
index 60f5ee7..a233878 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckTransformer.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckTransformer.java
@@ -17,16 +17,12 @@
 
 package org.apache.commons.math4.ode.nonstiff;
 
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.numbers.fraction.BigFraction;
 import org.apache.commons.numbers.field.BigFractionField;
-import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
 import org.apache.commons.math4.linear.Array2DRowRealMatrix;
-import org.apache.commons.math4.linear.ArrayFieldVector;
-import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.QRDecomposition;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.field.linalg.FieldDenseMatrix;
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 d91bc8b..b34feea 100644
--- a/src/main/java/org/apache/commons/math4/special/BesselJ.java
+++ b/src/main/java/org/apache/commons/math4/special/BesselJ.java
@@ -24,7 +24,6 @@ import org.apache.commons.math4.exception.ConvergenceException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * This class provides computation methods related to Bessel
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 d62371a..e85cc09 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
@@ -17,7 +17,6 @@
 
 package org.apache.commons.math4.stat.inference;
 
-import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.Arrays;
 
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 28e05fc..9f462ed 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
@@ -21,7 +21,6 @@ import java.util.Arrays;
 
 import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * Results of a Multiple Linear Regression model fit.


[commons-math] 03/04: Removed obsolete "copyOf" method.

Posted by er...@apache.org.
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 6e5577ad8adff3aad503365a3e118453501bcfef
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Dec 17 02:18:44 2019 +0100

    Removed obsolete "copyOf" method.
---
 .../org/apache/commons/math4/util/MathArrays.java  |  65 -----------
 .../apache/commons/math4/util/MathArraysTest.java  | 128 +--------------------
 2 files changed, 1 insertion(+), 192 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java b/src/main/java/org/apache/commons/math4/util/MathArrays.java
index 0f7046e..a7488e2 100644
--- a/src/main/java/org/apache/commons/math4/util/MathArrays.java
+++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java
@@ -766,71 +766,6 @@ public class MathArrays {
     }
 
     /**
-     * Creates a copy of the {@code source} array.
-     *
-     * @param source Array to be copied.
-     * @return the copied array.
-     */
-     public static int[] copyOf(int[] source) {
-         return copyOf(source, source.length);
-     }
-
-    /**
-     * Creates a copy of the {@code source} array.
-     *
-     * @param source Array to be copied.
-     * @return the copied array.
-     */
-     public static double[] copyOf(double[] source) {
-         return copyOf(source, source.length);
-     }
-
-    /**
-     * Creates a copy of the {@code source} array.
-     *
-     * @param source Array to be copied.
-     * @param len Number of entries to copy. If smaller then the source
-     * length, the copy will be truncated, if larger it will padded with
-     * zeroes.
-     * @return the copied array.
-     */
-    public static int[] copyOf(int[] source, int len) {
-         final int[] output = new int[len];
-         System.arraycopy(source, 0, output, 0, FastMath.min(len, source.length));
-         return output;
-     }
-
-    /**
-     * Creates a copy of the {@code source} array.
-     *
-     * @param source Array to be copied.
-     * @param len Number of entries to copy. If smaller then the source
-     * length, the copy will be truncated, if larger it will padded with
-     * zeroes.
-     * @return the copied array.
-     */
-    public static double[] copyOf(double[] source, int len) {
-         final double[] output = new double[len];
-         System.arraycopy(source, 0, output, 0, FastMath.min(len, source.length));
-         return output;
-     }
-
-    /**
-     * Creates a copy of the {@code source} array.
-     *
-     * @param source Array to be copied.
-     * @param from Initial index of the range to be copied, inclusive.
-     * @param to Final index of the range to be copied, exclusive. (This index may lie outside the array.)
-     * @return the copied array.
-     */
-    public static double[] copyOfRange(double[] source, int from, int to) {
-        final int len = to - from;
-        final double[] output = new double[len];
-        System.arraycopy(source, from, output, 0, FastMath.min(len, source.length - from));
-        return output;
-     }
-
-    /**
      * Returns true iff both arguments are null or have same dimensions and all
      * their elements are equal as defined by
      * {@link Precision#equals(float,float)}.
diff --git a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
index f4a5e6c..87ab07e 100644
--- a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
@@ -48,7 +48,7 @@ public class MathArraysTest {
     @Test
     public void testScale() {
         final double[] test = new double[] { -2.5, -1, 0, 1, 2.5 };
-        final double[] correctTest = MathArrays.copyOf(test);
+        final double[] correctTest = Arrays.copyOf(test, test.length);
         final double[] correctScaled = new double[]{5.25, 2.1, 0, -2.1, -5.25};
 
         final double[] scaled = MathArrays.scale(-2.1, test);
@@ -543,132 +543,6 @@ public class MathArraysTest {
     }
 
     @Test
-    public void testCopyOfInt() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int[] dest = MathArrays.copyOf(source);
-
-        Assert.assertEquals(dest.length, source.length);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-    }
-
-    @Test
-    public void testCopyOfInt2() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int offset = 3;
-        final int[] dest = MathArrays.copyOf(source, source.length - offset);
-
-        Assert.assertEquals(dest.length, source.length - offset);
-        for (int i = 0; i < source.length - offset; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-    }
-
-    @Test
-    public void testCopyOfInt3() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int offset = 3;
-        final int[] dest = MathArrays.copyOf(source, source.length + offset);
-
-        Assert.assertEquals(dest.length, source.length + offset);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-        for (int i = source.length; i < source.length + offset; i++) {
-            Assert.assertEquals(0, dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  FastMath.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final double[] dest = MathArrays.copyOf(source);
-
-        Assert.assertEquals(dest.length, source.length);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble2() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  FastMath.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final int offset = 3;
-        final double[] dest = MathArrays.copyOf(source, source.length - offset);
-
-        Assert.assertEquals(dest.length, source.length - offset);
-        for (int i = 0; i < source.length - offset; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble3() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  FastMath.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final int offset = 3;
-        final double[] dest = MathArrays.copyOf(source, source.length + offset);
-
-        Assert.assertEquals(dest.length, source.length + offset);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-        for (int i = source.length; i < source.length + offset; i++) {
-            Assert.assertEquals(0, dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfRange() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  FastMath.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final int from = 3;
-        final int to = source.length + 14;
-        final double[] dest = MathArrays.copyOfRange(source, from, to);
-
-        Assert.assertEquals(dest.length, to - from);
-        for (int i = from; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i - from], 0);
-        }
-        for (int i = source.length; i < dest.length; i++) {
-            Assert.assertEquals(0, dest[i - from], 0);
-        }
-    }
-
-    @Test
     public void testArrayEquals() {
         Assert.assertFalse(MathArrays.equals(new double[] { 1d }, null));
         Assert.assertFalse(MathArrays.equals(null, new double[] { 1d }));


[commons-math] 01/04: Use "Arrays.copyOf" from JDK.

Posted by er...@apache.org.
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 <gi...@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);


[commons-math] 02/04: Use "Arrays.copyOf" from JDK.

Posted by er...@apache.org.
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 f4dd17aa7d68509e41c906dd8e53265985b878b4
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Dec 17 02:17:55 2019 +0100

    Use "Arrays.copyOf" from JDK.
---
 .../fitting/leastsquares/StatisticalReferenceDataset.java    | 10 +++++-----
 .../apache/commons/math4/linear/RealVectorAbstractTest.java  |  4 ++--
 .../commons/math4/stat/descriptive/rank/PercentileTest.java  |  3 +--
 .../math4/stat/inference/KolmogorovSmirnovTestTest.java      | 12 ++++++------
 4 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/test/java/org/apache/commons/math4/fitting/leastsquares/StatisticalReferenceDataset.java b/src/test/java/org/apache/commons/math4/fitting/leastsquares/StatisticalReferenceDataset.java
index 491a463..9af6c8b 100644
--- a/src/test/java/org/apache/commons/math4/fitting/leastsquares/StatisticalReferenceDataset.java
+++ b/src/test/java/org/apache/commons/math4/fitting/leastsquares/StatisticalReferenceDataset.java
@@ -19,10 +19,10 @@ package org.apache.commons.math4.fitting.leastsquares;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.apache.commons.math4.analysis.MultivariateMatrixFunction;
 import org.apache.commons.math4.analysis.MultivariateVectorFunction;
-import org.apache.commons.math4.util.MathArrays;
 
 /**
  * This class gives access to the statistical reference datasets provided by the
@@ -199,7 +199,7 @@ public abstract class StatisticalReferenceDataset {
      */
     public double[][] getData() {
         return new double[][] {
-            MathArrays.copyOf(x), MathArrays.copyOf(y)
+            Arrays.copyOf(x, x.length), Arrays.copyOf(y, y.length)
         };
     }
 
@@ -238,7 +238,7 @@ public abstract class StatisticalReferenceDataset {
      * @return the values of the parameters
      */
     public double[] getParameters() {
-        return MathArrays.copyOf(a);
+        return Arrays.copyOf(a, a.length);
     }
 
     /**
@@ -257,7 +257,7 @@ public abstract class StatisticalReferenceDataset {
      * @return the standard deviations of the parameters
      */
     public double[] getParametersStandardDeviations() {
-        return MathArrays.copyOf(sigA);
+        return Arrays.copyOf(sigA, sigA.length);
     }
 
     /**
@@ -297,7 +297,7 @@ public abstract class StatisticalReferenceDataset {
      * @return the starting point
      */
     public double[] getStartingPoint(final int i) {
-        return MathArrays.copyOf(startingValues[i]);
+        return Arrays.copyOf(startingValues[i], startingValues[i].length);
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/math4/linear/RealVectorAbstractTest.java b/src/test/java/org/apache/commons/math4/linear/RealVectorAbstractTest.java
index 0324ffc..167566e 100644
--- a/src/test/java/org/apache/commons/math4/linear/RealVectorAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/RealVectorAbstractTest.java
@@ -223,7 +223,7 @@ public abstract class RealVectorAbstractTest {
     public void testSetEntry() {
         final double x = getPreferredEntryValue();
         final double[] data = {x, 1d, 2d, x, x};
-        final double[] expected = MathArrays.copyOf(data);
+        final double[] expected = Arrays.copyOf(data, data.length);
         final RealVector actual = create(data);
 
         /*
@@ -270,7 +270,7 @@ public abstract class RealVectorAbstractTest {
         final double x = getPreferredEntryValue();
         final double[] data1 = {x, 1d, 2d, x, x};
 
-        final double[] expected = MathArrays.copyOf(data1);
+        final double[] expected = Arrays.copyOf(data1, data1.length);
         final RealVector actual = create(data1);
 
         /*
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
index aa2c4c1..b56c610 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
@@ -32,7 +32,6 @@ import org.apache.commons.math4.stat.descriptive.rank.Percentile.EstimationType;
 import org.apache.commons.math4.stat.ranking.NaNStrategy;
 import org.apache.commons.math4.util.CentralPivotingStrategy;
 import org.apache.commons.math4.util.KthSelector;
-import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.MedianOf3PivotingStrategy;
 import org.apache.commons.math4.util.PivotingStrategyInterface;
 import org.apache.commons.math4.util.RandomPivotingStrategy;
@@ -630,7 +629,7 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
     public void testAllEstimationTechniquesOnlyLimits() {
         final int N=testArray.length;
 
-        final double[] input=MathArrays.copyOf(testArray);
+        final double[] input = Arrays.copyOf(testArray, testArray.length);
         Arrays.sort(input);
         final double min = input[0];
         final double max=input[input.length-1];
diff --git a/src/test/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTestTest.java b/src/test/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTestTest.java
index e0cea55..852d4f4 100644
--- a/src/test/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTestTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTestTest.java
@@ -709,8 +709,8 @@ public class KolmogorovSmirnovTestTest {
     public void testFixTiesNoOp() throws Exception {
         final double[] x = {0, 1, 2, 3, 4};
         final double[] y = {5, 6, 7, 8};
-        final double[] origX = MathArrays.copyOf(x);
-        final double[] origY = MathArrays.copyOf(y);
+        final double[] origX = Arrays.copyOf(x, x.length);
+        final double[] origY = Arrays.copyOf(y, y.length);
         fixTies(x,y);
         Assert.assertArrayEquals(origX, x, 0);
         Assert.assertArrayEquals(origY, y, 0);
@@ -724,11 +724,11 @@ public class KolmogorovSmirnovTestTest {
     public void testFixTiesConsistency() throws Exception {
         final double[] x = {0, 1, 2, 3, 4, 2};
         final double[] y = {5, 6, 7, 8, 1, 2};
-        final double[] xP = MathArrays.copyOf(x);
-        final double[] yP = MathArrays.copyOf(y);
+        final double[] xP = Arrays.copyOf(x, x.length);
+        final double[] yP = Arrays.copyOf(y, y.length);
         checkFixTies(x, y);
-        final double[] fixedX = MathArrays.copyOf(x);
-        final double[] fixedY = MathArrays.copyOf(y);
+        final double[] fixedX = Arrays.copyOf(x, x.length);
+        final double[] fixedY = Arrays.copyOf(y, y.length);
         checkFixTies(xP, yP);
         Assert.assertArrayEquals(fixedX, xP, 0);
         Assert.assertArrayEquals(fixedY, yP, 0);