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

View File

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

View File

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

View File

@ -150,9 +150,7 @@ class HessenbergTransformer {
}
// copy upper triangular part of the matrix
for (int j = i; j < m; ++j) {
h[i][j] = householderVectors[i][j];
}
System.arraycopy(householderVectors[i], i, h[i], i, m - i);
}
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
// then applying inverse transform
T[][] shiftedP = bigP.getData();
for (int i = shiftedP.length - 1; i > 0; --i) {
// shift rows
shiftedP[i] = shiftedP[i - 1];
// shift rows
if (shiftedP.length - 1 > 0){
System.arraycopy(shiftedP, 0, shiftedP, 1, shiftedP.length - 1);
}
shiftedP[0] = MathArrays.buildArray(field, rows);
Arrays.fill(shiftedP[0], field.getZero());

View File

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

View File

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

View File

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