Avoid array declarations written in C-style syntax and replace it with java.

Closes #202.
This commit is contained in:
Arturo Bernal 2022-01-18 19:28:55 +01:00 committed by Gilles Sadowski
parent 49f220cbcb
commit 645d85a8c7
23 changed files with 55 additions and 55 deletions

View File

@ -416,7 +416,7 @@ public final class FunctionUtils {
final double[] partials = new double[point.length];
final double[] packed = new double[parameters + 1];
packed[0] = v;
final int orders[] = new int[parameters];
final int[] orders = new int[parameters];
for (int i = 0; i < parameters; ++i) {
// we differentiate once with respect to parameter i

View File

@ -94,8 +94,8 @@ public class RombergIntegrator extends BaseAbstractUnivariateIntegrator {
@Override
protected double doIntegrate() {
final int m = iterations.getMaximalCount() + 1;
double previousRow[] = new double[m];
double currentRow[] = new double[m];
double[] previousRow = new double[m];
double[] currentRow = new double[m];
TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
currentRow[0] = qtrap.stage(this, 0);

View File

@ -48,7 +48,7 @@ public class DividedDifferenceInterpolator
* strictly increasing order.
*/
@Override
public PolynomialFunctionNewtonForm interpolate(double x[], double y[])
public PolynomialFunctionNewtonForm interpolate(double[] x, double[] y)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {
@ -93,7 +93,7 @@ public class DividedDifferenceInterpolator
* @throws NonMonotonicSequenceException
* if {@code x} is not sorted in strictly increasing order.
*/
protected static double[] computeDividedDifference(final double x[], final double y[])
protected static double[] computeDividedDifference(final double[] x, final double[] y)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {

View File

@ -43,7 +43,7 @@ public class LinearInterpolator implements UnivariateInterpolator {
* than 2.
*/
@Override
public PolynomialSplineFunction interpolate(double x[], double y[])
public PolynomialSplineFunction interpolate(double[] x, double[] y)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {
@ -62,13 +62,13 @@ public class LinearInterpolator implements UnivariateInterpolator {
MathArrays.checkOrder(x);
// Slope of the lines between the datapoints.
final double m[] = new double[n];
final double[] m = new double[n];
for (int i = 0; i < n; i++) {
m[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]);
}
final PolynomialFunction polynomials[] = new PolynomialFunction[n];
final double coefficients[] = new double[2];
final PolynomialFunction[] polynomials = new PolynomialFunction[n];
final double[] coefficients = new double[2];
for (int i = 0; i < n; i++) {
coefficients[0] = y[i];
coefficients[1] = m[i];

View File

@ -45,7 +45,7 @@ public class NevilleInterpolator implements UnivariateInterpolator {
* value.
*/
@Override
public PolynomialFunctionLagrangeForm interpolate(double x[], double y[])
public PolynomialFunctionLagrangeForm interpolate(double[] x, double[] y)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {

View File

@ -122,10 +122,10 @@ public class PiecewiseBicubicSplineInterpolatingFunction
final int i = searchIndex(x, xval, offset, count);
final int j = searchIndex(y, yval, offset, count);
final double xArray[] = new double[count];
final double yArray[] = new double[count];
final double zArray[] = new double[count];
final double interpArray[] = new double[count];
final double[] xArray = new double[count];
final double[] yArray = new double[count];
final double[] zArray = new double[count];
final double[] interpArray = new double[count];
for (int index = 0; index < count; index++) {
xArray[index] = xval[i + index];

View File

@ -63,7 +63,7 @@ public class SplineInterpolator implements UnivariateInterpolator {
* than 3.
*/
@Override
public PolynomialSplineFunction interpolate(double x[], double y[])
public PolynomialSplineFunction interpolate(double[] x, double[] y)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {

View File

@ -36,6 +36,6 @@ public interface UnivariateInterpolator {
* algorithm.
* @throws DimensionMismatchException if arrays lengths do not match
*/
UnivariateFunction interpolate(double xval[], double yval[])
UnivariateFunction interpolate(double[] xval, double[] yval)
throws MathIllegalArgumentException, DimensionMismatchException;
}

View File

@ -39,7 +39,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction {
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private final double coefficients[];
private final double[] coefficients;
/**
* Construct a polynomial with the given coefficients. The first element
@ -55,7 +55,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction {
* @throws NullArgumentException if {@code c} is {@code null}.
* @throws NoDataException if {@code c} is empty.
*/
public PolynomialFunction(double c[])
public PolynomialFunction(double[] c)
throws NullArgumentException, NoDataException {
super();
NullArgumentException.check(c);

View File

@ -42,15 +42,15 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private double coefficients[];
private double[] coefficients;
/**
* Interpolating points (abscissas).
*/
private final double x[];
private final double[] x;
/**
* Function values at interpolating points.
*/
private final double y[];
private final double[] y;
/**
* Whether the polynomial coefficients are available.
*/
@ -69,7 +69,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
* @throws NonMonotonicSequenceException
* if two abscissae have the same value.
*/
public PolynomialFunctionLagrangeForm(double x[], double y[])
public PolynomialFunctionLagrangeForm(double[] x, double[] y)
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
this.x = new double[x.length];
this.y = new double[y.length];
@ -171,7 +171,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
* @throws NumberIsTooSmallException if the size of {@code x} is less
* than 2.
*/
public static double evaluate(double x[], double y[], double z)
public static double evaluate(double[] x, double[] y, double z)
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
if (verifyInterpolationArray(x, y, false)) {
return evaluateInternal(x, y, z);
@ -205,7 +205,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
* @throws NumberIsTooSmallException if the size of {@code x} is less
* than 2.
*/
private static double evaluateInternal(double x[], double y[], double z) {
private static double evaluateInternal(double[] x, double[] y, double z) {
int nearest = 0;
final int n = x.length;
final double[] c = new double[n];
@ -314,7 +314,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
* @see #evaluate(double[], double[], double)
* @see #computeCoefficients()
*/
public static boolean verifyInterpolationArray(double x[], double y[], boolean abort)
public static boolean verifyInterpolationArray(double[] x, double[] y, boolean abort)
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
if (x.length != y.length) {
throw new DimensionMismatchException(x.length, y.length);

View File

@ -42,18 +42,18 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private double coefficients[];
private double[] coefficients;
/**
* Centers of the Newton polynomial.
*/
private final double c[];
private final double[] c;
/**
* When all c[i] = 0, a[] becomes normal polynomial coefficients,
* i.e. a[i] = coefficients[i].
*/
private final double a[];
private final double[] a;
/**
* Whether the polynomial coefficients are available.
@ -74,7 +74,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
* @throws DimensionMismatchException if the size difference between
* {@code a} and {@code c} is not equal to 1.
*/
public PolynomialFunctionNewtonForm(double a[], double c[])
public PolynomialFunctionNewtonForm(double[] a, double[] c)
throws NullArgumentException, NoDataException, DimensionMismatchException {
verifyInputArray(a, c);
@ -179,7 +179,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
* @throws DimensionMismatchException if the size difference between
* {@code a} and {@code c} is not equal to 1.
*/
public static double evaluate(double a[], double c[], double z)
public static double evaluate(double[] a, double[] c, double z)
throws NullArgumentException, DimensionMismatchException, NoDataException {
verifyInputArray(a, c);
@ -230,7 +230,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
* @see org.apache.commons.math4.legacy.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[],
* double[])
*/
protected static void verifyInputArray(double a[], double c[])
protected static void verifyInputArray(double[] a, double[] c)
throws NullArgumentException, NoDataException, DimensionMismatchException {
NullArgumentException.check(a);
NullArgumentException.check(c);

View File

@ -66,7 +66,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* Spline segment interval delimiters (knots).
* Size is n + 1 for n segments.
*/
private final double knots[];
private final double[] knots;
/**
* The polynomial functions that make up the spline. The first element
* determines the value of the spline over the first subinterval, the
@ -74,7 +74,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* evaluating these functions at {@code (x - knot[i])} where i is the
* knot segment to which x belongs.
*/
private final PolynomialFunction polynomials[];
private final PolynomialFunction[] polynomials;
/**
* Number of spline segments. It is equal to the number of polynomials and
* to the number of partition points - 1.
@ -96,7 +96,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* @throws NonMonotonicSequenceException if the {@code knots} array is not strictly increasing.
*
*/
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[])
public PolynomialSplineFunction(double[] knots, PolynomialFunction[] polynomials)
throws NullArgumentException, NumberIsTooSmallException,
DimensionMismatchException, NonMonotonicSequenceException{
if (knots == null ||
@ -154,7 +154,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* @return the derivative function.
*/
public PolynomialSplineFunction polynomialSplineDerivative() {
PolynomialFunction derivativePolynomials[] = new PolynomialFunction[n];
PolynomialFunction[] derivativePolynomials = new PolynomialFunction[n];
for (int i = 0; i < n; i++) {
derivativePolynomials[i] = polynomials[i].polynomialDerivative();
}
@ -202,7 +202,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* @return the interpolating polynomials.
*/
public PolynomialFunction[] getPolynomials() {
PolynomialFunction p[] = new PolynomialFunction[n];
PolynomialFunction[] p = new PolynomialFunction[n];
System.arraycopy(polynomials, 0, p, 0, n);
return p;
}
@ -215,7 +215,7 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
* @return the knot points.
*/
public double[] getKnots() {
double out[] = new double[n + 1];
double[] out = new double[n + 1];
System.arraycopy(knots, 0, out, 0, n + 1);
return out;
}

View File

@ -146,7 +146,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
* @return the point at which the function value is zero.
*/
private double laguerre(double lo, double hi) {
final Complex c[] = real2Complex(getCoefficients());
final Complex[] c = real2Complex(getCoefficients());
final Complex initial = Complex.ofCartesian(0.5 * (lo + hi), 0);
final Complex z = complexSolver.solve(c, initial);
@ -261,7 +261,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
* {@code null}.
* @throws NoDataException if the {@code coefficients} array is empty.
*/
public Complex[] solveAll(Complex coefficients[], Complex initial)
public Complex[] solveAll(Complex[] coefficients, Complex initial)
throws NullArgumentException,
NoDataException,
TooManyEvaluationsException {
@ -273,15 +273,15 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
throw new NoDataException(LocalizedFormats.POLYNOMIAL);
}
// Coefficients for deflated polynomial.
final Complex c[] = new Complex[n + 1];
final Complex[] c = new Complex[n + 1];
for (int i = 0; i <= n; i++) {
c[i] = coefficients[i];
}
// Solve individual roots successively.
final Complex root[] = new Complex[n];
final Complex[] root = new Complex[n];
for (int i = 0; i < n; i++) {
final Complex subarray[] = new Complex[n - i + 1];
final Complex[] subarray = new Complex[n - i + 1];
System.arraycopy(c, 0, subarray, 0, subarray.length);
root[i] = solve(subarray, initial);
// Polynomial deflation using synthetic division.
@ -310,7 +310,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
* {@code null}.
* @throws NoDataException if the {@code coefficients} array is empty.
*/
public Complex solve(Complex coefficients[], Complex initial)
public Complex solve(Complex[] coefficients, Complex initial)
throws NullArgumentException,
NoDataException,
TooManyEvaluationsException {

View File

@ -195,7 +195,7 @@ public final class HarmonicCurveFitter extends SimpleCurveFitter {
final WeightedObservedPoint[] sorted
= sortObservations(observations).toArray(new WeightedObservedPoint[0]);
final double aOmega[] = guessAOmega(sorted);
final double[] aOmega = guessAOmega(sorted);
final double a = aOmega[0];
final double omega = aOmega[1];

View File

@ -37,7 +37,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
private static final long serialVersionUID = -1067294169172445528L;
/** Entries of the matrix. */
private double data[][];
private double[][] data;
/**
* Creates a matrix with no data.

View File

@ -41,7 +41,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
private static final RealVectorFormat DEFAULT_FORMAT = RealVectorFormat.getInstance();
/** Entries of the vector. */
private double data[];
private double[] data;
/**
* Build a 0-length vector.

View File

@ -37,7 +37,7 @@ import org.apache.commons.math4.core.jdkmath.JdkMath;
class BiDiagonalTransformer {
/** Householder vectors. */
private final double householderVectors[][];
private final double[][] householderVectors;
/** Main diagonal. */
private final double[] main;

View File

@ -76,7 +76,7 @@ public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
/** Serializable version identifier. */
private static final long serialVersionUID = -4602336630143123183L;
/** Blocks of matrix entries. */
private final T blocks[][];
private final T[][] blocks;
/** Number of rows of the matrix. */
private final int rows;
/** Number of columns of the matrix. */

View File

@ -73,7 +73,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable
/** Serializable version identifier. */
private static final long serialVersionUID = 4991895511313664478L;
/** Blocks of matrix entries. */
private final double blocks[][];
private final double[][] blocks;
/** Number of rows of the matrix. */
private final int rows;
/** Number of columns of the matrix. */

View File

@ -40,9 +40,9 @@ import org.apache.commons.numbers.core.Precision;
*/
class HessenbergTransformer {
/** Householder vectors. */
private final double householderVectors[][];
private final double[][] householderVectors;
/** Temporary storage vector. */
private final double ort[];
private final double[] ort;
/** Cached value of P. */
private RealMatrix cachedP;
/** Cached value of Pt. */

View File

@ -46,9 +46,9 @@ class SchurTransformer {
private static final int MAX_ITERATIONS = 100;
/** P matrix. */
private final double matrixP[][];
private final double[][] matrixP;
/** T matrix. */
private final double matrixT[][];
private final double[][] matrixT;
/** Cached value of P. */
private RealMatrix cachedP;
/** Cached value of T. */

View File

@ -38,7 +38,7 @@ import org.apache.commons.math4.core.jdkmath.JdkMath;
*/
class TriDiagonalTransformer {
/** Householder vectors. */
private final double householderVectors[][];
private final double[][] householderVectors;
/** Main diagonal. */
private final double[] main;
/** Secondary diagonal. */

View File

@ -1041,7 +1041,7 @@ public class KolmogorovSmirnovTest {
final int sum = nn + mm;
int tail = 0;
final boolean b[] = new boolean[sum];
final boolean[] b = new boolean[sum];
for (int i = 0; i < iterations; i++) {
fillBooleanArrayRandomlyWithFixedNumberTrueValues(b, nn, rng);
long curD = 0L;