lbfgsb 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.clang-format +149 -0
- data/.github/workflows/build.yml +3 -3
- data/CHANGELOG.md +20 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +2 -1
- data/Steepfile +20 -0
- data/ext/lbfgsb/lbfgsbext.c +34 -31
- data/ext/lbfgsb/lbfgsbext.h +2 -0
- data/ext/lbfgsb/src/blas.c +6 -40
- data/ext/lbfgsb/src/blas.h +4 -5
- data/ext/lbfgsb/src/lbfgsb.c +140 -220
- data/ext/lbfgsb/src/lbfgsb.h +68 -109
- data/ext/lbfgsb/src/linpack.c +55 -53
- data/ext/lbfgsb/src/linpack.h +2 -2
- data/lbfgsb.gemspec +9 -5
- data/lib/lbfgsb.rb +13 -3
- data/lib/lbfgsb/version.rb +1 -1
- data/sig/lbfgsb.rbs +31 -0
- data/sig/patch.rbs +11 -0
- metadata +14 -6
data/ext/lbfgsb/src/blas.h
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
|
4
4
|
#include <math.h>
|
5
5
|
|
6
|
-
extern
|
7
|
-
extern int
|
8
|
-
extern
|
9
|
-
extern
|
10
|
-
extern int dscal_(long *n, double *da, double *dx, long *incx);
|
6
|
+
extern int lbfgsb_rb_daxpy_(long* n, double* da, double* dx, long* incx, double* dy, long* incy);
|
7
|
+
extern int lbfgsb_rb_dcopy_(long* n, double* dx, long* incx, double* dy, long* incy);
|
8
|
+
extern double lbfgsb_rb_ddot_(long* n, double* dx, long* incx, double* dy, long* incy);
|
9
|
+
extern int lbfgsb_rb_dscal_(long* n, double* da, double* dx, long* incx);
|
11
10
|
|
12
11
|
#endif /* LBFGSB_RB_BLAS_H_ */
|
data/ext/lbfgsb/src/lbfgsb.c
CHANGED
@@ -44,9 +44,9 @@
|
|
44
44
|
* March 2011
|
45
45
|
*/
|
46
46
|
|
47
|
+
#include "lbfgsb.h"
|
47
48
|
#include "blas.h"
|
48
49
|
#include "linpack.h"
|
49
|
-
#include "lbfgsb.h"
|
50
50
|
|
51
51
|
static double c_b9 = 0.;
|
52
52
|
static long c__1 = 1;
|
@@ -232,12 +232,8 @@ static double c_b282 = .1;
|
|
232
232
|
* Ciyou Zhu
|
233
233
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
234
234
|
*/
|
235
|
-
int setulb_(long
|
236
|
-
|
237
|
-
double *factr, double *pgtol, double *wa, long *iwa,
|
238
|
-
char *task, long *iprint, char *csave, long *lsave,
|
239
|
-
long *isave, double *dsave)
|
240
|
-
{
|
235
|
+
int setulb_(long* n, long* m, double* x, double* l, double* u, long* nbd, double* f, double* g, double* factr, double* pgtol,
|
236
|
+
double* wa, long* iwa, char* task, long* iprint, char* csave, long* lsave, long* isave, double* dsave) {
|
241
237
|
long i__1;
|
242
238
|
|
243
239
|
static long ld, lr, lt, lz, lwa, lwn, lss, lxp, lws, lwt, lsy, lwy, lsnd;
|
@@ -287,11 +283,9 @@ int setulb_(long *n, long *m, double *x,
|
|
287
283
|
lt = isave[14];
|
288
284
|
lxp = isave[15];
|
289
285
|
lwa = isave[16];
|
290
|
-
mainlb_(n, m, &x[1], &l[1], &u[1], &nbd[1], f, &g[1], factr, pgtol, &wa[lws],
|
291
|
-
&wa[
|
292
|
-
&
|
293
|
-
&iwa[*n + 1], &iwa[(*n << 1) + 1], task, iprint, csave, &lsave[1],
|
294
|
-
&isave[22], &dsave[1]);
|
286
|
+
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],
|
287
|
+
&wa[lwn], &wa[lsnd], &wa[lz], &wa[lr], &wa[ld], &wa[lt], &wa[lxp], &wa[lwa], &iwa[1], &iwa[*n + 1],
|
288
|
+
&iwa[(*n << 1) + 1], task, iprint, csave, &lsave[1], &isave[22], &dsave[1]);
|
295
289
|
return 0;
|
296
290
|
}
|
297
291
|
|
@@ -471,20 +465,14 @@ int setulb_(long *n, long *m, double *x,
|
|
471
465
|
* Ciyou Zhu
|
472
466
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
473
467
|
*/
|
474
|
-
int mainlb_(long
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
long *iwhere, long *indx2, char *task, long *iprint,
|
481
|
-
char *csave, long *lsave, long *isave, double *dsave)
|
482
|
-
{
|
483
|
-
long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset,
|
484
|
-
ss_dim1, ss_offset, wt_dim1, wt_offset, wn_dim1, wn_offset,
|
485
|
-
snd_dim1, snd_offset, i__1;
|
468
|
+
int mainlb_(long* n, long* m, double* x, double* l, double* u, long* nbd, double* f, double* g, double* factr, double* pgtol,
|
469
|
+
double* ws, double* wy, double* sy, double* ss, double* wt, double* wn, double* snd, double* z__, double* r__,
|
470
|
+
double* d__, double* t, double* xp, double* wa, long* index, long* iwhere, long* indx2, char* task, long* iprint,
|
471
|
+
char* csave, long* lsave, long* isave, double* dsave) {
|
472
|
+
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,
|
473
|
+
snd_dim1, snd_offset, i__1;
|
486
474
|
double d__1, d__2;
|
487
|
-
FILE
|
475
|
+
FILE* itfptr;
|
488
476
|
static long i__, k;
|
489
477
|
static double gd, dr, rr, dtd;
|
490
478
|
static long col;
|
@@ -610,9 +598,8 @@ int mainlb_(long *n, long *m, double *x,
|
|
610
598
|
/* Check the input arguments for errors. */
|
611
599
|
errclb_(n, m, factr, &l[1], &u[1], &nbd[1], task, &info, &k);
|
612
600
|
if (strncmp(task, "ERROR", 5) == 0) {
|
613
|
-
prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol,
|
614
|
-
|
615
|
-
&stp, &xstep, &k, &cachyt, &sbtime, &lnscht);
|
601
|
+
prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, &nskip, &nact, &sbgnrm, &c_b9, &nseg, word,
|
602
|
+
&iback, &stp, &xstep, &k, &cachyt, &sbtime, &lnscht);
|
616
603
|
return 0;
|
617
604
|
}
|
618
605
|
prn1lb_(n, m, &l[1], &u[1], &x[1], iprint, &itfile, &epsmch);
|
@@ -673,8 +660,8 @@ int mainlb_(long *n, long *m, double *x,
|
|
673
660
|
if (strncmp(task, "STOP", 4) == 0) {
|
674
661
|
if (strncmp(task + 6, "CPU", 3) == 0) {
|
675
662
|
/* restore the previous iterate. */
|
676
|
-
|
677
|
-
|
663
|
+
lbfgsb_rb_dcopy_(n, &t[1], &c__1, &x[1], &c__1);
|
664
|
+
lbfgsb_rb_dcopy_(n, &r__[1], &c__1, &g[1], &c__1);
|
678
665
|
*f = fold;
|
679
666
|
}
|
680
667
|
goto L999;
|
@@ -707,9 +694,9 @@ L222:
|
|
707
694
|
}
|
708
695
|
iword = -1;
|
709
696
|
|
710
|
-
if (!
|
697
|
+
if (!cnstnd && col > 0) {
|
711
698
|
/* skip the search for GCP. */
|
712
|
-
|
699
|
+
lbfgsb_rb_dcopy_(n, &x[1], &c__1, &z__[1], &c__1);
|
713
700
|
wrk = updatd;
|
714
701
|
nseg = 0;
|
715
702
|
goto L333;
|
@@ -718,10 +705,9 @@ L222:
|
|
718
705
|
* Compute the Generalized Cauchy Point (GCP).
|
719
706
|
*/
|
720
707
|
timer_(&cpu1);
|
721
|
-
cauchy_(n, &x[1], &l[1], &u[1], &nbd[1], &g[1], &indx2[1], &iwhere[1], &t[1],
|
722
|
-
|
723
|
-
|
724
|
-
&wa[(*m << 2) + 1], &wa[*m * 6 + 1], &nseg, iprint, &sbgnrm, &info, &epsmch);
|
708
|
+
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],
|
709
|
+
&ws[ws_offset], &sy[sy_offset], &wt[wt_offset], &theta, &col, &head, &wa[1], &wa[(*m << 1) + 1], &wa[(*m << 2) + 1],
|
710
|
+
&wa[*m * 6 + 1], &nseg, iprint, &sbgnrm, &info, &epsmch);
|
725
711
|
if (info != 0) {
|
726
712
|
/* singular triangular system detected; refresh the lbfgs memory. */
|
727
713
|
if (*iprint >= 1) {
|
@@ -762,9 +748,8 @@ L333:
|
|
762
748
|
/* where E = [-I 0] */
|
763
749
|
/* [ 0 I] */
|
764
750
|
if (wrk) {
|
765
|
-
formk_(n, &nfree, &index[1], &nenter, &ileave, &indx2[1], &iupdat, &updatd,
|
766
|
-
|
767
|
-
&sy[sy_offset], &theta, &col, &head, &info);
|
751
|
+
formk_(n, &nfree, &index[1], &nenter, &ileave, &indx2[1], &iupdat, &updatd, &wn[wn_offset], &snd[snd_offset], m,
|
752
|
+
&ws[ws_offset], &wy[wy_offset], &sy[sy_offset], &theta, &col, &head, &info);
|
768
753
|
}
|
769
754
|
if (info != 0) {
|
770
755
|
/* nonpositive definiteness in Cholesky factorization; */
|
@@ -786,16 +771,14 @@ L333:
|
|
786
771
|
}
|
787
772
|
/* compute r=-Z'B(xcp-xk)-Z'g (using wa(2m+1)=W'(xcp-x) */
|
788
773
|
/* from 'cauchy'). */
|
789
|
-
cmprlb_(n, m, &x[1], &g[1], &ws[ws_offset], &wy[wy_offset], &sy[sy_offset],
|
790
|
-
|
791
|
-
&head, &nfree, &cnstnd, &info);
|
774
|
+
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],
|
775
|
+
&index[1], &theta, &col, &head, &nfree, &cnstnd, &info);
|
792
776
|
if (info != 0) {
|
793
777
|
goto L444;
|
794
778
|
}
|
795
779
|
/* jlm-jn call the direct method. */
|
796
|
-
subsm_(n, m, &nfree, &index[1], &l[1], &u[1], &nbd[1], &z__[1], &r__[1], &xp[1],
|
797
|
-
|
798
|
-
&head, &iword, &wa[1], &wn[wn_offset], iprint, &info);
|
780
|
+
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,
|
781
|
+
&x[1], &g[1], &col, &head, &iword, &wa[1], &wn[wn_offset], iprint, &info);
|
799
782
|
L444:
|
800
783
|
if (info != 0) {
|
801
784
|
/* singular triangular system detected; */
|
@@ -828,14 +811,12 @@ L555:
|
|
828
811
|
}
|
829
812
|
timer_(&cpu1);
|
830
813
|
L666:
|
831
|
-
lnsrlb_(n, &l[1], &u[1], &nbd[1], &x[1], f, &fold, &gd, &gdold, &g[1],
|
832
|
-
|
833
|
-
&stpmx, &iter, &ifun, &iback, &nfgv, &info, task, &boxed, &cnstnd,
|
834
|
-
csave, &isave[22], &dsave[17]);
|
814
|
+
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,
|
815
|
+
&xstep, &stpmx, &iter, &ifun, &iback, &nfgv, &info, task, &boxed, &cnstnd, csave, &isave[22], &dsave[17]);
|
835
816
|
if (info != 0 || iback >= 20) {
|
836
817
|
/* restore the previous iterate. */
|
837
|
-
|
838
|
-
|
818
|
+
lbfgsb_rb_dcopy_(n, &t[1], &c__1, &x[1], &c__1);
|
819
|
+
lbfgsb_rb_dcopy_(n, &r__[1], &c__1, &g[1], &c__1);
|
839
820
|
*f = fold;
|
840
821
|
if (col == 0) {
|
841
822
|
/* abnormal termination. */
|
@@ -881,8 +862,7 @@ L666:
|
|
881
862
|
/* Compute the infinity norm of the projected (-)gradient. */
|
882
863
|
projgr_(n, &l[1], &u[1], &nbd[1], &x[1], &g[1], &sbgnrm);
|
883
864
|
/* Print iteration information. */
|
884
|
-
prn2lb_(n, &x[1], f, &g[1], iprint, &itfile, &iter, &nfgv, &nact,
|
885
|
-
&sbgnrm, &nseg, word, &iword, &iback, &stp, &xstep);
|
865
|
+
prn2lb_(n, &x[1], f, &g[1], iprint, &itfile, &iter, &nfgv, &nact, &sbgnrm, &nseg, word, &iword, &iback, &stp, &xstep);
|
886
866
|
goto L1000;
|
887
867
|
}
|
888
868
|
L777:
|
@@ -910,13 +890,13 @@ L777:
|
|
910
890
|
for (i__ = 1; i__ <= i__1; ++i__) {
|
911
891
|
r__[i__] = g[i__] - r__[i__];
|
912
892
|
}
|
913
|
-
rr =
|
893
|
+
rr = lbfgsb_rb_ddot_(n, &r__[1], &c__1, &r__[1], &c__1);
|
914
894
|
if (stp == 1.) {
|
915
895
|
dr = gd - gdold;
|
916
896
|
ddum = -gdold;
|
917
897
|
} else {
|
918
898
|
dr = (gd - gdold) * stp;
|
919
|
-
|
899
|
+
lbfgsb_rb_dscal_(n, &stp, &d__[1], &c__1);
|
920
900
|
ddum = -gdold * stp;
|
921
901
|
}
|
922
902
|
if (dr <= epsmch * ddum) {
|
@@ -934,9 +914,8 @@ L777:
|
|
934
914
|
updatd = TRUE_;
|
935
915
|
++iupdat;
|
936
916
|
/* Update matrices WS and WY and form the middle matrix in B. */
|
937
|
-
matupd_(n, m, &ws[ws_offset], &wy[wy_offset], &sy[sy_offset],
|
938
|
-
|
939
|
-
&theta, &rr, &dr, &stp, &dtd);
|
917
|
+
matupd_(n, m, &ws[ws_offset], &wy[wy_offset], &sy[sy_offset], &ss[ss_offset], &d__[1], &r__[1], &itail, &iupdat, &col, &head,
|
918
|
+
&theta, &rr, &dr, &stp, &dtd);
|
940
919
|
/* Form the upper half of the pds T = theta*SS + L*D^(-1)*L'; */
|
941
920
|
/* Store T in the upper triangular of the array wt; */
|
942
921
|
/* Cholesky factorize T to J*J' with */
|
@@ -967,9 +946,8 @@ L888:
|
|
967
946
|
L999:
|
968
947
|
timer_(&time2);
|
969
948
|
time = time2 - time1;
|
970
|
-
prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol,
|
971
|
-
|
972
|
-
&k, &cachyt, &sbtime, &lnscht);
|
949
|
+
prn3lb_(n, &x[1], f, task, iprint, &info, &itfile, &iter, &nfgv, &nintol, &nskip, &nact, &sbgnrm, &time, &nseg, word, &iback,
|
950
|
+
&stp, &xstep, &k, &cachyt, &sbtime, &lnscht);
|
973
951
|
L1000:
|
974
952
|
/* Save local variables. */
|
975
953
|
lsave[1] = prjctd;
|
@@ -1035,10 +1013,8 @@ L1000:
|
|
1035
1013
|
* Ciyou Zhu
|
1036
1014
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
1037
1015
|
*/
|
1038
|
-
int active_(long
|
1039
|
-
|
1040
|
-
long *prjctd, long *cnstnd, long *boxed)
|
1041
|
-
{
|
1016
|
+
int active_(long* n, double* l, double* u, long* nbd, double* x, long* iwhere, long* iprint, long* prjctd, long* cnstnd,
|
1017
|
+
long* boxed) {
|
1042
1018
|
long i__1;
|
1043
1019
|
static long i__, nbdd;
|
1044
1020
|
--iwhere;
|
@@ -1080,7 +1056,7 @@ int active_(long *n, double *l, double *u,
|
|
1080
1056
|
if (nbd[i__] == 0) {
|
1081
1057
|
/* this variable is always free */
|
1082
1058
|
iwhere[i__] = -1;
|
1083
|
-
|
1059
|
+
/* otherwise set x(i)=mid(x(i), u(i), l(i)). */
|
1084
1060
|
} else {
|
1085
1061
|
*cnstnd = TRUE_;
|
1086
1062
|
if (nbd[i__] == 2 && u[i__] - l[i__] <= 0.) {
|
@@ -1095,7 +1071,7 @@ int active_(long *n, double *l, double *u,
|
|
1095
1071
|
if (*prjctd) {
|
1096
1072
|
fprintf(stdout, " The initial X is infeasible. Restart with its projection.\n");
|
1097
1073
|
}
|
1098
|
-
if (!
|
1074
|
+
if (!(*cnstnd)) {
|
1099
1075
|
fprintf(stdout, " This problem is unconstrained.\n");
|
1100
1076
|
}
|
1101
1077
|
}
|
@@ -1159,9 +1135,7 @@ int active_(long *n, double *l, double *u,
|
|
1159
1135
|
* Ciyou Zhu
|
1160
1136
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
1161
1137
|
*/
|
1162
|
-
int bmv_(long
|
1163
|
-
*col, double *v, double *p, long *info)
|
1164
|
-
{
|
1138
|
+
int bmv_(long* m, double* sy, double* wt, long* col, double* v, double* p, long* info) {
|
1165
1139
|
long sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2;
|
1166
1140
|
static long i__, k, i2;
|
1167
1141
|
static double sum;
|
@@ -1193,7 +1167,7 @@ int bmv_(long *m, double *sy, double *wt, long
|
|
1193
1167
|
p[i2] = v[i2] + sum;
|
1194
1168
|
}
|
1195
1169
|
/* Solve the triangular system */
|
1196
|
-
|
1170
|
+
lbfgsb_rb_dtrsl_(&wt[wt_offset], m, col, &p[*col + 1], &c__11, info);
|
1197
1171
|
if (*info != 0) {
|
1198
1172
|
return 0;
|
1199
1173
|
}
|
@@ -1205,7 +1179,7 @@ int bmv_(long *m, double *sy, double *wt, long
|
|
1205
1179
|
/* PART II: solve [ -D^(1/2) D^(-1/2)*L' ] [ p1 ] = [ p1 ] */
|
1206
1180
|
/* [ 0 J' ] [ p2 ] [ p2 ]. */
|
1207
1181
|
/* solve J^Tp2=p2. */
|
1208
|
-
|
1182
|
+
lbfgsb_rb_dtrsl_(&wt[wt_offset], m, col, &p[*col + 1], &c__1, info);
|
1209
1183
|
if (*info != 0) {
|
1210
1184
|
return 0;
|
1211
1185
|
}
|
@@ -1400,14 +1374,10 @@ int bmv_(long *m, double *sy, double *wt, long
|
|
1400
1374
|
* Ciyou Zhu
|
1401
1375
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
1402
1376
|
*/
|
1403
|
-
int cauchy_(long
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
double *theta, long *col, long *head, double *p,
|
1408
|
-
double *c__, double *wbp, double *v, long *nseg,
|
1409
|
-
long *iprint, double *sbgnrm, long *info, double *epsmch)
|
1410
|
-
{
|
1377
|
+
int cauchy_(long* n, double* x, double* l, double* u, long* nbd, double* g, long* iorder, long* iwhere, double* t, double* d__,
|
1378
|
+
double* xcp, long* m, double* wy, double* ws, double* sy, double* wt, double* theta, long* col, long* head,
|
1379
|
+
double* p, double* c__, double* wbp, double* v, long* nseg, long* iprint, double* sbgnrm, long* info,
|
1380
|
+
double* epsmch) {
|
1411
1381
|
long wy_dim1, wy_offset, ws_dim1, ws_offset, sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2;
|
1412
1382
|
double d__1;
|
1413
1383
|
static long i__, j;
|
@@ -1463,7 +1433,7 @@ int cauchy_(long *n, double *x, double *l,
|
|
1463
1433
|
if (*iprint >= 0) {
|
1464
1434
|
fprintf(stdout, " Subgnorm = 0. GCP = X.\n");
|
1465
1435
|
}
|
1466
|
-
|
1436
|
+
lbfgsb_rb_dcopy_(n, &x[1], &c__1, &xcp[1], &c__1);
|
1467
1437
|
return 0;
|
1468
1438
|
}
|
1469
1439
|
bnded = TRUE_;
|
@@ -1562,10 +1532,10 @@ int cauchy_(long *n, double *x, double *l,
|
|
1562
1532
|
/* The smallest of the nbreak breakpoints is in t(ibkmin)=bkmin. */
|
1563
1533
|
if (*theta != 1.) {
|
1564
1534
|
/* complete the initialization of p for theta not= one. */
|
1565
|
-
|
1535
|
+
lbfgsb_rb_dscal_(col, theta, &p[*col + 1], &c__1);
|
1566
1536
|
}
|
1567
1537
|
/* Initialize GCP xcp = x. */
|
1568
|
-
|
1538
|
+
lbfgsb_rb_dcopy_(n, &x[1], &c__1, &xcp[1], &c__1);
|
1569
1539
|
if (nbreak == 0 && nfree == *n + 1) {
|
1570
1540
|
/* is a zero vector, return with the initial xcp as GCP. */
|
1571
1541
|
if (*iprint > 100) {
|
@@ -1596,7 +1566,7 @@ int cauchy_(long *n, double *x, double *l,
|
|
1596
1566
|
if (*info != 0) {
|
1597
1567
|
return 0;
|
1598
1568
|
}
|
1599
|
-
f2 -=
|
1569
|
+
f2 -= lbfgsb_rb_ddot_(&col2, &v[1], &c__1, &p[1], &c__1);
|
1600
1570
|
}
|
1601
1571
|
dtm = -f1 / f2;
|
1602
1572
|
tsum = 0.;
|
@@ -1685,7 +1655,7 @@ L777:
|
|
1685
1655
|
f2 -= *theta * dibp2;
|
1686
1656
|
if (*col > 0) {
|
1687
1657
|
/* update c = c + dt*p. */
|
1688
|
-
|
1658
|
+
lbfgsb_rb_daxpy_(&col2, &dt, &p[1], &c__1, &c__[1], &c__1);
|
1689
1659
|
/* choose wbp, */
|
1690
1660
|
/* the row of W corresponding to the breakpoint encountered. */
|
1691
1661
|
pointr = *head;
|
@@ -1700,12 +1670,12 @@ L777:
|
|
1700
1670
|
if (*info != 0) {
|
1701
1671
|
return 0;
|
1702
1672
|
}
|
1703
|
-
wmc =
|
1704
|
-
wmp =
|
1705
|
-
wmw =
|
1673
|
+
wmc = lbfgsb_rb_ddot_(&col2, &c__[1], &c__1, &v[1], &c__1);
|
1674
|
+
wmp = lbfgsb_rb_ddot_(&col2, &p[1], &c__1, &v[1], &c__1);
|
1675
|
+
wmw = lbfgsb_rb_ddot_(&col2, &wbp[1], &c__1, &v[1], &c__1);
|
1706
1676
|
/* update p = p - dibp*wbp. */
|
1707
1677
|
d__1 = -dibp;
|
1708
|
-
|
1678
|
+
lbfgsb_rb_daxpy_(&col2, &d__1, &wbp[1], &c__1, &p[1], &c__1);
|
1709
1679
|
/* complete updating f1 and f2 while col > 0. */
|
1710
1680
|
f1 += dibp * wmc;
|
1711
1681
|
f2 = f2 + dibp * 2. * wmp - dibp2 * wmw;
|
@@ -1737,12 +1707,12 @@ L888:
|
|
1737
1707
|
tsum += dtm;
|
1738
1708
|
/* Move free variables (i.e., the ones w/o breakpoints) and */
|
1739
1709
|
/* the variables whose breakpoints haven't been reached. */
|
1740
|
-
|
1710
|
+
lbfgsb_rb_daxpy_(n, &tsum, &d__[1], &c__1, &xcp[1], &c__1);
|
1741
1711
|
L999:
|
1742
1712
|
/* Update c = c + dtm*p = W'(x^c - x) */
|
1743
1713
|
/* which will be used in computing r = Z'(B(x^c - x) + g). */
|
1744
1714
|
if (*col > 0) {
|
1745
|
-
|
1715
|
+
lbfgsb_rb_daxpy_(&col2, &dtm, &p[1], &c__1, &c__[1], &c__1);
|
1746
1716
|
}
|
1747
1717
|
if (*iprint > 100) {
|
1748
1718
|
fprintf(stdout, "Cauchy X = \n");
|
@@ -1782,12 +1752,8 @@ L999:
|
|
1782
1752
|
* Ciyou Zhu
|
1783
1753
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
1784
1754
|
*/
|
1785
|
-
int cmprlb_(long
|
1786
|
-
|
1787
|
-
double *wt, double *z__, double *r__, double *wa,
|
1788
|
-
long *index, double *theta, long *col, long *head,
|
1789
|
-
long *nfree, long *cnstnd, long *info)
|
1790
|
-
{
|
1755
|
+
int cmprlb_(long* n, long* m, double* x, double* g, double* ws, double* wy, double* sy, double* wt, double* z__, double* r__,
|
1756
|
+
double* wa, long* index, double* theta, long* col, long* head, long* nfree, long* cnstnd, long* info) {
|
1791
1757
|
long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2;
|
1792
1758
|
static long i__, j, k;
|
1793
1759
|
static double a1, a2;
|
@@ -1812,7 +1778,7 @@ int cmprlb_(long *n, long *m, double *x,
|
|
1812
1778
|
ws_offset = 1 + ws_dim1;
|
1813
1779
|
ws -= ws_offset;
|
1814
1780
|
|
1815
|
-
if (!
|
1781
|
+
if (!(*cnstnd) && *col > 0) {
|
1816
1782
|
i__1 = *n;
|
1817
1783
|
for (i__ = 1; i__ <= i__1; ++i__) {
|
1818
1784
|
r__[i__] = -g[i__];
|
@@ -1858,9 +1824,7 @@ int cmprlb_(long *n, long *m, double *x,
|
|
1858
1824
|
* Ciyou Zhu
|
1859
1825
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
1860
1826
|
*/
|
1861
|
-
int errclb_(long
|
1862
|
-
double *l, double *u, long *nbd, char *task, long *info, long *k)
|
1863
|
-
{
|
1827
|
+
int errclb_(long* n, long* m, double* factr, double* l, double* u, long* nbd, char* task, long* info, long* k) {
|
1864
1828
|
long i__1;
|
1865
1829
|
static long i__;
|
1866
1830
|
--nbd;
|
@@ -2017,14 +1981,9 @@ int errclb_(long *n, long *m, double *factr,
|
|
2017
1981
|
* Ciyou Zhu
|
2018
1982
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2019
1983
|
*/
|
2020
|
-
int formk_(long
|
2021
|
-
|
2022
|
-
|
2023
|
-
double *wy, double *sy, double *theta, long *col,
|
2024
|
-
long *head, long *info)
|
2025
|
-
{
|
2026
|
-
long wn_dim1, wn_offset, wn1_dim1, wn1_offset, ws_dim1, ws_offset,
|
2027
|
-
wy_dim1, wy_offset, sy_dim1, sy_offset, i__1, i__2, i__3;
|
1984
|
+
int formk_(long* n, long* nsub, long* ind, long* nenter, long* ileave, long* indx2, long* iupdat, long* updatd, double* wn,
|
1985
|
+
double* wn1, long* m, double* ws, double* wy, double* sy, double* theta, long* col, long* head, long* info) {
|
1986
|
+
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;
|
2028
1987
|
static long i__, k, k1, m2, is, js, iy, jy, is1, js1, col2, dend, pend;
|
2029
1988
|
static long upcl;
|
2030
1989
|
static double temp1, temp2, temp3, temp4;
|
@@ -2060,11 +2019,11 @@ int formk_(long *n, long *nsub, long *ind, long *nenter,
|
|
2060
2019
|
for (jy = 1; jy <= i__1; ++jy) {
|
2061
2020
|
js = *m + jy;
|
2062
2021
|
i__2 = *m - jy;
|
2063
|
-
|
2022
|
+
lbfgsb_rb_dcopy_(&i__2, &wn1[jy + 1 + (jy + 1) * wn1_dim1], &c__1, &wn1[jy + jy * wn1_dim1], &c__1);
|
2064
2023
|
i__2 = *m - jy;
|
2065
|
-
|
2024
|
+
lbfgsb_rb_dcopy_(&i__2, &wn1[js + 1 + (js + 1) * wn1_dim1], &c__1, &wn1[js + js * wn1_dim1], &c__1);
|
2066
2025
|
i__2 = *m - 1;
|
2067
|
-
|
2026
|
+
lbfgsb_rb_dcopy_(&i__2, &wn1[*m + 2 + (jy + 1) * wn1_dim1], &c__1, &wn1[*m + 1 + jy * wn1_dim1], &c__1);
|
2068
2027
|
}
|
2069
2028
|
}
|
2070
2029
|
/* put new rows in blocks (1,1), (2,1) and (2,2). */
|
@@ -2215,7 +2174,7 @@ int formk_(long *n, long *nsub, long *ind, long *nenter,
|
|
2215
2174
|
/* [(-L_a +R_z)L'^-1 S'AA'S*theta ] */
|
2216
2175
|
/* first Cholesky factor (1,1) block of wn to get LL' */
|
2217
2176
|
/* with L' stored in the upper triangle of wn. */
|
2218
|
-
|
2177
|
+
lbfgsb_rb_dpofa_(&wn[wn_offset], &m2, col, info);
|
2219
2178
|
if (*info != 0) {
|
2220
2179
|
*info = -1;
|
2221
2180
|
return 0;
|
@@ -2224,7 +2183,7 @@ int formk_(long *n, long *nsub, long *ind, long *nenter,
|
|
2224
2183
|
col2 = *col << 1;
|
2225
2184
|
i__1 = col2;
|
2226
2185
|
for (js = *col + 1; js <= i__1; ++js) {
|
2227
|
-
|
2186
|
+
lbfgsb_rb_dtrsl_(&wn[wn_offset], &m2, col, &wn[js * wn_dim1 + 1], &c__11, info);
|
2228
2187
|
}
|
2229
2188
|
/* Form S'AA'S*theta + (L^-1(-L_a'+R_z'))'L^-1(-L_a'+R_z') in the */
|
2230
2189
|
/* upper triangle of (2,2) block of wn. */
|
@@ -2232,11 +2191,11 @@ int formk_(long *n, long *nsub, long *ind, long *nenter,
|
|
2232
2191
|
for (is = *col + 1; is <= i__1; ++is) {
|
2233
2192
|
i__2 = col2;
|
2234
2193
|
for (js = is; js <= i__2; ++js) {
|
2235
|
-
wn[is + js * wn_dim1] +=
|
2194
|
+
wn[is + js * wn_dim1] += lbfgsb_rb_ddot_(col, &wn[is * wn_dim1 + 1], &c__1, &wn[js * wn_dim1 + 1], &c__1);
|
2236
2195
|
}
|
2237
2196
|
}
|
2238
2197
|
/* Cholesky factorization of (2,2) block of wn. */
|
2239
|
-
|
2198
|
+
lbfgsb_rb_dpofa_(&wn[*col + 1 + (*col + 1) * wn_dim1], &m2, col, info);
|
2240
2199
|
if (*info != 0) {
|
2241
2200
|
*info = -2;
|
2242
2201
|
return 0;
|
@@ -2265,9 +2224,7 @@ int formk_(long *n, long *nsub, long *ind, long *nenter,
|
|
2265
2224
|
* Ciyou Zhu
|
2266
2225
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2267
2226
|
*/
|
2268
|
-
int formt_(long
|
2269
|
-
double *ss, long *col, double *theta, long *info)
|
2270
|
-
{
|
2227
|
+
int formt_(long* m, double* wt, double* sy, double* ss, long* col, double* theta, long* info) {
|
2271
2228
|
long wt_dim1, wt_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, i__1, i__2, i__3;
|
2272
2229
|
static long i__, j, k, k1;
|
2273
2230
|
static double ddum;
|
@@ -2303,7 +2260,7 @@ int formt_(long *m, double *wt, double *sy,
|
|
2303
2260
|
}
|
2304
2261
|
/* Cholesky factorize T to J*J' with */
|
2305
2262
|
/* J' stored in the upper triangle of wt. */
|
2306
|
-
|
2263
|
+
lbfgsb_rb_dpofa_(&wt[wt_offset], m, col, info);
|
2307
2264
|
if (*info != 0) {
|
2308
2265
|
*info = -3;
|
2309
2266
|
}
|
@@ -2343,11 +2300,8 @@ int formt_(long *m, double *wt, double *sy,
|
|
2343
2300
|
* Ciyou Zhu
|
2344
2301
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2345
2302
|
*/
|
2346
|
-
int freev_(long
|
2347
|
-
|
2348
|
-
long *wrk, long *updatd, long *cnstnd, long *iprint,
|
2349
|
-
long *iter)
|
2350
|
-
{
|
2303
|
+
int freev_(long* n, long* nfree, long* index, long* nenter, long* ileave, long* indx2, long* iwhere, long* wrk, long* updatd,
|
2304
|
+
long* cnstnd, long* iprint, long* iter) {
|
2351
2305
|
long i__1;
|
2352
2306
|
static long i__, k, iact;
|
2353
2307
|
|
@@ -2385,7 +2339,7 @@ int freev_(long *n, long *nfree, long *index,
|
|
2385
2339
|
}
|
2386
2340
|
if (*iprint >= 99) {
|
2387
2341
|
i__1 = *n + 1 - *ileave;
|
2388
|
-
fprintf(stdout,
|
2342
|
+
fprintf(stdout, " %2ld variables leave; %2ld variables enter\n", i__1, *nenter);
|
2389
2343
|
}
|
2390
2344
|
}
|
2391
2345
|
*wrk = *ileave < *n + 1 || *nenter > 0 || *updatd;
|
@@ -2448,8 +2402,7 @@ int freev_(long *n, long *nfree, long *index,
|
|
2448
2402
|
* Ciyou Zhu
|
2449
2403
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2450
2404
|
*/
|
2451
|
-
int hpsolb_(long
|
2452
|
-
{
|
2405
|
+
int hpsolb_(long* n, double* t, long* iorder, long* iheap) {
|
2453
2406
|
long i__1;
|
2454
2407
|
static long i__, j, k;
|
2455
2408
|
static double out, ddum;
|
@@ -2466,7 +2419,7 @@ int hpsolb_(long *n, double *t, long *iorder, long *iheap)
|
|
2466
2419
|
indxin = iorder[k];
|
2467
2420
|
/* Add ddum to the heap. */
|
2468
2421
|
i__ = k;
|
2469
|
-
L10:
|
2422
|
+
L10:
|
2470
2423
|
if (i__ > 1) {
|
2471
2424
|
j = i__ / 2;
|
2472
2425
|
if (ddum < t[j]) {
|
@@ -2490,7 +2443,7 @@ L10:
|
|
2490
2443
|
ddum = t[*n];
|
2491
2444
|
indxin = iorder[*n];
|
2492
2445
|
/* Restore the heap */
|
2493
|
-
L30:
|
2446
|
+
L30:
|
2494
2447
|
j = i__ + i__;
|
2495
2448
|
if (j <= *n - 1) {
|
2496
2449
|
if (t[j + 1] < t[j]) {
|
@@ -2534,15 +2487,10 @@ L30:
|
|
2534
2487
|
* Ciyou Zhu
|
2535
2488
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2536
2489
|
*/
|
2537
|
-
int lnsrlb_(long
|
2538
|
-
|
2539
|
-
|
2540
|
-
|
2541
|
-
double *dnorm, double *dtd, double *xstep, double *stpmx,
|
2542
|
-
long *iter, long *ifun, long *iback, long *nfgv,
|
2543
|
-
long *info, char *task, long *boxed, long *cnstnd,
|
2544
|
-
char *csave, long *isave, double *dsave)
|
2545
|
-
{
|
2490
|
+
int lnsrlb_(long* n, double* l, double* u, long* nbd, double* x, double* f, double* fold, double* gd, double* gdold, double* g,
|
2491
|
+
double* d__, double* r__, double* t, double* z__, double* stp, double* dnorm, double* dtd, double* xstep,
|
2492
|
+
double* stpmx, long* iter, long* ifun, long* iback, long* nfgv, long* info, char* task, long* boxed, long* cnstnd,
|
2493
|
+
char* csave, long* isave, double* dsave) {
|
2546
2494
|
long i__1;
|
2547
2495
|
double d__1;
|
2548
2496
|
static long i__;
|
@@ -2563,7 +2511,7 @@ int lnsrlb_(long *n, double *l, double *u,
|
|
2563
2511
|
if (strncmp(task, "FG_LN", 5) == 0) {
|
2564
2512
|
goto L556;
|
2565
2513
|
}
|
2566
|
-
*dtd =
|
2514
|
+
*dtd = lbfgsb_rb_ddot_(n, &d__[1], &c__1, &d__[1], &c__1);
|
2567
2515
|
*dnorm = sqrt(*dtd);
|
2568
2516
|
/* Determine the maximum step length. */
|
2569
2517
|
*stpmx = 1e10;
|
@@ -2594,20 +2542,20 @@ int lnsrlb_(long *n, double *l, double *u,
|
|
2594
2542
|
}
|
2595
2543
|
}
|
2596
2544
|
}
|
2597
|
-
if (*iter == 0 && !
|
2545
|
+
if (*iter == 0 && !(*boxed)) {
|
2598
2546
|
d__1 = 1. / *dnorm;
|
2599
2547
|
*stp = d__1 <= *stpmx ? d__1 : *stpmx;
|
2600
2548
|
} else {
|
2601
2549
|
*stp = 1.;
|
2602
2550
|
}
|
2603
|
-
|
2604
|
-
|
2551
|
+
lbfgsb_rb_dcopy_(n, &x[1], &c__1, &t[1], &c__1);
|
2552
|
+
lbfgsb_rb_dcopy_(n, &g[1], &c__1, &r__[1], &c__1);
|
2605
2553
|
*fold = *f;
|
2606
2554
|
*ifun = 0;
|
2607
2555
|
*iback = 0;
|
2608
2556
|
strcpy(csave, "START");
|
2609
2557
|
L556:
|
2610
|
-
*gd =
|
2558
|
+
*gd = lbfgsb_rb_ddot_(n, &g[1], &c__1, &d__[1], &c__1);
|
2611
2559
|
if (*ifun == 0) {
|
2612
2560
|
*gdold = *gd;
|
2613
2561
|
if (*gd >= 0.) {
|
@@ -2626,7 +2574,7 @@ L556:
|
|
2626
2574
|
++(*nfgv);
|
2627
2575
|
*iback = *ifun - 1;
|
2628
2576
|
if (*stp == 1.) {
|
2629
|
-
|
2577
|
+
lbfgsb_rb_dcopy_(n, &z__[1], &c__1, &x[1], &c__1);
|
2630
2578
|
} else {
|
2631
2579
|
i__1 = *n;
|
2632
2580
|
for (i__ = 1; i__ <= i__1; ++i__) {
|
@@ -2658,12 +2606,8 @@ L556:
|
|
2658
2606
|
* Ciyou Zhu
|
2659
2607
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2660
2608
|
*/
|
2661
|
-
int matupd_(long
|
2662
|
-
|
2663
|
-
double *r__, long *itail, long *iupdat, long *col,
|
2664
|
-
long *head, double *theta, double *rr, double *dr,
|
2665
|
-
double *stp, double *dtd)
|
2666
|
-
{
|
2609
|
+
int matupd_(long* n, long* m, double* ws, double* wy, double* sy, double* ss, double* d__, double* r__, long* itail,
|
2610
|
+
long* iupdat, long* col, long* head, double* theta, double* rr, double* dr, double* stp, double* dtd) {
|
2667
2611
|
long ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, i__1, i__2;
|
2668
2612
|
static long j;
|
2669
2613
|
static long pointr;
|
@@ -2693,8 +2637,8 @@ int matupd_(long *n, long *m, double *ws,
|
|
2693
2637
|
*head = *head % *m + 1;
|
2694
2638
|
}
|
2695
2639
|
/* Update matrices WS and WY. */
|
2696
|
-
|
2697
|
-
|
2640
|
+
lbfgsb_rb_dcopy_(n, &d__[1], &c__1, &ws[*itail * ws_dim1 + 1], &c__1);
|
2641
|
+
lbfgsb_rb_dcopy_(n, &r__[1], &c__1, &wy[*itail * wy_dim1 + 1], &c__1);
|
2698
2642
|
/* Set theta=yy/ys. */
|
2699
2643
|
*theta = *rr / *dr;
|
2700
2644
|
/* Form the middle matrix in B. */
|
@@ -2704,9 +2648,9 @@ int matupd_(long *n, long *m, double *ws,
|
|
2704
2648
|
/* move old information */
|
2705
2649
|
i__1 = *col - 1;
|
2706
2650
|
for (j = 1; j <= i__1; ++j) {
|
2707
|
-
|
2651
|
+
lbfgsb_rb_dcopy_(&j, &ss[(j + 1) * ss_dim1 + 2], &c__1, &ss[j * ss_dim1 + 1], &c__1);
|
2708
2652
|
i__2 = *col - j;
|
2709
|
-
|
2653
|
+
lbfgsb_rb_dcopy_(&i__2, &sy[j + 1 + (j + 1) * sy_dim1], &c__1, &sy[j + j * sy_dim1], &c__1);
|
2710
2654
|
}
|
2711
2655
|
}
|
2712
2656
|
/* add new information: the last row of SY */
|
@@ -2714,8 +2658,8 @@ int matupd_(long *n, long *m, double *ws,
|
|
2714
2658
|
pointr = *head;
|
2715
2659
|
i__1 = *col - 1;
|
2716
2660
|
for (j = 1; j <= i__1; ++j) {
|
2717
|
-
sy[*col + j * sy_dim1] =
|
2718
|
-
ss[j + *col * ss_dim1] =
|
2661
|
+
sy[*col + j * sy_dim1] = lbfgsb_rb_ddot_(n, &d__[1], &c__1, &wy[pointr * wy_dim1 + 1], &c__1);
|
2662
|
+
ss[j + *col * ss_dim1] = lbfgsb_rb_ddot_(n, &ws[pointr * ws_dim1 + 1], &c__1, &d__[1], &c__1);
|
2719
2663
|
pointr = pointr % *m + 1;
|
2720
2664
|
}
|
2721
2665
|
if (*stp == 1.) {
|
@@ -2743,12 +2687,9 @@ int matupd_(long *n, long *m, double *ws,
|
|
2743
2687
|
* Ciyou Zhu
|
2744
2688
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2745
2689
|
*/
|
2746
|
-
int prn1lb_(long
|
2747
|
-
double *u, double *x, long *iprint, long *itfile,
|
2748
|
-
double *epsmch)
|
2749
|
-
{
|
2690
|
+
int prn1lb_(long* n, long* m, double* l, double* u, double* x, long* iprint, long* itfile, double* epsmch) {
|
2750
2691
|
long i__1;
|
2751
|
-
FILE
|
2692
|
+
FILE* itfptr;
|
2752
2693
|
static long i__;
|
2753
2694
|
|
2754
2695
|
--x;
|
@@ -2840,14 +2781,11 @@ int prn1lb_(long *n, long *m, double *l,
|
|
2840
2781
|
* Ciyou Zhu
|
2841
2782
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2842
2783
|
*/
|
2843
|
-
int prn2lb_(long
|
2844
|
-
|
2845
|
-
long *nfgv, long *nact, double *sbgnrm, long *nseg, char*word,
|
2846
|
-
long *iword, long *iback, double *stp, double *xstep)
|
2847
|
-
{
|
2784
|
+
int prn2lb_(long* n, double* x, double* f, double* g, long* iprint, long* itfile, long* iter, long* nfgv, long* nact,
|
2785
|
+
double* sbgnrm, long* nseg, char* word, long* iword, long* iback, double* stp, double* xstep) {
|
2848
2786
|
long i__1;
|
2849
2787
|
static long i__, imod;
|
2850
|
-
FILE
|
2788
|
+
FILE* itfptr;
|
2851
2789
|
--g;
|
2852
2790
|
--x;
|
2853
2791
|
|
@@ -2890,8 +2828,8 @@ int prn2lb_(long *n, double *x, double *f,
|
|
2890
2828
|
}
|
2891
2829
|
if (*iprint >= 1) {
|
2892
2830
|
itfptr = fopen("iterate.dat", "a");
|
2893
|
-
fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E %10.3E %10.3E\n",
|
2894
|
-
|
2831
|
+
fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E %10.3E %10.3E\n", *iter, *nfgv, *nseg, *nact, word, *iback,
|
2832
|
+
*stp, *xstep, *sbgnrm, *f);
|
2895
2833
|
fclose(itfptr);
|
2896
2834
|
}
|
2897
2835
|
return 0;
|
@@ -2913,15 +2851,11 @@ int prn2lb_(long *n, double *x, double *f,
|
|
2913
2851
|
* Ciyou Zhu
|
2914
2852
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
2915
2853
|
*/
|
2916
|
-
int prn3lb_(long
|
2917
|
-
|
2918
|
-
|
2919
|
-
double *sbgnrm, double *time, long *nseg, char *word,
|
2920
|
-
long *iback, double *stp, double *xstep, long *k,
|
2921
|
-
double *cachyt, double *sbtime, double *lnscht)
|
2922
|
-
{
|
2854
|
+
int prn3lb_(long* n, double* x, double* f, char* task, long* iprint, long* info, long* itfile, long* iter, long* nfgv,
|
2855
|
+
long* nintol, long* nskip, long* nact, double* sbgnrm, double* time, long* nseg, char* word, long* iback,
|
2856
|
+
double* stp, double* xstep, long* k, double* cachyt, double* sbtime, double* lnscht) {
|
2923
2857
|
long i__1;
|
2924
|
-
FILE
|
2858
|
+
FILE* itfptr;
|
2925
2859
|
static long i__;
|
2926
2860
|
|
2927
2861
|
--x;
|
@@ -3023,8 +2957,8 @@ L999:
|
|
3023
2957
|
if (*iprint >= 1) {
|
3024
2958
|
itfptr = fopen("iterate.dat", "a");
|
3025
2959
|
if (*info == -4 || *info == -9) {
|
3026
|
-
fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E - -\n",
|
3027
|
-
|
2960
|
+
fprintf(itfptr, " %4ld %4ld %5ld %5ld %3s %4ld %7.1E %7.1E - -\n", *iter, *nfgv, *nseg, *nact, word,
|
2961
|
+
*iback, *stp, *xstep);
|
3028
2962
|
}
|
3029
2963
|
fprintf(itfptr, "\n");
|
3030
2964
|
fprintf(itfptr, "%s\n", task);
|
@@ -3090,9 +3024,7 @@ L999:
|
|
3090
3024
|
* Ciyou Zhu
|
3091
3025
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
|
3092
3026
|
*/
|
3093
|
-
int projgr_(long
|
3094
|
-
long *nbd, double *x, double *g, double *sbgnrm)
|
3095
|
-
{
|
3027
|
+
int projgr_(long* n, double* l, double* u, long* nbd, double* x, double* g, double* sbgnrm) {
|
3096
3028
|
long i__1;
|
3097
3029
|
double d__1, d__2;
|
3098
3030
|
static long i__;
|
@@ -3299,13 +3231,9 @@ int projgr_(long *n, double *l, double *u,
|
|
3299
3231
|
* Ciyou Zhu
|
3300
3232
|
* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal
|
3301
3233
|
*/
|
3302
|
-
int subsm_(long
|
3303
|
-
|
3304
|
-
|
3305
|
-
double *theta, double *xx, double *gg, long *col,
|
3306
|
-
long *head, long *iword, double *wv, double *wn,
|
3307
|
-
long *iprint, long *info)
|
3308
|
-
{
|
3234
|
+
int subsm_(long* n, long* m, long* nsub, long* ind, double* l, double* u, long* nbd, double* x, double* d__, double* xp,
|
3235
|
+
double* ws, double* wy, double* theta, double* xx, double* gg, long* col, long* head, long* iword, double* wv,
|
3236
|
+
double* wn, long* iprint, long* info) {
|
3309
3237
|
long ws_dim1, ws_offset, wy_dim1, wy_offset, wn_dim1, wn_offset, i__1, i__2;
|
3310
3238
|
double d__1, d__2;
|
3311
3239
|
static long i__, j, k, m2;
|
@@ -3361,7 +3289,7 @@ int subsm_(long *n, long *m, long *nsub, long *ind,
|
|
3361
3289
|
/* Compute wv:=K^(-1)wv. */
|
3362
3290
|
m2 = *m << 1;
|
3363
3291
|
col2 = *col << 1;
|
3364
|
-
|
3292
|
+
lbfgsb_rb_dtrsl_(&wn[wn_offset], &m2, &col2, &wv[1], &c__11, info);
|
3365
3293
|
if (*info != 0) {
|
3366
3294
|
return 0;
|
3367
3295
|
}
|
@@ -3369,7 +3297,7 @@ int subsm_(long *n, long *m, long *nsub, long *ind,
|
|
3369
3297
|
for (i__ = 1; i__ <= i__1; ++i__) {
|
3370
3298
|
wv[i__] = -wv[i__];
|
3371
3299
|
}
|
3372
|
-
|
3300
|
+
lbfgsb_rb_dtrsl_(&wn[wn_offset], &m2, &col2, &wv[1], &c__1, info);
|
3373
3301
|
if (*info != 0) {
|
3374
3302
|
return 0;
|
3375
3303
|
}
|
@@ -3381,18 +3309,17 @@ int subsm_(long *n, long *m, long *nsub, long *ind,
|
|
3381
3309
|
i__2 = *nsub;
|
3382
3310
|
for (i__ = 1; i__ <= i__2; ++i__) {
|
3383
3311
|
k = ind[i__];
|
3384
|
-
d__[i__] = d__[i__] + wy[k + pointr * wy_dim1] * wv[jy] / *theta
|
3385
|
-
+ ws[k + pointr * ws_dim1] * wv[js];
|
3312
|
+
d__[i__] = d__[i__] + wy[k + pointr * wy_dim1] * wv[jy] / *theta + ws[k + pointr * ws_dim1] * wv[js];
|
3386
3313
|
}
|
3387
3314
|
pointr = pointr % *m + 1;
|
3388
3315
|
}
|
3389
3316
|
d__1 = 1. / *theta;
|
3390
|
-
|
3317
|
+
lbfgsb_rb_dscal_(nsub, &d__1, &d__[1], &c__1);
|
3391
3318
|
|
3392
3319
|
/* ----------------------------------------------------------------- */
|
3393
3320
|
/* Let us try the projection, d is the Newton direction */
|
3394
3321
|
*iword = 0;
|
3395
|
-
|
3322
|
+
lbfgsb_rb_dcopy_(n, &x[1], &c__1, &xp[1], &c__1);
|
3396
3323
|
|
3397
3324
|
i__1 = *nsub;
|
3398
3325
|
for (i__ = 1; i__ <= i__1; ++i__) {
|
@@ -3445,7 +3372,7 @@ int subsm_(long *n, long *m, long *nsub, long *ind,
|
|
3445
3372
|
dd_p__ += (x[i__] - xx[i__]) * gg[i__];
|
3446
3373
|
}
|
3447
3374
|
if (dd_p__ > 0.) {
|
3448
|
-
|
3375
|
+
lbfgsb_rb_dcopy_(n, &xp[1], &c__1, &x[1], &c__1);
|
3449
3376
|
fprintf(stderr, " Positive dir derivative in projection\n");
|
3450
3377
|
fprintf(stderr, " Using the backtracking step\n");
|
3451
3378
|
} else {
|
@@ -3637,11 +3564,8 @@ L911:
|
|
3637
3564
|
* Argonne National Laboratory and University of Minnesota.
|
3638
3565
|
* Brett M. Averick, Richard G. Carter, and Jorge J. More'.
|
3639
3566
|
*/
|
3640
|
-
int dcsrch_(double
|
3641
|
-
|
3642
|
-
double *stpmin, double *stpmax,
|
3643
|
-
char *task, long *isave, double *dsave)
|
3644
|
-
{
|
3567
|
+
int dcsrch_(double* f, double* g, double* stp, double* ftol, double* gtol, double* xtol, double* stpmin, double* stpmax,
|
3568
|
+
char* task, long* isave, double* dsave) {
|
3645
3569
|
|
3646
3570
|
double d__1;
|
3647
3571
|
static double fm, gm, fx, fy, gx, gy, fxm, fym, gxm, gym, stx, sty;
|
@@ -3917,11 +3841,8 @@ L1000:
|
|
3917
3841
|
* Argonne National Laboratory and University of Minnesota.
|
3918
3842
|
* Brett M. Averick and Jorge J. More'.
|
3919
3843
|
*/
|
3920
|
-
int dcstep_(double
|
3921
|
-
|
3922
|
-
double *fp, double *dp, long *brackt, double *stpmin,
|
3923
|
-
double *stpmax)
|
3924
|
-
{
|
3844
|
+
int dcstep_(double* stx, double* fx, double* dx, double* sty, double* fy, double* dy, double* stp, double* fp, double* dp,
|
3845
|
+
long* brackt, double* stpmin, double* stpmax) {
|
3925
3846
|
double d__1, d__2, d__3;
|
3926
3847
|
static double p, q, r__, s, sgnd, stpc, stpf, stpq, gamma, theta;
|
3927
3848
|
|
@@ -3953,10 +3874,10 @@ int dcstep_(double *stx, double *fx, double *dx,
|
|
3953
3874
|
stpf = stpc + (stpq - stpc) / 2.;
|
3954
3875
|
}
|
3955
3876
|
*brackt = TRUE_;
|
3956
|
-
|
3957
|
-
|
3958
|
-
|
3959
|
-
|
3877
|
+
/* Second case: A lower function value and derivatives of opposite */
|
3878
|
+
/* sign. The minimum is bracketed. If the cubic step is farther from */
|
3879
|
+
/* stp than the secant step, the cubic step is taken, otherwise the */
|
3880
|
+
/* secant step is taken. */
|
3960
3881
|
} else if (sgnd < 0.) {
|
3961
3882
|
theta = (*fx - *fp) * 3. / (*stp - *stx) + *dx + *dp;
|
3962
3883
|
d__1 = fabs(theta);
|
@@ -3980,8 +3901,8 @@ int dcstep_(double *stx, double *fx, double *dx,
|
|
3980
3901
|
stpf = stpq;
|
3981
3902
|
}
|
3982
3903
|
*brackt = TRUE_;
|
3983
|
-
|
3984
|
-
|
3904
|
+
/* Third case: A lower function value, derivatives of the same sign, */
|
3905
|
+
/* and the magnitude of the derivative decreases. */
|
3985
3906
|
} else if (fabs(*dp) < fabs(*dx)) {
|
3986
3907
|
/* The cubic step is computed only if the cubic tends to infinity */
|
3987
3908
|
/* in the direction of the step or if the minimum of the cubic */
|
@@ -4041,10 +3962,10 @@ int dcstep_(double *stx, double *fx, double *dx,
|
|
4041
3962
|
stpf = *stpmax <= stpf ? *stpmax : stpf;
|
4042
3963
|
stpf = *stpmin >= stpf ? *stpmin : stpf;
|
4043
3964
|
}
|
4044
|
-
|
4045
|
-
|
4046
|
-
|
4047
|
-
|
3965
|
+
/* Fourth case: A lower function value, derivatives of the same sign, */
|
3966
|
+
/* and the magnitude of the derivative does not decrease. If the */
|
3967
|
+
/* minimum is not bracketed, the step is either stpmin or stpmax, */
|
3968
|
+
/* otherwise the cubic step is taken. */
|
4048
3969
|
} else {
|
4049
3970
|
if (*brackt) {
|
4050
3971
|
theta = (*fp - *fy) * 3. / (*sty - *stp) + *dy + *dp;
|
@@ -4052,7 +3973,7 @@ int dcstep_(double *stx, double *fx, double *dx,
|
|
4052
3973
|
d__2 = fabs(*dy);
|
4053
3974
|
d__1 = d__1 >= d__2 ? d__1 : d__2;
|
4054
3975
|
d__2 = fabs(*dp);
|
4055
|
-
s = d__1 >= d__2 ? d__1: d__2;
|
3976
|
+
s = d__1 >= d__2 ? d__1 : d__2;
|
4056
3977
|
d__1 = theta / s;
|
4057
3978
|
gamma = s * sqrt(d__1 * d__1 - *dy / s * (*dp / s));
|
4058
3979
|
if (*stp > *sty) {
|
@@ -4089,8 +4010,7 @@ int dcstep_(double *stx, double *fx, double *dx,
|
|
4089
4010
|
return 0;
|
4090
4011
|
}
|
4091
4012
|
|
4092
|
-
int timer_(double
|
4093
|
-
{
|
4013
|
+
int timer_(double* ttime) {
|
4094
4014
|
*ttime = (double)clock() / CLOCKS_PER_SEC;
|
4095
4015
|
return 0;
|
4096
4016
|
}
|