9 extern "C" void *ctonbe_;
10 extern "C" void *ctcabe_;
11 extern "C" void *euclid_;
12 typedef void (*SimulFunc) (
long* indic,
long* n,
double* x,
double* pf,
double* g,
long [],
float [],
void* dzs);
13 extern "C" void m1qn3_ (
void f(
long* indic,
long* n,
double* x,
double* pf,
double* g,
long [],
float [],
void* dzs),
14 void **,
void **,
void **,
15 long *,
double [],
double *,
double [],
double*,
double *,
16 double *,
char [],
long *,
long *,
long *,
long *,
long *,
long *,
long [],
double [],
long *,
17 long *,
long *,
long [],
float [],
void* );
19 void fakesimul(
long* indic,
long* n,
double* X,
double* pf,
double* G,
long izs[1],
float rzs[1],
void* dzs);
28 void M1qn3Usage(
void){
32 _printf0_(
" Xs are the X values (m x n, where m is the number of independents, n the number of evaluations previously carried out on X)\n");
33 _printf0_(
" Gs are the G (gradient) values (m x n, where m is the number of independents, n the number of evaluations previously carried out on X,G)\n");
62 if(nlhs!=
NLHS || nrhs!=3){
73 SimulFunc costfuncion = &fakesimul;
74 void** prosca = &euclid_;
75 char normtype[] =
"dfn";
86 long niter = long(intn);
87 long nsim = long(intn);
91 IssmPDouble* G = xNew<IssmPDouble>(n);
for (
int i=0;i<n;i++)G[i]=Gs[i*priorn+0];
92 IssmPDouble* X = xNew<IssmPDouble>(n);
for (
int i=0;i<n;i++)X[i]=Xs[i*priorn+0];
97 long ndz = 4*n+m*(2*n+1);
98 double* dz = xNew<double>(ndz);
102 data_struct.priorn=priorn;
103 data_struct.counter=0;
108 m1qn3_(costfuncion,prosca,&ctonbe_,&ctcabe_,
109 &n,X,&f,G,&dxmin,&f1,
110 >tol,normtype,&impres,&io,imode,&omode,&niter,&nsim,iz,dz,&ndz,
111 &reverse,&indic,izs,rzs,(
void*)&data_struct);
115 case 1:
_printf0_(
" Convergence reached (gradient satisfies stopping criterion)\n");
break;
116 case 2:
_printf0_(
" Bad initialization\n");
break;
117 case 3:
_printf0_(
" Line search failure\n");
break;
118 case 4:
_printf0_(
" Maximum number of iterations exceeded\n");
break;
119 case 5:
_printf0_(
" Maximum number of function calls exceeded\n");
break;
120 case 6:
_printf0_(
" stopped on dxmin during line search\n");
break;
121 case 7:
_printf0_(
" <g,d> > 0 or <y,s> <0\n");
break;
122 default:
_printf0_(
" Unknown end condition\n");
126 X_out=xNew<IssmPDouble>(n);
127 for(
int i=0;i<n;i++)X_out[i]=X[i];
136 xDelete<double>(X_out);
140 _error_(
"m1qn3 is not installed");
148 void fakesimul(
long* indic,
long* n,
double* X,
double* pf,
double* G,
long izs[1],
float rzs[1],
void* dzs){
156 if(ds->counter+1==ds->priorn){
163 for(
int i=0;i<*n;i++) X[i]=Xs[ds->priorn*i+ds->counter];
164 for(
int i=0;i<*n;i++) G[i]=Gs[ds->priorn*i+ds->counter];