mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-29 23:34:12 +08:00
some eigenization in main algorithms
This commit is contained in:
parent
134dea76d3
commit
8b9b671e83
@ -61,16 +61,9 @@ int ei_hybrd(
|
|||||||
factor <= 0. || ldfjac < n || lr < n * (n + 1) / 2) {
|
factor <= 0. || ldfjac < n || lr < n * (n + 1) / 2) {
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
}
|
||||||
if (mode != 2) {
|
if (mode == 2)
|
||||||
goto L20;
|
for (j = 0; j < n; ++j)
|
||||||
}
|
if (diag[j] <= 0.) goto L300;
|
||||||
for (j = 0; j < n; ++j) {
|
|
||||||
if (diag[j] <= 0.) {
|
|
||||||
goto L300;
|
|
||||||
}
|
|
||||||
/* L10: */
|
|
||||||
}
|
|
||||||
L20:
|
|
||||||
|
|
||||||
/* evaluate the function at the starting point */
|
/* evaluate the function at the starting point */
|
||||||
/* and calculate its norm. */
|
/* and calculate its norm. */
|
||||||
@ -135,10 +128,7 @@ L50:
|
|||||||
/* on the first iteration, calculate the norm of the scaled x */
|
/* on the first iteration, calculate the norm of the scaled x */
|
||||||
/* and initialize the step bound delta. */
|
/* and initialize the step bound delta. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa3 = diag.cwise() * x;
|
||||||
wa3[j] = diag[j] * x[j];
|
|
||||||
/* L60: */
|
|
||||||
}
|
|
||||||
xnorm = wa3.stableNorm();
|
xnorm = wa3.stableNorm();
|
||||||
delta = factor * xnorm;
|
delta = factor * xnorm;
|
||||||
if (delta == 0.) {
|
if (delta == 0.) {
|
||||||
@ -148,10 +138,7 @@ L70:
|
|||||||
|
|
||||||
/* form (q transpose)*fvec and store in qtf. */
|
/* form (q transpose)*fvec and store in qtf. */
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
qtf = fvec;
|
||||||
qtf[i] = fvec[i];
|
|
||||||
/* L80: */
|
|
||||||
}
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
if (fjac(j,j) == 0.) {
|
if (fjac(j,j) == 0.) {
|
||||||
goto L110;
|
goto L110;
|
||||||
@ -200,8 +187,7 @@ L110:
|
|||||||
goto L170;
|
goto L170;
|
||||||
}
|
}
|
||||||
/* Computing MAX */
|
/* Computing MAX */
|
||||||
for (j = 0; j < n; ++j)
|
diag = diag.cwise().max(wa2);
|
||||||
diag[j] = std::max(diag[j], wa2[j]);
|
|
||||||
L170:
|
L170:
|
||||||
|
|
||||||
/* beginning of the inner loop. */
|
/* beginning of the inner loop. */
|
||||||
@ -228,12 +214,9 @@ L190:
|
|||||||
|
|
||||||
/* store the direction p and x + p. calculate the norm of p. */
|
/* store the direction p and x + p. calculate the norm of p. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa1 = -wa1;
|
||||||
wa1[j] = -wa1[j];
|
wa2 = x + wa1;
|
||||||
wa2[j] = x[j] + wa1[j];
|
wa3 = diag.cwise() * wa1;
|
||||||
wa3[j] = diag[j] * wa1[j];
|
|
||||||
/* L200: */
|
|
||||||
}
|
|
||||||
pnorm = wa3.stableNorm();
|
pnorm = wa3.stableNorm();
|
||||||
|
|
||||||
/* on the first iteration, adjust the initial step bound. */
|
/* on the first iteration, adjust the initial step bound. */
|
||||||
@ -310,12 +293,9 @@ L240:
|
|||||||
|
|
||||||
/* successful iteration. update x, fvec, and their norms. */
|
/* successful iteration. update x, fvec, and their norms. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
x = wa2;
|
||||||
x[j] = wa2[j];
|
wa2 = diag.cwise() * x;
|
||||||
wa2[j] = diag[j] * x[j];
|
fvec = wa4;
|
||||||
fvec[j] = wa4[j];
|
|
||||||
/* L250: */
|
|
||||||
}
|
|
||||||
temp = wa2.stableNorm();
|
temp = wa2.stableNorm();
|
||||||
fnorm = fnorm1;
|
fnorm = fnorm1;
|
||||||
++iter;
|
++iter;
|
||||||
@ -368,18 +348,12 @@ L260:
|
|||||||
/* and update qtf if necessary. */
|
/* and update qtf if necessary. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
sum = 0.;
|
sum = wa4.dot(fjac.col(j));
|
||||||
for (i = 0; i < n; ++i) {
|
|
||||||
sum += fjac(i,j) * wa4[i];
|
|
||||||
/* L270: */
|
|
||||||
}
|
|
||||||
wa2[j] = (sum - wa3[j]) / pnorm;
|
wa2[j] = (sum - wa3[j]) / pnorm;
|
||||||
wa1[j] = diag[j] * (diag[j] * wa1[j] / pnorm);
|
wa1[j] = diag[j] * (diag[j] * wa1[j] / pnorm);
|
||||||
if (ratio >= Scalar(1e-4)) {
|
if (ratio >= Scalar(1e-4))
|
||||||
qtf[j] = sum;
|
qtf[j] = sum;
|
||||||
}
|
}
|
||||||
/* L280: */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* compute the qr factorization of the updated jacobian. */
|
/* compute the qr factorization of the updated jacobian. */
|
||||||
|
|
||||||
|
@ -56,16 +56,10 @@ int ei_hybrj(
|
|||||||
0. || lr < n * (n + 1) / 2) {
|
0. || lr < n * (n + 1) / 2) {
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
}
|
||||||
if (mode != 2) {
|
if (mode == 2)
|
||||||
goto L20;
|
for (j = 0; j < n; ++j)
|
||||||
}
|
if (diag[j] <= 0.)
|
||||||
for (j = 0; j < n; ++j) {
|
|
||||||
if (diag[j] <= 0.) {
|
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
|
||||||
/* L10: */
|
|
||||||
}
|
|
||||||
L20:
|
|
||||||
|
|
||||||
/* evaluate the function at the starting point */
|
/* evaluate the function at the starting point */
|
||||||
/* and calculate its norm. */
|
/* and calculate its norm. */
|
||||||
@ -123,10 +117,7 @@ L50:
|
|||||||
/* on the first iteration, calculate the norm of the scaled x */
|
/* on the first iteration, calculate the norm of the scaled x */
|
||||||
/* and initialize the step bound delta. */
|
/* and initialize the step bound delta. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa3 = diag.cwise() * x;
|
||||||
wa3[j] = diag[j] * x[j];
|
|
||||||
/* L60: */
|
|
||||||
}
|
|
||||||
xnorm = wa3.stableNorm();;
|
xnorm = wa3.stableNorm();;
|
||||||
delta = factor * xnorm;
|
delta = factor * xnorm;
|
||||||
if (delta == 0.) {
|
if (delta == 0.) {
|
||||||
@ -136,10 +127,7 @@ L70:
|
|||||||
|
|
||||||
/* form (q transpose)*fvec and store in qtf. */
|
/* form (q transpose)*fvec and store in qtf. */
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
qtf = fvec;
|
||||||
qtf[i] = fvec[i];
|
|
||||||
/* L80: */
|
|
||||||
}
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
if (fjac(j,j) == 0.) {
|
if (fjac(j,j) == 0.) {
|
||||||
goto L110;
|
goto L110;
|
||||||
@ -219,7 +207,6 @@ L190:
|
|||||||
wa1[j] = -wa1[j];
|
wa1[j] = -wa1[j];
|
||||||
wa2[j] = x[j] + wa1[j];
|
wa2[j] = x[j] + wa1[j];
|
||||||
wa3[j] = diag[j] * wa1[j];
|
wa3[j] = diag[j] * wa1[j];
|
||||||
/* L200: */
|
|
||||||
}
|
}
|
||||||
pnorm = wa3.stableNorm();
|
pnorm = wa3.stableNorm();
|
||||||
|
|
||||||
@ -297,12 +284,9 @@ L240:
|
|||||||
|
|
||||||
/* successful iteration. update x, fvec, and their norms. */
|
/* successful iteration. update x, fvec, and their norms. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
x =wa2;
|
||||||
x[j] = wa2[j];
|
wa2 = diag.cwise() * x;
|
||||||
wa2[j] = diag[j] * x[j];
|
fvec = wa4;
|
||||||
fvec[j] = wa4[j];
|
|
||||||
/* L250: */
|
|
||||||
}
|
|
||||||
xnorm = wa2.stableNorm();
|
xnorm = wa2.stableNorm();
|
||||||
fnorm = fnorm1;
|
fnorm = fnorm1;
|
||||||
++iter;
|
++iter;
|
||||||
@ -359,11 +343,7 @@ L260:
|
|||||||
/* and update qtf if necessary. */
|
/* and update qtf if necessary. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
sum = 0.;
|
sum = wa4.dot(fjac.col(j));
|
||||||
for (i = 0; i < n; ++i) {
|
|
||||||
sum += fjac(i,j) * wa4[i];
|
|
||||||
/* L270: */
|
|
||||||
}
|
|
||||||
wa2[j] = (sum - wa3[j]) / pnorm;
|
wa2[j] = (sum - wa3[j]) / pnorm;
|
||||||
wa1[j] = diag[j] * (diag[j] * wa1[j] / pnorm);
|
wa1[j] = diag[j] * (diag[j] * wa1[j] / pnorm);
|
||||||
if (ratio >= Scalar(1e-4)) {
|
if (ratio >= Scalar(1e-4)) {
|
||||||
|
@ -50,16 +50,10 @@ int ei_lmder(
|
|||||||
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
}
|
||||||
if (mode != 2) {
|
if (mode == 2)
|
||||||
goto L20;
|
for (j = 0; j < n; ++j)
|
||||||
}
|
if (diag[j] <= 0.)
|
||||||
for (j = 0; j < n; ++j) {
|
|
||||||
if (diag[j] <= 0.) {
|
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
|
||||||
/* L10: */
|
|
||||||
}
|
|
||||||
L20:
|
|
||||||
|
|
||||||
/* evaluate the function at the starting point */
|
/* evaluate the function at the starting point */
|
||||||
/* and calculate its norm. */
|
/* and calculate its norm. */
|
||||||
@ -128,10 +122,7 @@ L60:
|
|||||||
/* on the first iteration, calculate the norm of the scaled x */
|
/* on the first iteration, calculate the norm of the scaled x */
|
||||||
/* and initialize the step bound delta. */
|
/* and initialize the step bound delta. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa3 = diag.cwise() * x ;
|
||||||
wa3[j] = diag[j] * x[j];
|
|
||||||
/* L70: */
|
|
||||||
}
|
|
||||||
xnorm = wa3.stableNorm();
|
xnorm = wa3.stableNorm();
|
||||||
delta = factor * xnorm;
|
delta = factor * xnorm;
|
||||||
if (delta == 0.) {
|
if (delta == 0.) {
|
||||||
@ -142,10 +133,7 @@ L80:
|
|||||||
/* form (q transpose)*fvec and store the first n components in */
|
/* form (q transpose)*fvec and store the first n components in */
|
||||||
/* qtf. */
|
/* qtf. */
|
||||||
|
|
||||||
for (i = 0; i < m; ++i) {
|
wa4 = fvec;
|
||||||
wa4[i] = fvec[i];
|
|
||||||
/* L90: */
|
|
||||||
}
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
if (fjac(j,j) == 0.) {
|
if (fjac(j,j) == 0.) {
|
||||||
goto L120;
|
goto L120;
|
||||||
@ -178,14 +166,11 @@ L120:
|
|||||||
goto L150;
|
goto L150;
|
||||||
}
|
}
|
||||||
sum = 0.;
|
sum = 0.;
|
||||||
for (i = 0; i <= j; ++i) {
|
for (i = 0; i <= j; ++i)
|
||||||
sum += fjac(i,j) * (qtf[i] / fnorm);
|
sum += fjac(i,j) * (qtf[i] / fnorm);
|
||||||
/* L140: */
|
|
||||||
}
|
|
||||||
/* Computing MAX */
|
/* Computing MAX */
|
||||||
gnorm = std::max(gnorm, ei_abs(sum / wa2[l]));
|
gnorm = std::max(gnorm, ei_abs(sum / wa2[l]));
|
||||||
L150:
|
L150:
|
||||||
/* L160: */
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
L170:
|
L170:
|
||||||
@ -221,12 +206,9 @@ L200:
|
|||||||
|
|
||||||
/* store the direction p and x + p. calculate the norm of p. */
|
/* store the direction p and x + p. calculate the norm of p. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa1 = -wa1;
|
||||||
wa1[j] = -wa1[j];
|
wa2 = x + wa1;
|
||||||
wa2[j] = x[j] + wa1[j];
|
wa3 = diag.cwise() * wa1;
|
||||||
wa3[j] = diag[j] * wa1[j];
|
|
||||||
/* L210: */
|
|
||||||
}
|
|
||||||
pnorm = wa3.stableNorm();
|
pnorm = wa3.stableNorm();
|
||||||
|
|
||||||
/* on the first iteration, adjust the initial step bound. */
|
/* on the first iteration, adjust the initial step bound. */
|
||||||
@ -253,6 +235,7 @@ L200:
|
|||||||
/* compute the scaled predicted reduction and */
|
/* compute the scaled predicted reduction and */
|
||||||
/* the scaled directional derivative. */
|
/* the scaled directional derivative. */
|
||||||
|
|
||||||
|
wa3.fill(0.);
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
wa3[j] = 0.;
|
wa3[j] = 0.;
|
||||||
l = ipvt[j];
|
l = ipvt[j];
|
||||||
@ -312,15 +295,9 @@ L260:
|
|||||||
|
|
||||||
/* successful iteration. update x, fvec, and their norms. */
|
/* successful iteration. update x, fvec, and their norms. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
x = wa2;
|
||||||
x[j] = wa2[j];
|
wa2 = diag.cwise() * x;
|
||||||
wa2[j] = diag[j] * x[j];
|
fvec = wa4;
|
||||||
/* L270: */
|
|
||||||
}
|
|
||||||
for (i = 0; i < m; ++i) {
|
|
||||||
fvec[i] = wa4[i];
|
|
||||||
/* L280: */
|
|
||||||
}
|
|
||||||
xnorm = wa2.stableNorm();
|
xnorm = wa2.stableNorm();
|
||||||
fnorm = fnorm1;
|
fnorm = fnorm1;
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -52,16 +52,10 @@ int ei_lmdif(
|
|||||||
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
}
|
||||||
if (mode != 2) {
|
if (mode == 2)
|
||||||
goto L20;
|
for (j = 0; j < n; ++j)
|
||||||
}
|
if (diag[j] <= 0.)
|
||||||
for (j = 0; j < n; ++j) {
|
|
||||||
if (diag[j] <= 0.) {
|
|
||||||
goto L300;
|
goto L300;
|
||||||
}
|
|
||||||
/* L10: */
|
|
||||||
}
|
|
||||||
L20:
|
|
||||||
|
|
||||||
/* evaluate the function at the starting point */
|
/* evaluate the function at the starting point */
|
||||||
/* and calculate its norm. */
|
/* and calculate its norm. */
|
||||||
@ -130,10 +124,7 @@ L60:
|
|||||||
/* on the first iteration, calculate the norm of the scaled x */
|
/* on the first iteration, calculate the norm of the scaled x */
|
||||||
/* and initialize the step bound delta. */
|
/* and initialize the step bound delta. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa3 = diag.cwise() * x;
|
||||||
wa3[j] = diag[j] * x[j];
|
|
||||||
/* L70: */
|
|
||||||
}
|
|
||||||
xnorm = wa3.stableNorm();;
|
xnorm = wa3.stableNorm();;
|
||||||
delta = factor * xnorm;
|
delta = factor * xnorm;
|
||||||
if (delta == 0.) {
|
if (delta == 0.) {
|
||||||
@ -144,10 +135,7 @@ L80:
|
|||||||
/* form (q transpose)*fvec and store the first n components in */
|
/* form (q transpose)*fvec and store the first n components in */
|
||||||
/* qtf. */
|
/* qtf. */
|
||||||
|
|
||||||
for (i = 0; i < m; ++i) {
|
wa4 = fvec;
|
||||||
wa4[i] = fvec[i];
|
|
||||||
/* L90: */
|
|
||||||
}
|
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
if (fjac[j + j * ldfjac] == 0.) {
|
if (fjac[j + j * ldfjac] == 0.) {
|
||||||
goto L120;
|
goto L120;
|
||||||
@ -223,12 +211,9 @@ L200:
|
|||||||
|
|
||||||
/* store the direction p and x + p. calculate the norm of p. */
|
/* store the direction p and x + p. calculate the norm of p. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa1 = -wa1;
|
||||||
wa1[j] = -wa1[j];
|
wa2 = x + wa1;
|
||||||
wa2[j] = x[j] + wa1[j];
|
wa3 = diag.cwise() * wa1;
|
||||||
wa3[j] = diag[j] * wa1[j];
|
|
||||||
/* L210: */
|
|
||||||
}
|
|
||||||
pnorm = wa3.stableNorm();
|
pnorm = wa3.stableNorm();
|
||||||
|
|
||||||
/* on the first iteration, adjust the initial step bound. */
|
/* on the first iteration, adjust the initial step bound. */
|
||||||
@ -314,15 +299,9 @@ L260:
|
|||||||
|
|
||||||
/* successful iteration. update x, fvec, and their norms. */
|
/* successful iteration. update x, fvec, and their norms. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
x = wa2;
|
||||||
x[j] = wa2[j];
|
wa2 = diag.cwise() * x;
|
||||||
wa2[j] = diag[j] * x[j];
|
fvec = wa4;
|
||||||
/* L270: */
|
|
||||||
}
|
|
||||||
for (i = 0; i < m; ++i) {
|
|
||||||
fvec[i] = wa4[i];
|
|
||||||
/* L280: */
|
|
||||||
}
|
|
||||||
xnorm = wa2.stableNorm();
|
xnorm = wa2.stableNorm();
|
||||||
fnorm = fnorm1;
|
fnorm = fnorm1;
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -52,16 +52,11 @@ int ei_lmstr(
|
|||||||
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
||||||
goto L340;
|
goto L340;
|
||||||
}
|
}
|
||||||
if (mode != 2) {
|
|
||||||
goto L20;
|
if (mode == 2)
|
||||||
}
|
for (j = 0; j < n; ++j)
|
||||||
for (j = 0; j < n; ++j) {
|
if (diag[j] <= 0.)
|
||||||
if (diag[j] <= 0.) {
|
goto L300;
|
||||||
goto L340;
|
|
||||||
}
|
|
||||||
/* L10: */
|
|
||||||
}
|
|
||||||
L20:
|
|
||||||
|
|
||||||
/* evaluate the function at the starting point */
|
/* evaluate the function at the starting point */
|
||||||
/* and calculate its norm. */
|
/* and calculate its norm. */
|
||||||
@ -248,12 +243,9 @@ L240:
|
|||||||
|
|
||||||
/* store the direction p and x + p. calculate the norm of p. */
|
/* store the direction p and x + p. calculate the norm of p. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
wa1 = -wa1;
|
||||||
wa1[j] = -wa1[j];
|
wa2 = x + wa1;
|
||||||
wa2[j] = x[j] + wa1[j];
|
wa3 = diag.cwise() * wa1;
|
||||||
wa3[j] = diag[j] * wa1[j];
|
|
||||||
/* L250: */
|
|
||||||
}
|
|
||||||
pnorm = wa3.stableNorm();
|
pnorm = wa3.stableNorm();
|
||||||
|
|
||||||
/* on the first iteration, adjust the initial step bound. */
|
/* on the first iteration, adjust the initial step bound. */
|
||||||
@ -340,15 +332,9 @@ L300:
|
|||||||
|
|
||||||
/* successful iteration. update x, fvec, and their norms. */
|
/* successful iteration. update x, fvec, and their norms. */
|
||||||
|
|
||||||
for (j = 0; j < n; ++j) {
|
x = wa2;
|
||||||
x[j] = wa2[j];
|
wa2 = diag.cwise() * x;
|
||||||
wa2[j] = diag[j] * x[j];
|
fvec = wa4;
|
||||||
/* L310: */
|
|
||||||
}
|
|
||||||
for (i = 0; i < m; ++i) {
|
|
||||||
fvec[i] = wa4[i];
|
|
||||||
/* L320: */
|
|
||||||
}
|
|
||||||
xnorm = wa2.stableNorm();
|
xnorm = wa2.stableNorm();
|
||||||
fnorm = fnorm1;
|
fnorm = fnorm1;
|
||||||
++iter;
|
++iter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user