aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported
diff options
context:
space:
mode:
Diffstat (limited to 'unsupported')
-rw-r--r--unsupported/Eigen/src/NonLinear/hybrj.h16
-rw-r--r--unsupported/Eigen/src/NonLinear/lmstr.h10
-rw-r--r--unsupported/test/NonLinear.cpp24
3 files changed, 27 insertions, 23 deletions
diff --git a/unsupported/Eigen/src/NonLinear/hybrj.h b/unsupported/Eigen/src/NonLinear/hybrj.h
index ebff1c42b..5533196bc 100644
--- a/unsupported/Eigen/src/NonLinear/hybrj.h
+++ b/unsupported/Eigen/src/NonLinear/hybrj.h
@@ -70,7 +70,7 @@ L20:
/* evaluate the function at the starting point */
/* 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;
if (iflag < 0) {
goto L300;
@@ -92,7 +92,7 @@ L30:
/* calculate the jacobian matrix. */
- iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 2);
+ iflag = Functor::f(x, fvec, fjac, 2);
++njev;
if (iflag < 0) {
goto L300;
@@ -202,9 +202,8 @@ L180:
goto L190;
}
iflag = 0;
- if ((iter - 1) % nprint == 0) {
- iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 0);
- }
+ if ((iter - 1) % nprint == 0)
+ iflag = Functor::f(x, fvec, fjac, 0);
if (iflag < 0) {
goto L300;
}
@@ -232,7 +231,7 @@ L190:
/* 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;
if (iflag < 0) {
goto L300;
@@ -395,9 +394,8 @@ L300:
if (iflag < 0) {
info = iflag;
}
- if (nprint > 0) {
- iflag = Functor::f(n, x.data(), fvec.data(), fjac.data(), ldfjac, 0);
- }
+ if (nprint > 0)
+ iflag = Functor::f(x, fvec, fjac, 0);
return info;
/* last card of subroutine hybrj. */
diff --git a/unsupported/Eigen/src/NonLinear/lmstr.h b/unsupported/Eigen/src/NonLinear/lmstr.h
index efeb81635..94d01f32c 100644
--- a/unsupported/Eigen/src/NonLinear/lmstr.h
+++ b/unsupported/Eigen/src/NonLinear/lmstr.h
@@ -66,7 +66,7 @@ L20:
/* evaluate the function at the starting point */
/* 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;
if (iflag < 0) {
goto L340;
@@ -89,7 +89,7 @@ L30:
}
iflag = 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) {
goto L340;
@@ -111,7 +111,7 @@ L40:
}
iflag = 2;
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;
}
temp = fvec[i];
@@ -264,7 +264,7 @@ L240:
/* 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;
if (iflag < 0) {
goto L340;
@@ -406,7 +406,7 @@ L340:
}
iflag = 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;
diff --git a/unsupported/test/NonLinear.cpp b/unsupported/test/NonLinear.cpp
index d9b878c94..31b44e5e8 100644
--- a/unsupported/test/NonLinear.cpp
+++ b/unsupported/test/NonLinear.cpp
@@ -217,13 +217,17 @@ void testLmder()
}
struct hybrj_functor {
- static int f(int n, const double *x, double *fvec, double *fjac, int ldfjac,
- int iflag)
+ static int f(const VectorXd &x, VectorXd &fvec, MatrixXd &fjac, int iflag)
{
/* subroutine fcn for hybrj1 example. */
int j, k;
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)
{
@@ -242,12 +246,10 @@ struct hybrj_functor {
for (k = 0; k < n; k++)
{
for (j = 0; j < n; j++)
- {
- fjac[k + ldfjac*(j)] = zero;
- }
- fjac[k + ldfjac*(k)] = three - four*x[k];
- if (k) fjac[k + ldfjac*(k-1)] = -one;
- if (k != n-1) fjac[k + ldfjac*(k+1)] = -two;
+ fjac(k,j) = zero;
+ fjac(k,k) = three - four*x[k];
+ if (k) fjac(k,k-1) = -one;
+ if (k != n-1) fjac(k,k+1) = -two;
}
}
return 0;
@@ -398,7 +400,7 @@ void testHybrd()
}
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. */
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,
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)
{
for (i=0; i<15; i++)