ext/lbfgsb/src/lbfgsb.c in lbfgsb-0.3.2 vs ext/lbfgsb/src/lbfgsb.c in lbfgsb-0.4.0

- old
+ new

@@ -42,13 +42,13 @@ * Mexico D.F. Mexico. * * March 2011 */ +#include "lbfgsb.h" #include "blas.h" #include "linpack.h" -#include "lbfgsb.h" static double c_b9 = 0.; static long c__1 = 1; static long c__11 = 11; static double c_b280 = .001; @@ -230,16 +230,12 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int setulb_(long *n, long *m, double *x, - double *l, double *u, long *nbd, double *f, double *g, - double *factr, double *pgtol, double *wa, long *iwa, - char *task, long *iprint, char *csave, long *lsave, - long *isave, double *dsave) -{ +int setulb_(long* n, long* m, double* x, double* l, double* u, long* nbd, double* f, double* g, double* factr, double* pgtol, + double* wa, long* iwa, char* task, long* iprint, char* csave, long* lsave, long* isave, double* dsave) { long i__1; static long ld, lr, lt, lz, lwa, lwn, lss, lxp, lws, lwt, lsy, lwy, lsnd; /* jlm-jn */ @@ -285,15 +281,13 @@ lr = isave[12]; ld = isave[13]; lt = isave[14]; lxp = isave[15]; lwa = isave[16]; - mainlb_(n, m, &x[1], &l[1], &u[1], &nbd[1], f, &g[1], factr, pgtol, &wa[lws], - &wa[lwy], &wa[lsy], &wa[lss], &wa[lwt], &wa[lwn], &wa[lsnd], - &wa[lz], &wa[lr], &wa[ld], &wa[lt], &wa[lxp], &wa[lwa], &iwa[1], - &iwa[*n + 1], &iwa[(*n << 1) + 1], task, iprint, csave, &lsave[1], - &isave[22], &dsave[1]); + mainlb_(n, m, &x[1], &l[1], &u[1], &nbd[1], f, &g[1], factr, pgtol, &wa[lws], &wa[lwy], &wa[lsy], &wa[lss], &wa[lwt], + &wa[lwn], &wa[lsnd], &wa[lz], &wa[lr], &wa[ld], &wa[lt], &wa[lxp], &wa[lwa], &iwa[1], &iwa[*n + 1], + &iwa[(*n << 1) + 1], task, iprint, csave, &lsave[1], &isave[22], &dsave[1]); return 0; } /** * Subroutine mainlb @@ -469,24 +463,18 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int mainlb_(long *n, long *m, double *x, - double *l, double *u, long *nbd, double *f, double *g, - double *factr, double *pgtol, double *ws, double *wy, - double *sy, double *ss, double *wt, double *wn, - double *snd, double *z__, double *r__, double *d__, - double *t, double *xp, double *wa, long *index, - long *iwhere, long *indx2, char *task, long *iprint, - char *csave, long *lsave, long *isave, double *dsave) -{ - long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, - ss_dim1, ss_offset, wt_dim1, wt_offset, wn_dim1, wn_offset, - snd_dim1, snd_offset, i__1; +int mainlb_(long* n, long* m, double* x, double* l, double* u, long* nbd, double* f, double* g, double* factr, double* pgtol, + double* ws, double* wy, double* sy, double* ss, double* wt, double* wn, double* snd, double* z__, double* r__, + double* d__, double* t, double* xp, double* wa, long* index, long* iwhere, long* indx2, char* task, long* iprint, + char* csave, long* lsave, long* isave, double* dsave) { + long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, wt_dim1, wt_offset, wn_dim1, wn_offset, + snd_dim1, snd_offset, i__1; double d__1, d__2; - FILE *itfptr; + FILE* itfptr; static long i__, k; static double gd, dr, rr, dtd; static long col; static double tol; static long wrk; @@ -608,13 +596,12 @@ info = 0; itfile = 8; /* Check the input arguments for errors. */ errclb_(n, m, factr, &l[1], &u[1], &nbd[1], task, &info, &k); if (strncmp(task, "ERROR", 5) == 0) { - prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, - &nskip, &nact, &sbgnrm, &c_b9, &nseg, word, &iback, - &stp, &xstep, &k, &cachyt, &sbtime, &lnscht); + prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, &nskip, &nact, &sbgnrm, &c_b9, &nseg, word, + &iback, &stp, &xstep, &k, &cachyt, &sbtime, &lnscht); return 0; } prn1lb_(n, m, &l[1], &u[1], &x[1], iprint, &itfile, &epsmch); /* Initialize iwhere & project x onto the feasible set. */ active_(n, &l[1], &u[1], &nbd[1], &x[1], &iwhere[1], iprint, &prjctd, &cnstnd, &boxed); @@ -705,25 +692,24 @@ i__1 = iter + 1; fprintf(stdout, "\n\nITERATION %5ld\n", i__1); } iword = -1; - if (! cnstnd && col > 0) { + if (!cnstnd && col > 0) { /* skip the search for GCP. */ lbfgsb_rb_dcopy_(n, &x[1], &c__1, &z__[1], &c__1); wrk = updatd; nseg = 0; goto L333; } /** * Compute the Generalized Cauchy Point (GCP). */ timer_(&cpu1); - cauchy_(n, &x[1], &l[1], &u[1], &nbd[1], &g[1], &indx2[1], &iwhere[1], &t[1], - &d__[1], &z__[1], m, &wy[wy_offset], &ws[ws_offset], &sy[sy_offset], - &wt[wt_offset], &theta, &col, &head, &wa[1], &wa[(*m << 1) + 1], - &wa[(*m << 2) + 1], &wa[*m * 6 + 1], &nseg, iprint, &sbgnrm, &info, &epsmch); + cauchy_(n, &x[1], &l[1], &u[1], &nbd[1], &g[1], &indx2[1], &iwhere[1], &t[1], &d__[1], &z__[1], m, &wy[wy_offset], + &ws[ws_offset], &sy[sy_offset], &wt[wt_offset], &theta, &col, &head, &wa[1], &wa[(*m << 1) + 1], &wa[(*m << 2) + 1], + &wa[*m * 6 + 1], &nseg, iprint, &sbgnrm, &info, &epsmch); if (info != 0) { /* singular triangular system detected; refresh the lbfgs memory. */ if (*iprint >= 1) { fprintf(stdout, "\n"); fprintf(stdout, " Singular triangular system detected;\n"); @@ -760,13 +746,12 @@ /* matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ] */ /* [L_a -R_z theta*S'AA'S ] */ /* where E = [-I 0] */ /* [ 0 I] */ if (wrk) { - formk_(n, &nfree, &index[1], &nenter, &ileave, &indx2[1], &iupdat, &updatd, - &wn[wn_offset], &snd[snd_offset], m, &ws[ws_offset], &wy[wy_offset], - &sy[sy_offset], &theta, &col, &head, &info); + formk_(n, &nfree, &index[1], &nenter, &ileave, &indx2[1], &iupdat, &updatd, &wn[wn_offset], &snd[snd_offset], m, + &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], &theta, &col, &head, &info); } if (info != 0) { /* nonpositive definiteness in Cholesky factorization; */ /* refresh the lbfgs memory and restart the iteration. */ if (*iprint >= 1) { @@ -784,20 +769,18 @@ sbtime = sbtime + cpu2 - cpu1; goto L222; } /* compute r=-Z'B(xcp-xk)-Z'g (using wa(2m+1)=W'(xcp-x) */ /* from 'cauchy'). */ - cmprlb_(n, m, &x[1], &g[1], &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], - &wt[wt_offset], &z__[1], &r__[1], &wa[1], &index[1], &theta, &col, - &head, &nfree, &cnstnd, &info); + cmprlb_(n, m, &x[1], &g[1], &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], &wt[wt_offset], &z__[1], &r__[1], &wa[1], + &index[1], &theta, &col, &head, &nfree, &cnstnd, &info); if (info != 0) { goto L444; } /* jlm-jn call the direct method. */ - subsm_(n, m, &nfree, &index[1], &l[1], &u[1], &nbd[1], &z__[1], &r__[1], &xp[1], - &ws[ws_offset], &wy[wy_offset], &theta, &x[1], &g[1], &col, - &head, &iword, &wa[1], &wn[wn_offset], iprint, &info); + subsm_(n, m, &nfree, &index[1], &l[1], &u[1], &nbd[1], &z__[1], &r__[1], &xp[1], &ws[ws_offset], &wy[wy_offset], &theta, + &x[1], &g[1], &col, &head, &iword, &wa[1], &wn[wn_offset], iprint, &info); L444: if (info != 0) { /* singular triangular system detected; */ /* refresh the lbfgs memory and restart the iteration. */ if (*iprint >= 1) { @@ -826,14 +809,12 @@ for (i__ = 1; i__ <= i__1; ++i__) { d__[i__] = z__[i__] - x[i__]; } timer_(&cpu1); L666: - lnsrlb_(n, &l[1], &u[1], &nbd[1], &x[1], f, &fold, &gd, &gdold, &g[1], - &d__[1], &r__[1], &t[1], &z__[1], &stp, &dnorm, &dtd, &xstep, - &stpmx, &iter, &ifun, &iback, &nfgv, &info, task, &boxed, &cnstnd, - csave, &isave[22], &dsave[17]); + lnsrlb_(n, &l[1], &u[1], &nbd[1], &x[1], f, &fold, &gd, &gdold, &g[1], &d__[1], &r__[1], &t[1], &z__[1], &stp, &dnorm, &dtd, + &xstep, &stpmx, &iter, &ifun, &iback, &nfgv, &info, task, &boxed, &cnstnd, csave, &isave[22], &dsave[17]); if (info != 0 || iback >= 20) { /* restore the previous iterate. */ lbfgsb_rb_dcopy_(n, &t[1], &c__1, &x[1], &c__1); lbfgsb_rb_dcopy_(n, &r__[1], &c__1, &g[1], &c__1); *f = fold; @@ -879,12 +860,11 @@ lnscht = lnscht + cpu2 - cpu1; ++iter; /* Compute the infinity norm of the projected (-)gradient. */ projgr_(n, &l[1], &u[1], &nbd[1], &x[1], &g[1], &sbgnrm); /* Print iteration information. */ - prn2lb_(n, &x[1], f, &g[1], iprint, &itfile, &iter, &nfgv, &nact, - &sbgnrm, &nseg, word, &iword, &iback, &stp, &xstep); + prn2lb_(n, &x[1], f, &g[1], iprint, &itfile, &iter, &nfgv, &nact, &sbgnrm, &nseg, word, &iword, &iback, &stp, &xstep); goto L1000; } L777: /* Test for termination. */ if (sbgnrm <= *pgtol) { @@ -932,13 +912,12 @@ * Update the L-BFGS matrix. */ updatd = TRUE_; ++iupdat; /* Update matrices WS and WY and form the middle matrix in B. */ - matupd_(n, m, &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], - &ss[ss_offset], &d__[1], &r__[1], &itail, &iupdat, &col, &head, - &theta, &rr, &dr, &stp, &dtd); + matupd_(n, m, &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], &ss[ss_offset], &d__[1], &r__[1], &itail, &iupdat, &col, &head, + &theta, &rr, &dr, &stp, &dtd); /* Form the upper half of the pds T = theta*SS + L*D^(-1)*L'; */ /* Store T in the upper triangular of the array wt; */ /* Cholesky factorize T to J*J' with */ /* J' stored in the upper triangular of wt. */ formt_(m, &wt[wt_offset], &sy[sy_offset], &ss[ss_offset], &col, &theta, &info); @@ -965,13 +944,12 @@ /* -------------------- the end of the loop ----------------------------- */ goto L222; L999: timer_(&time2); time = time2 - time1; - prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, - &nskip, &nact, &sbgnrm, &time, &nseg, word, &iback, &stp, &xstep, - &k, &cachyt, &sbtime, &lnscht); + prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, &nskip, &nact, &sbgnrm, &time, &nseg, word, &iback, + &stp, &xstep, &k, &cachyt, &sbtime, &lnscht); L1000: /* Save local variables. */ lsave[1] = prjctd; lsave[2] = cnstnd; lsave[3] = boxed; @@ -1033,14 +1011,12 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int active_(long *n, double *l, double *u, - long *nbd, double *x, long *iwhere, long *iprint, - long *prjctd, long *cnstnd, long *boxed) -{ +int active_(long* n, double* l, double* u, long* nbd, double* x, long* iwhere, long* iprint, long* prjctd, long* cnstnd, + long* boxed) { long i__1; static long i__, nbdd; --iwhere; --x; --nbd; @@ -1078,11 +1054,11 @@ *boxed = FALSE_; } if (nbd[i__] == 0) { /* this variable is always free */ iwhere[i__] = -1; - /* otherwise set x(i)=mid(x(i), u(i), l(i)). */ + /* otherwise set x(i)=mid(x(i), u(i), l(i)). */ } else { *cnstnd = TRUE_; if (nbd[i__] == 2 && u[i__] - l[i__] <= 0.) { /* this variable is always fixed */ iwhere[i__] = 3; @@ -1093,11 +1069,11 @@ } if (*iprint >= 0) { if (*prjctd) { fprintf(stdout, " The initial X is infeasible. Restart with its projection.\n"); } - if (! (*cnstnd)) { + if (!(*cnstnd)) { fprintf(stdout, " This problem is unconstrained.\n"); } } if (*iprint > 0) { fprintf(stdout, "\n"); @@ -1157,13 +1133,11 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int bmv_(long *m, double *sy, double *wt, long - *col, double *v, double *p, long *info) -{ +int bmv_(long* m, double* sy, double* wt, long* col, double* v, double* p, long* info) { long sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2; static long i__, k, i2; static double sum; wt_dim1 = *m; @@ -1398,18 +1372,14 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int cauchy_(long *n, double *x, double *l, - double *u, long *nbd, double *g, long *iorder, long *iwhere, - double *t, double *d__, double *xcp, long *m, - double *wy, double *ws, double *sy, double *wt, - double *theta, long *col, long *head, double *p, - double *c__, double *wbp, double *v, long *nseg, - long *iprint, double *sbgnrm, long *info, double *epsmch) -{ +int cauchy_(long* n, double* x, double* l, double* u, long* nbd, double* g, long* iorder, long* iwhere, double* t, double* d__, + double* xcp, long* m, double* wy, double* ws, double* sy, double* wt, double* theta, long* col, long* head, + double* p, double* c__, double* wbp, double* v, long* nseg, long* iprint, double* sbgnrm, long* info, + double* epsmch) { long wy_dim1, wy_offset, ws_dim1, ws_offset, sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2; double d__1; static long i__, j; static double f1, f2, dt, tj, tl, tu, tj0; static long ibp; @@ -1780,16 +1750,12 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int cmprlb_(long *n, long *m, double *x, - double *g, double *ws, double *wy, double *sy, - double *wt, double *z__, double *r__, double *wa, - long *index, double *theta, long *col, long *head, - long *nfree, long *cnstnd, long *info) -{ +int cmprlb_(long* n, long* m, double* x, double* g, double* ws, double* wy, double* sy, double* wt, double* z__, double* r__, + double* wa, long* index, double* theta, long* col, long* head, long* nfree, long* cnstnd, long* info) { long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2; static long i__, j, k; static double a1, a2; static long pointr; @@ -1810,11 +1776,11 @@ wy -= wy_offset; ws_dim1 = *n; ws_offset = 1 + ws_dim1; ws -= ws_offset; - if (! (*cnstnd) && *col > 0) { + if (!(*cnstnd) && *col > 0) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { r__[i__] = -g[i__]; } } else { @@ -1856,13 +1822,11 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int errclb_(long *n, long *m, double *factr, - double *l, double *u, long *nbd, char *task, long *info, long *k) -{ +int errclb_(long* n, long* m, double* factr, double* l, double* u, long* nbd, char* task, long* info, long* k) { long i__1; static long i__; --nbd; --u; --l; @@ -2015,18 +1979,13 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int formk_(long *n, long *nsub, long *ind, long *nenter, - long *ileave, long *indx2, long *iupdat, long *updatd, - double *wn, double *wn1, long *m, double *ws, - double *wy, double *sy, double *theta, long *col, - long *head, long *info) -{ - long wn_dim1, wn_offset, wn1_dim1, wn1_offset, ws_dim1, ws_offset, - wy_dim1, wy_offset, sy_dim1, sy_offset, i__1, i__2, i__3; +int formk_(long* n, long* nsub, long* ind, long* nenter, long* ileave, long* indx2, long* iupdat, long* updatd, double* wn, + double* wn1, long* m, double* ws, double* wy, double* sy, double* theta, long* col, long* head, long* info) { + long wn_dim1, wn_offset, wn1_dim1, wn1_offset, ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, i__1, i__2, i__3; static long i__, k, k1, m2, is, js, iy, jy, is1, js1, col2, dend, pend; static long upcl; static double temp1, temp2, temp3, temp4; static long ipntr, jpntr, dbegin, pbegin; @@ -2263,13 +2222,11 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int formt_(long *m, double *wt, double *sy, - double *ss, long *col, double *theta, long *info) -{ +int formt_(long* m, double* wt, double* sy, double* ss, long* col, double* theta, long* info) { long wt_dim1, wt_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, i__1, i__2, i__3; static long i__, j, k, k1; static double ddum; ss_dim1 = *m; @@ -2341,15 +2298,12 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int freev_(long *n, long *nfree, long *index, - long *nenter, long *ileave, long *indx2, long *iwhere, - long *wrk, long *updatd, long *cnstnd, long *iprint, - long *iter) -{ +int freev_(long* n, long* nfree, long* index, long* nenter, long* ileave, long* indx2, long* iwhere, long* wrk, long* updatd, + long* cnstnd, long* iprint, long* iter) { long i__1; static long i__, k, iact; --iwhere; --indx2; @@ -2383,11 +2337,11 @@ } } } if (*iprint >= 99) { i__1 = *n + 1 - *ileave; - fprintf(stdout, " %2ld variables leave; %2ld variables enter\n", i__1, *nenter); + fprintf(stdout, " %2ld variables leave; %2ld variables enter\n", i__1, *nenter); } } *wrk = *ileave < *n + 1 || *nenter > 0 || *updatd; /* Find the index set of free and active variables at the GCP. */ *nfree = 0; @@ -2446,12 +2400,11 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int hpsolb_(long *n, double *t, long *iorder, long *iheap) -{ +int hpsolb_(long* n, double* t, long* iorder, long* iheap) { long i__1; static long i__, j, k; static double out, ddum; static long indxin, indxou; @@ -2464,11 +2417,11 @@ for (k = 2; k <= i__1; ++k) { ddum = t[k]; indxin = iorder[k]; /* Add ddum to the heap. */ i__ = k; -L10: + L10: if (i__ > 1) { j = i__ / 2; if (ddum < t[j]) { t[i__] = t[j]; iorder[i__] = iorder[j]; @@ -2488,11 +2441,11 @@ out = t[1]; indxou = iorder[1]; ddum = t[*n]; indxin = iorder[*n]; /* Restore the heap */ -L30: + L30: j = i__ + i__; if (j <= *n - 1) { if (t[j + 1] < t[j]) { ++j; } @@ -2532,19 +2485,14 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int lnsrlb_(long *n, double *l, double *u, - long *nbd, double *x, double *f, double *fold, - double *gd, double *gdold, double *g, double *d__, - double *r__, double *t, double *z__, double *stp, - double *dnorm, double *dtd, double *xstep, double *stpmx, - long *iter, long *ifun, long *iback, long *nfgv, - long *info, char *task, long *boxed, long *cnstnd, - char *csave, long *isave, double *dsave) -{ +int lnsrlb_(long* n, double* l, double* u, long* nbd, double* x, double* f, double* fold, double* gd, double* gdold, double* g, + double* d__, double* r__, double* t, double* z__, double* stp, double* dnorm, double* dtd, double* xstep, + double* stpmx, long* iter, long* ifun, long* iback, long* nfgv, long* info, char* task, long* boxed, long* cnstnd, + char* csave, long* isave, double* dsave) { long i__1; double d__1; static long i__; static double a1, a2; @@ -2592,11 +2540,11 @@ } } } } } - if (*iter == 0 && ! (*boxed)) { + if (*iter == 0 && !(*boxed)) { d__1 = 1. / *dnorm; *stp = d__1 <= *stpmx ? d__1 : *stpmx; } else { *stp = 1.; } @@ -2656,16 +2604,12 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int matupd_(long *n, long *m, double *ws, - double *wy, double *sy, double *ss, double *d__, - double *r__, long *itail, long *iupdat, long *col, - long *head, double *theta, double *rr, double *dr, - double *stp, double *dtd) -{ +int matupd_(long* n, long* m, double* ws, double* wy, double* sy, double* ss, double* d__, double* r__, long* itail, + long* iupdat, long* col, long* head, double* theta, double* rr, double* dr, double* stp, double* dtd) { long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, i__1, i__2; static long j; static long pointr; --r__; @@ -2741,16 +2685,13 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int prn1lb_(long *n, long *m, double *l, - double *u, double *x, long *iprint, long *itfile, - double *epsmch) -{ +int prn1lb_(long* n, long* m, double* l, double* u, double* x, long* iprint, long* itfile, double* epsmch) { long i__1; - FILE *itfptr; + FILE* itfptr; static long i__; --x; --u; --l; @@ -2838,18 +2779,15 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int prn2lb_(long *n, double *x, double *f, - double *g, long *iprint, long *itfile, long *iter, - long *nfgv, long *nact, double *sbgnrm, long *nseg, char*word, - long *iword, long *iback, double *stp, double *xstep) -{ +int prn2lb_(long* n, double* x, double* f, double* g, long* iprint, long* itfile, long* iter, long* nfgv, long* nact, + double* sbgnrm, long* nseg, char* word, long* iword, long* iback, double* stp, double* xstep) { long i__1; static long i__, imod; - FILE *itfptr; + FILE* itfptr; --g; --x; /* 'word' records the status of subspace solutions. */ if (*iword == 0) { @@ -2888,12 +2826,12 @@ fprintf(stdout, "\nAt iterate%5ld f= %12.5E |proj g|= %12.5E\n", *iter, *f, *sbgnrm); } } if (*iprint >= 1) { itfptr = fopen("iterate.dat", "a"); - fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E %10.3E %10.3E\n", - *iter, *nfgv, *nseg, *nact, word, *iback, *stp, *xstep, *sbgnrm, *f); + fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E %10.3E %10.3E\n", *iter, *nfgv, *nseg, *nact, word, *iback, + *stp, *xstep, *sbgnrm, *f); fclose(itfptr); } return 0; } @@ -2911,19 +2849,15 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int prn3lb_(long *n, double *x, double *f, char *task, - long *iprint, long *info, long *itfile, long *iter, - long *nfgv, long *nintol, long *nskip, long *nact, - double *sbgnrm, double *time, long *nseg, char *word, - long *iback, double *stp, double *xstep, long *k, - double *cachyt, double *sbtime, double *lnscht) -{ +int prn3lb_(long* n, double* x, double* f, char* task, long* iprint, long* info, long* itfile, long* iter, long* nfgv, + long* nintol, long* nskip, long* nact, double* sbgnrm, double* time, long* nseg, char* word, long* iback, + double* stp, double* xstep, long* k, double* cachyt, double* sbtime, double* lnscht) { long i__1; - FILE *itfptr; + FILE* itfptr; static long i__; --x; if (strncmp(task, "ERROR", 5) == 0) { @@ -3021,12 +2955,12 @@ fprintf(stdout, "\n"); if (*iprint >= 1) { itfptr = fopen("iterate.dat", "a"); if (*info == -4 || *info == -9) { - fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E - -\n", - *iter, *nfgv, *nseg, *nact, word, *iback, *stp, *xstep); + fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E - -\n", *iter, *nfgv, *nseg, *nact, word, + *iback, *stp, *xstep); } fprintf(itfptr, "\n"); fprintf(itfptr, "%s\n", task); if (*info != 0) { if (*info == -1) { @@ -3088,13 +3022,11 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ -int projgr_(long *n, double *l, double *u, - long *nbd, double *x, double *g, double *sbgnrm) -{ +int projgr_(long* n, double* l, double* u, long* nbd, double* x, double* g, double* sbgnrm) { long i__1; double d__1, d__2; static long i__; static double gi; @@ -3297,17 +3229,13 @@ * Argonne National Laboratory and Northwestern University. * Written by * Ciyou Zhu * in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal */ -int subsm_(long *n, long *m, long *nsub, long *ind, - double *l, double *u, long *nbd, double *x, - double *d__, double *xp, double *ws, double *wy, - double *theta, double *xx, double *gg, long *col, - long *head, long *iword, double *wv, double *wn, - long *iprint, long *info) -{ +int subsm_(long* n, long* m, long* nsub, long* ind, double* l, double* u, long* nbd, double* x, double* d__, double* xp, + double* ws, double* wy, double* theta, double* xx, double* gg, long* col, long* head, long* iword, double* wv, + double* wn, long* iprint, long* info) { long ws_dim1, ws_offset, wy_dim1, wy_offset, wn_dim1, wn_offset, i__1, i__2; double d__1, d__2; static long i__, j, k, m2; static double dk; static long js, jy; @@ -3379,12 +3307,11 @@ for (jy = 1; jy <= i__1; ++jy) { js = *col + jy; i__2 = *nsub; for (i__ = 1; i__ <= i__2; ++i__) { k = ind[i__]; - d__[i__] = d__[i__] + wy[k + pointr * wy_dim1] * wv[jy] / *theta - + ws[k + pointr * ws_dim1] * wv[js]; + d__[i__] = d__[i__] + wy[k + pointr * wy_dim1] * wv[jy] / *theta + ws[k + pointr * ws_dim1] * wv[js]; } pointr = pointr % *m + 1; } d__1 = 1. / *theta; lbfgsb_rb_dscal_(nsub, &d__1, &d__[1], &c__1); @@ -3635,15 +3562,12 @@ * * MINPACK-2 Project. October 1993. * Argonne National Laboratory and University of Minnesota. * Brett M. Averick, Richard G. Carter, and Jorge J. More'. */ -int dcsrch_(double *f, double *g, double *stp, - double *ftol, double *gtol, double *xtol, - double *stpmin, double *stpmax, - char *task, long *isave, double *dsave) -{ +int dcsrch_(double* f, double* g, double* stp, double* ftol, double* gtol, double* xtol, double* stpmin, double* stpmax, + char* task, long* isave, double* dsave) { double d__1; static double fm, gm, fx, fy, gx, gy, fxm, fym, gxm, gym, stx, sty; static long stage; static double finit, ginit, width, ftest, gtest, stmin, stmax, width1; @@ -3915,15 +3839,12 @@ * * MINPACK-2 Project. October 1993. * Argonne National Laboratory and University of Minnesota. * Brett M. Averick and Jorge J. More'. */ -int dcstep_(double *stx, double *fx, double *dx, - double *sty, double *fy, double *dy, double *stp, - double *fp, double *dp, long *brackt, double *stpmin, - double *stpmax) -{ +int dcstep_(double* stx, double* fx, double* dx, double* sty, double* fy, double* dy, double* stp, double* fp, double* dp, + long* brackt, double* stpmin, double* stpmax) { double d__1, d__2, d__3; static double p, q, r__, s, sgnd, stpc, stpf, stpq, gamma, theta; sgnd = *dp * (*dx / fabs(*dx)); /* First case: A higher function value. The minimum is bracketed. */ @@ -3951,14 +3872,14 @@ stpf = stpc; } else { stpf = stpc + (stpq - stpc) / 2.; } *brackt = TRUE_; - /* Second case: A lower function value and derivatives of opposite */ - /* sign. The minimum is bracketed. If the cubic step is farther from */ - /* stp than the secant step, the cubic step is taken, otherwise the */ - /* secant step is taken. */ + /* Second case: A lower function value and derivatives of opposite */ + /* sign. The minimum is bracketed. If the cubic step is farther from */ + /* stp than the secant step, the cubic step is taken, otherwise the */ + /* secant step is taken. */ } else if (sgnd < 0.) { theta = (*fx - *fp) * 3. / (*stp - *stx) + *dx + *dp; d__1 = fabs(theta); d__2 = fabs(*dx); d__1 = d__1 >= d__2 ? d__1 : d__2; @@ -3978,12 +3899,12 @@ stpf = stpc; } else { stpf = stpq; } *brackt = TRUE_; - /* Third case: A lower function value, derivatives of the same sign, */ - /* and the magnitude of the derivative decreases. */ + /* Third case: A lower function value, derivatives of the same sign, */ + /* and the magnitude of the derivative decreases. */ } else if (fabs(*dp) < fabs(*dx)) { /* The cubic step is computed only if the cubic tends to infinity */ /* in the direction of the step or if the minimum of the cubic */ /* is beyond stp. Otherwise the cubic step is defined to be the */ /* secant step. */ @@ -4039,22 +3960,22 @@ stpf = stpq; } stpf = *stpmax <= stpf ? *stpmax : stpf; stpf = *stpmin >= stpf ? *stpmin : stpf; } - /* Fourth case: A lower function value, derivatives of the same sign, */ - /* and the magnitude of the derivative does not decrease. If the */ - /* minimum is not bracketed, the step is either stpmin or stpmax, */ - /* otherwise the cubic step is taken. */ + /* Fourth case: A lower function value, derivatives of the same sign, */ + /* and the magnitude of the derivative does not decrease. If the */ + /* minimum is not bracketed, the step is either stpmin or stpmax, */ + /* otherwise the cubic step is taken. */ } else { if (*brackt) { theta = (*fp - *fy) * 3. / (*sty - *stp) + *dy + *dp; d__1 = fabs(theta); d__2 = fabs(*dy); d__1 = d__1 >= d__2 ? d__1 : d__2; d__2 = fabs(*dp); - s = d__1 >= d__2 ? d__1: d__2; + s = d__1 >= d__2 ? d__1 : d__2; d__1 = theta / s; gamma = s * sqrt(d__1 * d__1 - *dy / s * (*dp / s)); if (*stp > *sty) { gamma = -gamma; } @@ -4087,10 +4008,9 @@ /* Compute the new step. */ *stp = stpf; return 0; } -int timer_(double *ttime) -{ +int timer_(double* ttime) { *ttime = (double)clock() / CLOCKS_PER_SEC; return 0; }