MATH-1569: Manual array copy. (#219)

This commit is contained in:
Arturo Bernal 2022-10-25 22:34:17 +02:00 committed by GitHub
parent 3f043ba7e1
commit 199648a8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 26 deletions

View File

@ -663,8 +663,8 @@ public class Dfp implements RealFieldElement<Dfp> {
/** Shift the mantissa left, and adjust the exponent to compensate. /** Shift the mantissa left, and adjust the exponent to compensate.
*/ */
protected void shiftLeft() { protected void shiftLeft() {
for (int i = mant.length - 1; i > 0; i--) { if (mant.length - 1 > 0) {
mant[i] = mant[i - 1]; System.arraycopy(mant, 0, mant, 1, mant.length - 1);
} }
mant[0] = 0; mant[0] = 0;
exp--; exp--;
@ -675,8 +675,8 @@ public class Dfp implements RealFieldElement<Dfp> {
/** Shift the mantissa right, and adjust the exponent to compensate. /** Shift the mantissa right, and adjust the exponent to compensate.
*/ */
protected void shiftRight() { protected void shiftRight() {
for (int i = 0; i < mant.length - 1; i++) { if (mant.length - 1 > 0) {
mant[i] = mant[i + 1]; System.arraycopy(mant, 1, mant, 0, mant.length - 1);
} }
mant[mant.length - 1] = 0; mant[mant.length - 1] = 0;
exp++; exp++;
@ -1849,9 +1849,7 @@ public class Dfp implements RealFieldElement<Dfp> {
/* move the remainder into the dividend while left shifting */ /* move the remainder into the dividend while left shifting */
dividend[0] = 0; dividend[0] = 0;
for (int i = 0; i < mant.length; i++) { System.arraycopy(remainder, 0, dividend, 1, mant.length);
dividend[i + 1] = remainder[i];
}
} }
/* Find the most sig digit */ /* Find the most sig digit */

View File

@ -273,10 +273,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
throw new NoDataException(LocalizedFormats.POLYNOMIAL); throw new NoDataException(LocalizedFormats.POLYNOMIAL);
} }
// Coefficients for deflated polynomial. // Coefficients for deflated polynomial.
final Complex[] c = new Complex[n + 1]; final Complex[] c = coefficients.clone();
for (int i = 0; i <= n; i++) {
c[i] = coefficients[i];
}
// Solve individual roots successively. // Solve individual roots successively.
final Complex[] root = new Complex[n]; final Complex[] root = new Complex[n];

View File

@ -349,9 +349,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
//residuals already have weights applied //residuals already have weights applied
double[] weightedResidual = currentResiduals; double[] weightedResidual = currentResiduals;
for (int i = 0; i < nR; i++) { System.arraycopy(weightedResidual, 0, qtf, 0, nR);
qtf[i] = weightedResidual[i];
}
// compute Qt.res // compute Qt.res
qTy(qtf, internalData); qTy(qtf, internalData);

View File

@ -150,9 +150,7 @@ class HessenbergTransformer {
} }
// copy upper triangular part of the matrix // copy upper triangular part of the matrix
for (int j = i; j < m; ++j) { System.arraycopy(householderVectors[i], i, h[i], i, m - i);
h[i][j] = householderVectors[i][j];
}
} }
cachedH = MatrixUtils.createRealMatrix(h); cachedH = MatrixUtils.createRealMatrix(h);
} }

View File

@ -170,9 +170,9 @@ public final class AdamsNordsieckFieldTransformer<T extends RealFieldElement<T>>
// Nordsieck to multistep, then shifting rows to represent step advance // Nordsieck to multistep, then shifting rows to represent step advance
// then applying inverse transform // then applying inverse transform
T[][] shiftedP = bigP.getData(); T[][] shiftedP = bigP.getData();
for (int i = shiftedP.length - 1; i > 0; --i) { // shift rows
// shift rows if (shiftedP.length - 1 > 0){
shiftedP[i] = shiftedP[i - 1]; System.arraycopy(shiftedP, 0, shiftedP, 1, shiftedP.length - 1);
} }
shiftedP[0] = MathArrays.buildArray(field, rows); shiftedP[0] = MathArrays.buildArray(field, rows);
Arrays.fill(shiftedP[0], field.getZero()); Arrays.fill(shiftedP[0], field.getZero());

View File

@ -752,8 +752,8 @@ public class CMAESOptimizer
* @param val Current best fitness value. * @param val Current best fitness value.
*/ */
private static void push(double[] vals, double val) { private static void push(double[] vals, double val) {
for (int i = vals.length-1; i > 0; i--) { if (vals.length - 1 > 0) {
vals[i] = vals[i-1]; System.arraycopy(vals, 0, vals, 1, vals.length - 1);
} }
vals[0] = val; vals[0] = val;
} }

View File

@ -235,9 +235,7 @@ public class NeuronSquareMesh2D
public synchronized NeuronSquareMesh2D copy() { public synchronized NeuronSquareMesh2D copy() {
final long[][] idGrid = new long[numberOfRows][numberOfColumns]; final long[][] idGrid = new long[numberOfRows][numberOfColumns];
for (int r = 0; r < numberOfRows; r++) { for (int r = 0; r < numberOfRows; r++) {
for (int c = 0; c < numberOfColumns; c++) { System.arraycopy(identifiers[r], 0, idGrid[r], 0, numberOfColumns);
idGrid[r][c] = identifiers[r][c];
}
} }
return new NeuronSquareMesh2D(wrapRows, return new NeuronSquareMesh2D(wrapRows,

View File

@ -44,7 +44,7 @@
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SparseGradient\.java$" lines="385,396" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]SparseGradient\.java$" lines="385,396" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]DerivativeStructure\.java$" lines="468,481" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]DerivativeStructure\.java$" lines="468,481" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleCurveFitter\.java$" lines="321-322" /> <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=".*[/\\]EnumeratedDistribution\.java$" lines="128-129" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleRegression\.java$" lines="823" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleRegression\.java$" lines="823" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]MillerUpdatingRegression\.java$" lines="172-173" /> <suppress checks="UnnecessaryParentheses" files=".*[/\\]MillerUpdatingRegression\.java$" lines="172-173" />