mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-13 20:26:03 +08:00
further cleaning/ goto removing
This commit is contained in:
parent
92a5bb4539
commit
312ab1abb3
@ -39,13 +39,11 @@ void ei_dogleg(
|
|||||||
/* Computing MAX */
|
/* Computing MAX */
|
||||||
temp = std::max(temp,ei_abs(r[l]));
|
temp = std::max(temp,ei_abs(r[l]));
|
||||||
l = l + n - i;
|
l = l + n - i;
|
||||||
/* L30: */
|
|
||||||
}
|
}
|
||||||
temp = epsmch * temp;
|
temp = epsmch * temp;
|
||||||
if (temp == 0.) {
|
if (temp == 0.)
|
||||||
temp = epsmch;
|
temp = epsmch;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
x[j] = (qtb[j] - sum) / temp;
|
x[j] = (qtb[j] - sum) / temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ void ei_dogleg(
|
|||||||
sgnorm = 0.;
|
sgnorm = 0.;
|
||||||
alpha = delta / qnorm;
|
alpha = delta / qnorm;
|
||||||
if (gnorm == 0.)
|
if (gnorm == 0.)
|
||||||
goto L120;
|
goto algo_end;
|
||||||
|
|
||||||
/* calculate the point along the scaled gradient */
|
/* calculate the point along the scaled gradient */
|
||||||
/* at which the quadratic is minimized. */
|
/* at which the quadratic is minimized. */
|
||||||
@ -100,9 +98,8 @@ void ei_dogleg(
|
|||||||
/* test whether the scaled gradient direction is acceptable. */
|
/* test whether the scaled gradient direction is acceptable. */
|
||||||
|
|
||||||
alpha = 0.;
|
alpha = 0.;
|
||||||
if (sgnorm >= delta) {
|
if (sgnorm >= delta)
|
||||||
goto L120;
|
goto algo_end;
|
||||||
}
|
|
||||||
|
|
||||||
/* the scaled gradient direction is not acceptable. */
|
/* the scaled gradient direction is not acceptable. */
|
||||||
/* finally, calculate the point along the dogleg */
|
/* finally, calculate the point along the dogleg */
|
||||||
@ -114,7 +111,7 @@ void ei_dogleg(
|
|||||||
temp = temp - delta / qnorm * ei_abs2(sgnorm / delta) + ei_sqrt(ei_abs2(temp - delta / qnorm) + (1.-ei_abs2(delta / qnorm)) * (1.-ei_abs2(sgnorm / delta)));
|
temp = temp - delta / qnorm * ei_abs2(sgnorm / delta) + ei_sqrt(ei_abs2(temp - delta / qnorm) + (1.-ei_abs2(delta / qnorm)) * (1.-ei_abs2(sgnorm / delta)));
|
||||||
/* Computing 2nd power */
|
/* Computing 2nd power */
|
||||||
alpha = delta / qnorm * (1. - ei_abs2(sgnorm / delta)) / temp;
|
alpha = delta / qnorm * (1. - ei_abs2(sgnorm / delta)) / temp;
|
||||||
L120:
|
algo_end:
|
||||||
|
|
||||||
/* form appropriate convex combination of the gauss-newton */
|
/* form appropriate convex combination of the gauss-newton */
|
||||||
/* direction and the scaled gradient direction. */
|
/* direction and the scaled gradient direction. */
|
||||||
|
@ -62,16 +62,17 @@ void ei_lmpar(
|
|||||||
wa2 = diag.cwise() * x;
|
wa2 = diag.cwise() * x;
|
||||||
dxnorm = wa2.blueNorm();
|
dxnorm = wa2.blueNorm();
|
||||||
fp = dxnorm - delta;
|
fp = dxnorm - delta;
|
||||||
if (fp <= Scalar(0.1) * delta)
|
if (fp <= Scalar(0.1) * delta) {
|
||||||
goto L220;
|
par = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* if the jacobian is not rank deficient, the newton */
|
/* if the jacobian is not rank deficient, the newton */
|
||||||
/* step provides a lower bound, parl, for the zero of */
|
/* step provides a lower bound, parl, for the zero of */
|
||||||
/* the function. otherwise set this bound to zero. */
|
/* the function. otherwise set this bound to zero. */
|
||||||
|
|
||||||
parl = 0.;
|
parl = 0.;
|
||||||
if (nsing < n-1)
|
if (nsing >= n-1) {
|
||||||
goto L120;
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
l = ipvt[j];
|
l = ipvt[j];
|
||||||
wa1[j] = diag[l] * (wa2[l] / dxnorm);
|
wa1[j] = diag[l] * (wa2[l] / dxnorm);
|
||||||
@ -84,7 +85,7 @@ void ei_lmpar(
|
|||||||
}
|
}
|
||||||
temp = wa1.blueNorm();
|
temp = wa1.blueNorm();
|
||||||
parl = fp / delta / temp / temp;
|
parl = fp / delta / temp / temp;
|
||||||
L120:
|
}
|
||||||
|
|
||||||
/* calculate an upper bound, paru, for the zero of the function. */
|
/* calculate an upper bound, paru, for the zero of the function. */
|
||||||
|
|
||||||
@ -97,9 +98,8 @@ L120:
|
|||||||
}
|
}
|
||||||
gnorm = wa1.stableNorm();
|
gnorm = wa1.stableNorm();
|
||||||
paru = gnorm / delta;
|
paru = gnorm / delta;
|
||||||
if (paru == 0.) {
|
if (paru == 0.)
|
||||||
paru = dwarf / std::min(delta,Scalar(0.1));
|
paru = dwarf / std::min(delta,Scalar(0.1));
|
||||||
}
|
|
||||||
|
|
||||||
/* if the input par lies outside of the interval (parl,paru), */
|
/* if the input par lies outside of the interval (parl,paru), */
|
||||||
/* set par to the closer endpoint. */
|
/* set par to the closer endpoint. */
|
||||||
@ -111,7 +111,7 @@ L120:
|
|||||||
|
|
||||||
/* beginning of an iteration. */
|
/* beginning of an iteration. */
|
||||||
|
|
||||||
L150:
|
while (true) {
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
/* evaluate the function at the current value of par. */
|
/* evaluate the function at the current value of par. */
|
||||||
@ -135,10 +135,8 @@ L150:
|
|||||||
/* of par. also test for the exceptional cases where parl */
|
/* of par. also test for the exceptional cases where parl */
|
||||||
/* is zero or the number of iterations has reached 10. */
|
/* is zero or the number of iterations has reached 10. */
|
||||||
|
|
||||||
if (ei_abs(fp) <= Scalar(0.1) * delta || (parl == 0. && fp <= temp && temp < 0.) ||
|
if (ei_abs(fp) <= Scalar(0.1) * delta || (parl == 0. && fp <= temp && temp < 0.) || iter == 10)
|
||||||
iter == 10) {
|
break;
|
||||||
goto L220;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* compute the newton correction. */
|
/* compute the newton correction. */
|
||||||
|
|
||||||
@ -158,12 +156,10 @@ L150:
|
|||||||
|
|
||||||
/* depending on the sign of the function, update parl or paru. */
|
/* depending on the sign of the function, update parl or paru. */
|
||||||
|
|
||||||
if (fp > 0.) {
|
if (fp > 0.)
|
||||||
parl = std::max(parl,par);
|
parl = std::max(parl,par);
|
||||||
}
|
if (fp < 0.)
|
||||||
if (fp < 0.) {
|
|
||||||
paru = std::min(paru,par);
|
paru = std::min(paru,par);
|
||||||
}
|
|
||||||
|
|
||||||
/* compute an improved estimate for par. */
|
/* compute an improved estimate for par. */
|
||||||
|
|
||||||
@ -172,14 +168,12 @@ L150:
|
|||||||
|
|
||||||
/* end of an iteration. */
|
/* end of an iteration. */
|
||||||
|
|
||||||
goto L150;
|
}
|
||||||
L220:
|
|
||||||
|
|
||||||
/* termination. */
|
/* termination. */
|
||||||
|
|
||||||
if (iter == 0) {
|
if (iter == 0)
|
||||||
par = 0.;
|
par = 0.;
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user