some more work on Functors

This commit is contained in:
Thomas Capricelli 2009-08-24 21:48:22 +02:00
parent 15d2c3af90
commit 45442b8d41
11 changed files with 63 additions and 49 deletions

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_fdjac1(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Matrix< Scalar, Dynamic, Dynamic > &fjac,
@ -30,7 +31,7 @@ int ei_fdjac1(
if (h == 0.)
h = eps;
x[j] = temp + h;
iflag = Functor::f(x, wa1);
iflag = Functor.f(x, wa1);
if (iflag < 0)
return iflag;
x[j] = temp;
@ -46,7 +47,7 @@ int ei_fdjac1(
if (h == 0.) h = eps;
x[j] = wa2[j] + h;
}
iflag = Functor::f(x, wa1);
iflag = Functor.f(x, wa1);
if (iflag < 0) {
return iflag;
}

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_fdjac2(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Matrix< Scalar, Dynamic, Dynamic > &fjac,
@ -23,7 +24,7 @@ int ei_fdjac2(
h = eps;
}
x[j] = temp + h;
iflag = Functor::f(x, wa);
iflag = Functor.f(x, wa);
if (iflag < 0)
return iflag;
x[j] = temp;

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_hybrd(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
int &nfev,
@ -64,7 +65,7 @@ int ei_hybrd(
/* evaluate the function at the starting point */
/* and calculate its norm. */
iflag = Functor::f(x, fvec);
iflag = Functor.f(x, fvec);
nfev = 1;
if (iflag < 0)
goto algo_end;
@ -91,7 +92,7 @@ int ei_hybrd(
/* calculate the jacobian matrix. */
iflag = ei_fdjac1<Functor,Scalar>(x, fvec, fjac,
iflag = ei_fdjac1(Functor, x, fvec, fjac,
nb_of_subdiagonals, nb_of_superdiagonals, epsfcn, wa1, wa2);
nfev += msum;
if (iflag < 0)
@ -163,12 +164,12 @@ int ei_hybrd(
/* beginning of the inner loop. */
while (true) {
/* if requested, call Functor::f to enable printing of iterates. */
/* if requested, call Functor.f to enable printing of iterates. */
if (nprint > 0) {
iflag = 0;
if ((iter - 1) % nprint == 0)
iflag = Functor::debug(x, fvec);
iflag = Functor.debug(x, fvec);
if (iflag < 0)
goto algo_end;
}
@ -191,7 +192,7 @@ int ei_hybrd(
/* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(wa2, wa4);
iflag = Functor.f(wa2, wa4);
++nfev;
if (iflag < 0)
goto algo_end;
@ -319,7 +320,7 @@ algo_end:
if (iflag < 0)
info = iflag;
if (nprint > 0)
iflag = Functor::debug(x, fvec);
iflag = Functor.debug(x, fvec);
return info;
}

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_hybrd1(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Scalar tol = ei_sqrt(epsilon<Scalar>())
@ -18,7 +19,8 @@ int ei_hybrd1(
}
diag.setConstant(n, 1.);
info = ei_hybrd<Functor,Scalar>(
info = ei_hybrd(
Functor,
x, fvec,
nfev,
fjac,

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_hybrj(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
int &nfev,
@ -59,7 +60,7 @@ int ei_hybrj(
/* evaluate the function at the starting point */
/* and calculate its norm. */
iflag = Functor::f(x, fvec);
iflag = Functor.f(x, fvec);
nfev = 1;
if (iflag < 0)
goto algo_end;
@ -80,7 +81,7 @@ int ei_hybrj(
/* calculate the jacobian matrix. */
iflag = Functor::df(x, fjac);
iflag = Functor.df(x, fjac);
++njev;
if (iflag < 0)
break;
@ -151,12 +152,12 @@ int ei_hybrj(
/* beginning of the inner loop. */
while (true) {
/* if requested, call Functor::f to enable printing of iterates. */
/* if requested, call Functor.f to enable printing of iterates. */
if (nprint > 0) {
iflag = 0;
if ((iter - 1) % nprint == 0)
iflag = Functor::debug(x, fvec, fjac);
iflag = Functor.debug(x, fvec, fjac);
if (iflag < 0)
goto algo_end;
}
@ -179,7 +180,7 @@ int ei_hybrj(
/* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(wa2, wa4);
iflag = Functor.f(wa2, wa4);
++nfev;
if (iflag < 0)
goto algo_end;
@ -306,7 +307,7 @@ algo_end:
if (iflag < 0)
info = iflag;
if (nprint > 0)
iflag = Functor::debug(x, fvec, fjac);
iflag = Functor.debug(x, fvec, fjac);
return info;
}

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_hybrj1(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Matrix< Scalar, Dynamic, Dynamic > &fjac,
@ -18,7 +19,8 @@ int ei_hybrj1(
}
diag.setConstant(n, 1.);
info = ei_hybrj<Functor,Scalar>(
info = ei_hybrj(
Functor,
x, fvec,
nfev, njev,
fjac,

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_lmdif(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
int &nfev,
@ -54,7 +55,7 @@ int ei_lmdif(
/* evaluate the function at the starting point */
/* and calculate its norm. */
iflag = Functor::f(x, fvec);
iflag = Functor.f(x, fvec);
nfev = 1;
if (iflag < 0)
goto algo_end;
@ -71,17 +72,17 @@ int ei_lmdif(
/* calculate the jacobian matrix. */
iflag = ei_fdjac2<Functor,Scalar>(x, fvec, fjac, epsfcn, wa4);
iflag = ei_fdjac2(Functor, x, fvec, fjac, epsfcn, wa4);
nfev += n;
if (iflag < 0)
break;
/* if requested, call Functor::f to enable printing of iterates. */
/* if requested, call Functor.f to enable printing of iterates. */
if (nprint > 0) {
iflag = 0;
if ((iter - 1) % nprint == 0)
iflag = Functor::debug(x, fvec);
iflag = Functor.debug(x, fvec);
if (iflag < 0)
break;
}
@ -177,7 +178,7 @@ int ei_lmdif(
/* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(wa2, wa4);
iflag = Functor.f(wa2, wa4);
++nfev;
if (iflag < 0)
goto algo_end;
@ -274,7 +275,7 @@ algo_end:
if (iflag < 0)
info = iflag;
if (nprint > 0)
iflag = Functor::debug(x, fvec);
iflag = Functor.debug(x, fvec);
return info;
}

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_lmdif1(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Scalar tol = ei_sqrt(epsilon<Scalar>())
@ -18,7 +19,8 @@ int ei_lmdif1(
return 0;
}
info = ei_lmdif<Functor,Scalar>(
info = ei_lmdif(
Functor,
x, fvec,
nfev,
fjac, ipvt, qtf, diag,

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_lmstr(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
int &nfev,
@ -55,7 +56,7 @@ int ei_lmstr(
/* evaluate the function at the starting point */
/* and calculate its norm. */
iflag = Functor::f(x, fvec);
iflag = Functor.f(x, fvec);
nfev = 1;
if (iflag < 0)
goto algo_end;
@ -70,12 +71,12 @@ int ei_lmstr(
while (true) {
/* if requested, call Functor::f to enable printing of iterates. */
/* if requested, call Functor.f to enable printing of iterates. */
if (nprint > 0) {
iflag = 0;
if ((iter - 1) % nprint == 0)
iflag = Functor::debug(x, fvec, wa3);
iflag = Functor.debug(x, fvec, wa3);
if (iflag < 0)
break;
}
@ -89,7 +90,7 @@ int ei_lmstr(
fjac.fill(0.);
iflag = 2;
for (i = 0; i < m; ++i) {
if (Functor::df(x, wa3, iflag) < 0)
if (Functor.df(x, wa3, iflag) < 0)
break;
temp = fvec[i];
ei_rwupdt<Scalar>(n, fjac.data(), fjac.rows(), wa3.data(), qtf.data(), &temp, wa1.data(), wa2.data());
@ -194,7 +195,7 @@ int ei_lmstr(
/* evaluate the function at x + p and calculate its norm. */
iflag = Functor::f(wa2, wa4);
iflag = Functor.f(wa2, wa4);
++nfev;
if (iflag < 0)
goto algo_end;
@ -291,7 +292,7 @@ algo_end:
if (iflag < 0)
info = iflag;
if (nprint > 0)
iflag = Functor::debug(x, fvec, wa3);
iflag = Functor.debug(x, fvec, wa3);
return info;
}

View File

@ -1,6 +1,7 @@
template<typename Functor, typename Scalar>
template<typename FunctorType, typename Scalar>
int ei_lmstr1(
const FunctorType &Functor,
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
VectorXi &ipvt,
@ -19,7 +20,8 @@ int ei_lmstr1(
}
ipvt.resize(n);
info = ei_lmstr<Functor,Scalar>(
info = ei_lmstr(
Functor,
x, fvec,
nfev, njev,
fjac, ipvt, qtf, diag,

View File

@ -266,7 +266,7 @@ void testHybrj1()
x.setConstant(n, -1.);
// do the computation
info = ei_hybrj1<hybrj_functor>(x,fvec, fjac);
info = ei_hybrj1(hybrj_functor(), x,fvec, fjac);
// check return value
VERIFY( 1 == info);
@ -298,7 +298,7 @@ void testHybrj()
diag.setConstant(n, 1.);
// do the computation
info = ei_hybrj<hybrj_functor>(x,fvec, nfev, njev, fjac, R, qtf, diag, mode);
info = ei_hybrj(hybrj_functor(), x,fvec, nfev, njev, fjac, R, qtf, diag, mode);
// check return value
VERIFY( 1 == info);
@ -349,7 +349,7 @@ void testHybrd1()
x.setConstant(n, -1.);
// do the computation
info = ei_hybrd1<hybrd_functor>(x, fvec);
info = ei_hybrd1(hybrd_functor(), x, fvec);
// check return value
VERIFY( 1 == info);
@ -379,7 +379,7 @@ void testHybrd()
diag.setConstant(n, 1.);
// do the computation
info = ei_hybrd<hybrd_functor>(x,fvec, nfev, fjac, R, qtf, diag, mode, ml, mu);
info = ei_hybrd(hybrd_functor(), x,fvec, nfev, fjac, R, qtf, diag, mode, ml, mu);
// check return value
VERIFY( 1 == info);
@ -447,7 +447,7 @@ void testLmstr1()
x.setConstant(n, 1.);
// do the computation
info = ei_lmstr1<lmstr_functor>(x, fvec, ipvt);
info = ei_lmstr1(lmstr_functor(), x, fvec, ipvt);
// check return value
VERIFY( 1 == info);
@ -474,7 +474,7 @@ void testLmstr()
x.setConstant(n, 1.);
// do the computation
info = ei_lmstr<lmstr_functor>(x, fvec, nfev, njev, fjac, ipvt, qtf, diag);
info = ei_lmstr(lmstr_functor(), x, fvec, nfev, njev, fjac, ipvt, qtf, diag);
VectorXd wa(n);
// check return values
@ -529,7 +529,7 @@ void testLmdif1()
x.setConstant(n, 1.);
// do the computation
info = ei_lmdif1<lmdif_functor>(x, fvec);
info = ei_lmdif1(lmdif_functor(), x, fvec);
// check return value
VERIFY( 1 == info);
@ -557,7 +557,7 @@ void testLmdif()
x.setConstant(n, 1.);
// do the computation
info = ei_lmdif<lmdif_functor>(x, fvec, nfev, fjac, ipvt, qtf, diag);
info = ei_lmdif(lmdif_functor(), x, fvec, nfev, fjac, ipvt, qtf, diag);
// check return values
VERIFY( 1 == info);