use eigen objects for hybrj and lmstr

This commit is contained in:
Thomas Capricelli 2009-08-23 03:14:42 +02:00
parent 3251e12258
commit 8a27e774f8
3 changed files with 27 additions and 23 deletions

View File

@ -70,7 +70,7 @@ L20:
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 1); iflag = Functor::f(x, fvec, fjac, 1);
nfev = 1; nfev = 1;
if (iflag < 0) { if (iflag < 0) {
goto L300; goto L300;
@ -92,7 +92,7 @@ L30:
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 2); iflag = Functor::f(x, fvec, fjac, 2);
++njev; ++njev;
if (iflag < 0) { if (iflag < 0) {
goto L300; goto L300;
@ -202,9 +202,8 @@ L180:
goto L190; goto L190;
} }
iflag = 0; iflag = 0;
if ((iter - 1) % nprint == 0) { if ((iter - 1) % nprint == 0)
iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 0); iflag = Functor::f(x, fvec, fjac, 0);
}
if (iflag < 0) { if (iflag < 0) {
goto L300; goto L300;
} }
@ -232,7 +231,7 @@ L190:
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(n, wa2.data(), wa4.data(), fjac.data(), ldfjac, 1); iflag = Functor::f(wa2, wa4, fjac, 1);
++nfev; ++nfev;
if (iflag < 0) { if (iflag < 0) {
goto L300; goto L300;
@ -395,9 +394,8 @@ L300:
if (iflag < 0) { if (iflag < 0) {
info = iflag; info = iflag;
} }
if (nprint > 0) { if (nprint > 0)
iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 0); iflag = Functor::f(x, fvec, fjac, 0);
}
return info; return info;
/* last card of subroutine hybrj. */ /* last card of subroutine hybrj. */

View File

@ -66,7 +66,7 @@ L20:
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = Functor::f(m, n, x.data(), fvec.data(), wa3.data(), 1); iflag = Functor::f(x, fvec, wa3, 1);
nfev = 1; nfev = 1;
if (iflag < 0) { if (iflag < 0) {
goto L340; goto L340;
@ -89,7 +89,7 @@ L30:
} }
iflag = 0; iflag = 0;
if ((iter - 1) % nprint == 0) { if ((iter - 1) % nprint == 0) {
iflag = Functor::f(m, n, x.data(), fvec.data(), wa3.data(), 0); iflag = Functor::f(x, fvec, wa3, 0);
} }
if (iflag < 0) { if (iflag < 0) {
goto L340; goto L340;
@ -111,7 +111,7 @@ L40:
} }
iflag = 2; iflag = 2;
for (i = 0; i < m; ++i) { for (i = 0; i < m; ++i) {
if (Functor::f(m, n, x.data(), fvec.data(), wa3.data(), iflag) < 0) { if (Functor::f(x, fvec, wa3, iflag) < 0) {
goto L340; goto L340;
} }
temp = fvec[i]; temp = fvec[i];
@ -264,7 +264,7 @@ L240:
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(m, n, wa2.data(), wa4.data(), wa3.data(), 1); iflag = Functor::f(wa2, wa4, wa3, 1);
++nfev; ++nfev;
if (iflag < 0) { if (iflag < 0) {
goto L340; goto L340;
@ -406,7 +406,7 @@ L340:
} }
iflag = 0; iflag = 0;
if (nprint > 0) { if (nprint > 0) {
iflag = Functor::f(m, n, x.data(), fvec.data(), wa3.data(), 0); iflag = Functor::f(x, fvec, wa3, 0);
} }
return info; return info;

View File

@ -217,13 +217,17 @@ void testLmder()
} }
struct hybrj_functor { struct hybrj_functor {
static int f(int n, const double *x, double *fvec, double *fjac, int ldfjac, static int f(const VectorXd &x, VectorXd &fvec, MatrixXd &fjac, int iflag)
int iflag)
{ {
/* subroutine fcn for hybrj1 example. */ /* subroutine fcn for hybrj1 example. */
int j, k; int j, k;
double one=1, temp, temp1, temp2, three=3, two=2, zero=0, four=4; double one=1, temp, temp1, temp2, three=3, two=2, zero=0, four=4;
const int n = x.size();
assert(fvec.size()==n);
assert(fjac.rows()==n);
assert(fjac.cols()==n);
if (iflag != 2) if (iflag != 2)
{ {
@ -242,12 +246,10 @@ struct hybrj_functor {
for (k = 0; k < n; k++) for (k = 0; k < n; k++)
{ {
for (j = 0; j < n; j++) for (j = 0; j < n; j++)
{ fjac(k,j) = zero;
fjac[k + ldfjac*(j)] = zero; fjac(k,k) = three - four*x[k];
} if (k) fjac(k,k-1) = -one;
fjac[k + ldfjac*(k)] = three - four*x[k]; if (k != n-1) fjac(k,k+1) = -two;
if (k) fjac[k + ldfjac*(k-1)] = -one;
if (k != n-1) fjac[k + ldfjac*(k+1)] = -two;
} }
} }
return 0; return 0;
@ -398,7 +400,7 @@ void testHybrd()
} }
struct lmstr_functor { struct lmstr_functor {
static int f(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjrow, int iflag) static int f(const VectorXd &x, VectorXd &fvec, VectorXd &fjrow, int iflag)
{ {
/* subroutine fcn for lmstr1 example. */ /* subroutine fcn for lmstr1 example. */
int i; int i;
@ -406,6 +408,10 @@ struct lmstr_functor {
double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1, double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39}; 3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};
assert(15==fvec.size());
assert(3==x.size());
assert(fjrow.size()==x.size());
if (iflag < 2) if (iflag < 2)
{ {
for (i=0; i<15; i++) for (i=0; i<15; i++)