Use "Arrays.copyOf" from JDK.
This commit is contained in:
parent
49f3afd6b8
commit
ed6b06d02f
|
@ -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} */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue