diff --git a/unsupported/Eigen/src/NonLinear/fdjac1.h b/unsupported/Eigen/src/NonLinear/fdjac1.h index e697e7ab6..7c317df28 100644 --- a/unsupported/Eigen/src/NonLinear/fdjac1.h +++ b/unsupported/Eigen/src/NonLinear/fdjac1.h @@ -1,6 +1,7 @@ -template +template 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; } diff --git a/unsupported/Eigen/src/NonLinear/fdjac2.h b/unsupported/Eigen/src/NonLinear/fdjac2.h index f2e627d4f..bc3a82106 100644 --- a/unsupported/Eigen/src/NonLinear/fdjac2.h +++ b/unsupported/Eigen/src/NonLinear/fdjac2.h @@ -1,6 +1,7 @@ -template +template 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; diff --git a/unsupported/Eigen/src/NonLinear/hybrd.h b/unsupported/Eigen/src/NonLinear/hybrd.h index d6415bde4..ef310b5e1 100644 --- a/unsupported/Eigen/src/NonLinear/hybrd.h +++ b/unsupported/Eigen/src/NonLinear/hybrd.h @@ -1,6 +1,7 @@ -template +template 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(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; } diff --git a/unsupported/Eigen/src/NonLinear/hybrd1.h b/unsupported/Eigen/src/NonLinear/hybrd1.h index 47b64d8e8..b52acfb94 100644 --- a/unsupported/Eigen/src/NonLinear/hybrd1.h +++ b/unsupported/Eigen/src/NonLinear/hybrd1.h @@ -1,6 +1,7 @@ -template +template int ei_hybrd1( + const FunctorType &Functor, Matrix< Scalar, Dynamic, 1 > &x, Matrix< Scalar, Dynamic, 1 > &fvec, Scalar tol = ei_sqrt(epsilon()) @@ -18,7 +19,8 @@ int ei_hybrd1( } diag.setConstant(n, 1.); - info = ei_hybrd( + info = ei_hybrd( + Functor, x, fvec, nfev, fjac, diff --git a/unsupported/Eigen/src/NonLinear/hybrj.h b/unsupported/Eigen/src/NonLinear/hybrj.h index 1c99bd7d7..a77eecf45 100644 --- a/unsupported/Eigen/src/NonLinear/hybrj.h +++ b/unsupported/Eigen/src/NonLinear/hybrj.h @@ -1,6 +1,7 @@ -template +template 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; } diff --git a/unsupported/Eigen/src/NonLinear/hybrj1.h b/unsupported/Eigen/src/NonLinear/hybrj1.h index c32b0cf95..684a0e9ba 100644 --- a/unsupported/Eigen/src/NonLinear/hybrj1.h +++ b/unsupported/Eigen/src/NonLinear/hybrj1.h @@ -1,6 +1,7 @@ -template +template 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( + info = ei_hybrj( + Functor, x, fvec, nfev, njev, fjac, diff --git a/unsupported/Eigen/src/NonLinear/lmdif.h b/unsupported/Eigen/src/NonLinear/lmdif.h index 54db71d3d..3bf99e658 100644 --- a/unsupported/Eigen/src/NonLinear/lmdif.h +++ b/unsupported/Eigen/src/NonLinear/lmdif.h @@ -1,6 +1,7 @@ -template +template 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(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; } diff --git a/unsupported/Eigen/src/NonLinear/lmdif1.h b/unsupported/Eigen/src/NonLinear/lmdif1.h index 6b795b010..e272df4f7 100644 --- a/unsupported/Eigen/src/NonLinear/lmdif1.h +++ b/unsupported/Eigen/src/NonLinear/lmdif1.h @@ -1,6 +1,7 @@ -template +template int ei_lmdif1( + const FunctorType &Functor, Matrix< Scalar, Dynamic, 1 > &x, Matrix< Scalar, Dynamic, 1 > &fvec, Scalar tol = ei_sqrt(epsilon()) @@ -18,7 +19,8 @@ int ei_lmdif1( return 0; } - info = ei_lmdif( + info = ei_lmdif( + Functor, x, fvec, nfev, fjac, ipvt, qtf, diag, diff --git a/unsupported/Eigen/src/NonLinear/lmstr.h b/unsupported/Eigen/src/NonLinear/lmstr.h index 1d0a7684a..ddd662ab8 100644 --- a/unsupported/Eigen/src/NonLinear/lmstr.h +++ b/unsupported/Eigen/src/NonLinear/lmstr.h @@ -1,6 +1,7 @@ -template +template 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(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; } diff --git a/unsupported/Eigen/src/NonLinear/lmstr1.h b/unsupported/Eigen/src/NonLinear/lmstr1.h index 737b569ad..19df28394 100644 --- a/unsupported/Eigen/src/NonLinear/lmstr1.h +++ b/unsupported/Eigen/src/NonLinear/lmstr1.h @@ -1,6 +1,7 @@ -template +template 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( + info = ei_lmstr( + Functor, x, fvec, nfev, njev, fjac, ipvt, qtf, diag, diff --git a/unsupported/test/NonLinear.cpp b/unsupported/test/NonLinear.cpp index 7a10d7dfe..eda5090c1 100644 --- a/unsupported/test/NonLinear.cpp +++ b/unsupported/test/NonLinear.cpp @@ -266,7 +266,7 @@ void testHybrj1() x.setConstant(n, -1.); // do the computation - info = ei_hybrj1(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(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(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(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(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(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(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(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);