<commit_before>diff --git a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
index b41456e..e25d34c 100644
--- a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
+++ b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
@@ -255,8 +255,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
         double[] diag    = new double[cols];
         double[] oldX    = new double[cols];
         double[] oldRes  = new double[rows];
-        double[] oldObj  = new double[rows];
-        double[] qtf     = new double[rows];
         double[] work1   = new double[cols];
         double[] work2   = new double[cols];
         double[] work3   = new double[cols];
@@ -269,9 +267,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
         boolean firstIteration = true;
         VectorialPointValuePair current = new VectorialPointValuePair(point, objective);
         while (true) {
-            for (int i=0;i<rows;i++) {
-                qtf[i]=residuals[i];
-            }
             incrementIterationsCounter();
 
             // compute the Q.R. decomposition of the jacobian matrix
@@ -280,7 +275,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
             qrDecomposition();
 
             // compute Qt.res
-            qTy(qtf);
+            qTy(residuals);
             // now we don't need Q anymore,
             // so let jacobian contain the R matrix with its diagonal elements
             for (int k = 0; k < solvedCols; ++k) {
@@ -318,7 +313,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                     if (s != 0) {
                         double sum = 0;
                         for (int i = 0; i <= j; ++i) {
-                            sum += jacobian[i][pj] * qtf[i];
+                            sum += jacobian[i][pj] * residuals[i];
                         }
                         maxCosine = Math.max(maxCosine, Math.abs(sum) / (s * cost));
                     }
@@ -326,8 +321,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
             }
             if (maxCosine <= orthoTolerance) {
                 // convergence has been reached
-            	updateResidualsAndCost();
-            	current = new VectorialPointValuePair(point, objective);
                 return current;
             }
 
@@ -348,12 +341,9 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                 double[] tmpVec = residuals;
                 residuals = oldRes;
                 oldRes    = tmpVec;
-                tmpVec    = objective;
-                objective = oldObj;
-                oldObj    = tmpVec;
 
                 // determine the Levenberg-Marquardt parameter
-                determineLMParameter(qtf, delta, diag, work1, work2, work3);
+                determineLMParameter(oldRes, delta, diag, work1, work2, work3);
 
                 // compute the new point and the norm of the evolution direction
                 double lmNorm = 0;
@@ -372,6 +362,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
 
                 // evaluate the function at x + p and calculate its norm
                 updateResidualsAndCost();
+                current = new VectorialPointValuePair(point, objective);
 
                 // compute the scaled actual reduction
                 double actRed = -1.0;
@@ -426,16 +417,10 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                         double xK = diag[k] * point[k];
                         xNorm    += xK * xK;
                     }
-                    xNorm = Math.sqrt(xNorm);
-                    current = new VectorialPointValuePair(point, objective);
 
+                    xNorm = Math.sqrt(xNorm);
                     // tests for convergence.
-                    if (checker != null) {
                     // we use the vectorial convergence checker
-                    	if (checker.converged(getIterations(), previous, current)) {
-                    		return current;
-                    	}<commit_msg>Minor change to a Math patch: eliminate one common line.<commit_after>diff --git a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
index b41456e..5091493 100644
--- a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
+++ b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
@@ -255,8 +255,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
         double[] diag    = new double[cols];
         double[] oldX    = new double[cols];
         double[] oldRes  = new double[rows];
-        double[] oldObj  = new double[rows];
-        double[] qtf     = new double[rows];
         double[] work1   = new double[cols];
         double[] work2   = new double[cols];
         double[] work3   = new double[cols];
@@ -269,9 +267,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
         boolean firstIteration = true;
         VectorialPointValuePair current = new VectorialPointValuePair(point, objective);
         while (true) {
-            for (int i=0;i<rows;i++) {
-                qtf[i]=residuals[i];
-            }
             incrementIterationsCounter();
 
             // compute the Q.R. decomposition of the jacobian matrix
@@ -280,7 +275,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
             qrDecomposition();
 
             // compute Qt.res
-            qTy(qtf);
+            qTy(residuals);
             // now we don't need Q anymore,
             // so let jacobian contain the R matrix with its diagonal elements
             for (int k = 0; k < solvedCols; ++k) {
@@ -318,7 +313,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                     if (s != 0) {
                         double sum = 0;
                         for (int i = 0; i <= j; ++i) {
-                            sum += jacobian[i][pj] * qtf[i];
+                            sum += jacobian[i][pj] * residuals[i];
                         }
                         maxCosine = Math.max(maxCosine, Math.abs(sum) / (s * cost));
                     }
@@ -326,8 +321,6 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
             }
             if (maxCosine <= orthoTolerance) {
                 // convergence has been reached
-            	updateResidualsAndCost();
-            	current = new VectorialPointValuePair(point, objective);
                 return current;
             }
 
@@ -348,12 +341,9 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                 double[] tmpVec = residuals;
                 residuals = oldRes;
                 oldRes    = tmpVec;
-                tmpVec    = objective;
-                objective = oldObj;
-                oldObj    = tmpVec;
 
                 // determine the Levenberg-Marquardt parameter
-                determineLMParameter(qtf, delta, diag, work1, work2, work3);
+                determineLMParameter(oldRes, delta, diag, work1, work2, work3);
 
                 // compute the new point and the norm of the evolution direction
                 double lmNorm = 0;
@@ -372,6 +362,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
 
                 // evaluate the function at x + p and calculate its norm
                 updateResidualsAndCost();
+                current = new VectorialPointValuePair(point, objective);
 
                 // compute the scaled actual reduction
                 double actRed = -1.0;
@@ -427,15 +418,9 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
                         xNorm    += xK * xK;
                     }
                     xNorm = Math.sqrt(xNorm);
-                    current = new VectorialPointValuePair(point, objective);
 
                     // tests for convergence.
-                    if (checker != null) {
                     // we use the vectorial convergence checker
-                    	if (checker.converged(getIterations(), previous, current)) {
-                    		return current;
-                    	}
{'fraction_non_alphanumeric': 0.09733909483738913, 'fraction_numerical': 0.02274277916761428, 'mean_word_length': 1.7674638137193204, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3621252', 'n_tokens_mistral': 2635, 'n_tokens_neox': 2402, 'n_words': 575}