lbfgsb 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +1 -1
- data/ext/lbfgsb/extconf.rb +12 -3
- data/ext/lbfgsb/lbfgsbext.c +48 -17
- data/ext/lbfgsb/lbfgsbext.h +1 -1
- data/ext/lbfgsb/src/blas.c +25 -25
- data/ext/lbfgsb/src/blas.h +5 -5
- data/ext/lbfgsb/src/common.h +16 -0
- data/ext/lbfgsb/src/lbfgsb.c +260 -281
- data/ext/lbfgsb/src/lbfgsb.h +45 -43
- data/ext/lbfgsb/src/linpack.c +23 -24
- data/ext/lbfgsb/src/linpack.h +3 -3
- data/lib/lbfgsb/version.rb +1 -1
- data/lib/lbfgsb.rb +1 -1
- metadata +7 -15
- data/.clang-format +0 -149
- data/.github/workflows/build.yml +0 -19
- data/.gitignore +0 -17
- data/.rspec +0 -3
- data/.yardopts +0 -1
- data/Gemfile +0 -10
- data/Rakefile +0 -15
- data/Steepfile +0 -20
- data/lbfgsb.gemspec +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0558e429ff4c590e681165e0af885de04e9b78d4d679afc89f9c0bcfc1b2764
|
4
|
+
data.tar.gz: 5e1a8a157614da1a8541fbe28aad8cb04bf4096a4d3022f1b519c35abf071544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66997d33a6fd0fb750ae236934fa866a94592161cbba49375bd7d46d94a9c98f0177cd207431d24cd1812bbf10be050106c941de9ac972f7699d0687b97a41c8
|
7
|
+
data.tar.gz: d8ba46b919591239180642f9a45fe5f14337f2aa703ac527ba533449c647be4b64de700a49a88616019241010d37e6118904c992c3886ed7e44c620f771cadc9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.5.0
|
2
|
+
- Add build option to select FORTRAN integer bit size.
|
3
|
+
|
4
|
+
```
|
5
|
+
$ gem install lbfgsb -- --with-use-int64
|
6
|
+
```
|
7
|
+
|
8
|
+
- Add build option to use any blas library.
|
9
|
+
|
10
|
+
```
|
11
|
+
$ gem install lbfgsb -- --with-blas-dir=/opt/local/openblas/lib --with-blas-lib=openblas
|
12
|
+
```
|
13
|
+
|
14
|
+
- Change to use 32-bit integer for FORTRAN integer in internal functions by default.
|
15
|
+
- Introduce conventional commits.
|
16
|
+
|
1
17
|
## 0.4.1
|
2
18
|
- Remove dependent gem's type declaration file from installation files.
|
3
19
|
|
data/LICENSE.txt
CHANGED
data/ext/lbfgsb/extconf.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
require 'numo/narray'
|
3
3
|
|
4
|
+
$defs << '-DUSE_INT64' if with_config('use-int64', false)
|
5
|
+
|
4
6
|
$LOAD_PATH.each do |lp|
|
5
7
|
if File.exist?(File.join(lp, 'numo/numo/narray.h'))
|
6
8
|
$INCFLAGS = "-I#{lp}/numo #{$INCFLAGS}"
|
@@ -26,10 +28,17 @@ if RUBY_PLATFORM =~ /mswin|cygwin|mingw/
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
$srcs = Dir.glob("#{$srcdir}
|
30
|
-
|
31
|
+
$srcs = Dir.glob("#{$srcdir}/**/*.c").map { |path| File.basename(path) }
|
32
|
+
|
33
|
+
blas_dir = with_config('blas-dir')
|
34
|
+
$LDFLAGS = "-L#{blas_dir} #{$LDFLAGS}" unless blas_dir.nil?
|
35
|
+
|
36
|
+
blas_lib = with_config('blas-lib')
|
37
|
+
unless blas_lib.nil?
|
38
|
+
abort "#{blas_lib} not found." unless have_library(blas_lib)
|
39
|
+
$srcs.delete('blas.c')
|
40
|
+
end
|
31
41
|
|
32
|
-
$INCFLAGS << " -I$(srcdir)/src"
|
33
42
|
$VPATH << "$(srcdir)/src"
|
34
43
|
|
35
44
|
create_makefile('lbfgsb/lbfgsbext')
|
data/ext/lbfgsb/lbfgsbext.c
CHANGED
@@ -4,31 +4,43 @@ VALUE rb_mLbfgsb;
|
|
4
4
|
|
5
5
|
static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb, VALUE args, VALUE l_val, VALUE u_val,
|
6
6
|
VALUE nbd_val, VALUE maxcor, VALUE ftol, VALUE gtol, VALUE maxiter, VALUE disp) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
F77_int n_iter;
|
8
|
+
F77_int n_fev;
|
9
|
+
F77_int n_jev;
|
10
|
+
#ifdef USE_INT64
|
11
|
+
F77_int max_iter = NUM2LONG(maxiter);
|
12
|
+
#else
|
13
|
+
F77_int max_iter = NUM2INT(maxiter);
|
14
|
+
#endif
|
11
15
|
narray_t* x_nary;
|
12
16
|
narray_t* l_nary;
|
13
17
|
narray_t* u_nary;
|
14
18
|
narray_t* nbd_nary;
|
15
|
-
|
16
|
-
|
19
|
+
F77_int n;
|
20
|
+
#ifdef USE_INT64
|
21
|
+
F77_int m = NUM2LONG(maxcor);
|
22
|
+
#else
|
23
|
+
F77_int m = NUM2INT(maxcor);
|
24
|
+
#endif
|
17
25
|
double* x_ptr;
|
18
26
|
double* l_ptr;
|
19
27
|
double* u_ptr;
|
20
|
-
|
28
|
+
F77_int* nbd_ptr;
|
21
29
|
double f;
|
22
30
|
double* g;
|
23
31
|
double factr = NUM2DBL(ftol);
|
24
32
|
double pgtol = NUM2DBL(gtol);
|
25
33
|
double* wa;
|
26
|
-
|
34
|
+
F77_int* iwa;
|
27
35
|
char task[60];
|
28
|
-
|
36
|
+
#ifdef USE_INT64
|
37
|
+
F77_int iprint = NIL_P(disp) ? -1 : NUM2LONG(disp);
|
38
|
+
#else
|
39
|
+
F77_int iprint = NIL_P(disp) ? -1 : NUM2INT(disp);
|
40
|
+
#endif
|
29
41
|
char csave[60];
|
30
|
-
|
31
|
-
|
42
|
+
F77_int lsave[4];
|
43
|
+
F77_int isave[44];
|
32
44
|
double dsave[29];
|
33
45
|
VALUE g_val;
|
34
46
|
VALUE fg_arr;
|
@@ -39,7 +51,7 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
39
51
|
rb_raise(rb_eArgError, "x must be a 1-D array.");
|
40
52
|
return Qnil;
|
41
53
|
}
|
42
|
-
n = (
|
54
|
+
n = (F77_int)NA_SIZE(x_nary);
|
43
55
|
if (CLASS_OF(x_val) != numo_cDFloat) {
|
44
56
|
x_val = rb_funcall(numo_cDFloat, rb_intern("cast"), 1, x_val);
|
45
57
|
}
|
@@ -52,7 +64,7 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
52
64
|
rb_raise(rb_eArgError, "l must be a 1-D array.");
|
53
65
|
return Qnil;
|
54
66
|
}
|
55
|
-
if ((
|
67
|
+
if ((F77_int)NA_SIZE(l_nary) != n) {
|
56
68
|
rb_raise(rb_eArgError, "The size of l must be equal to that of x.");
|
57
69
|
return Qnil;
|
58
70
|
}
|
@@ -68,7 +80,7 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
68
80
|
rb_raise(rb_eArgError, "u must be a 1-D array.");
|
69
81
|
return Qnil;
|
70
82
|
}
|
71
|
-
if ((
|
83
|
+
if ((F77_int)NA_SIZE(u_nary) != n) {
|
72
84
|
rb_raise(rb_eArgError, "The size of u must be equal to that of x.");
|
73
85
|
return Qnil;
|
74
86
|
}
|
@@ -84,13 +96,19 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
84
96
|
rb_raise(rb_eArgError, "nbd must be a 1-D array.");
|
85
97
|
return Qnil;
|
86
98
|
}
|
87
|
-
if ((
|
99
|
+
if ((F77_int)NA_SIZE(nbd_nary) != n) {
|
88
100
|
rb_raise(rb_eArgError, "The size of nbd must be equal to that of x.");
|
89
101
|
return Qnil;
|
90
102
|
}
|
103
|
+
#ifdef USE_INT64
|
91
104
|
if (CLASS_OF(nbd_val) != numo_cInt64) {
|
92
105
|
nbd_val = rb_funcall(numo_cInt64, rb_intern("cast"), 1, nbd_val);
|
93
106
|
}
|
107
|
+
#else
|
108
|
+
if (CLASS_OF(nbd_val) != numo_cInt32) {
|
109
|
+
nbd_val = rb_funcall(numo_cInt32, rb_intern("cast"), 1, nbd_val);
|
110
|
+
}
|
111
|
+
#endif
|
94
112
|
if (!RTEST(nary_check_contiguous(nbd_val))) {
|
95
113
|
nbd_val = nary_dup(nbd_val);
|
96
114
|
}
|
@@ -98,10 +116,10 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
98
116
|
x_ptr = (double*)na_get_pointer_for_read_write(x_val);
|
99
117
|
l_ptr = (double*)na_get_pointer_for_read(l_val);
|
100
118
|
u_ptr = (double*)na_get_pointer_for_read(u_val);
|
101
|
-
nbd_ptr = (
|
119
|
+
nbd_ptr = (F77_int*)na_get_pointer_for_read(nbd_val);
|
102
120
|
g = ALLOC_N(double, n);
|
103
121
|
wa = ALLOC_N(double, (2 * m + 5) * n + 12 * m * m + 12 * m);
|
104
|
-
iwa = ALLOC_N(
|
122
|
+
iwa = ALLOC_N(F77_int, 3 * n);
|
105
123
|
|
106
124
|
g_val = Qnil;
|
107
125
|
f = 0.0;
|
@@ -145,9 +163,15 @@ static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb,
|
|
145
163
|
rb_hash_aset(ret, ID2SYM(rb_intern("x")), x_val);
|
146
164
|
rb_hash_aset(ret, ID2SYM(rb_intern("fnc")), DBL2NUM(f));
|
147
165
|
rb_hash_aset(ret, ID2SYM(rb_intern("jcb")), g_val);
|
166
|
+
#ifdef USE_INT64
|
148
167
|
rb_hash_aset(ret, ID2SYM(rb_intern("n_iter")), LONG2NUM(n_iter));
|
149
168
|
rb_hash_aset(ret, ID2SYM(rb_intern("n_fev")), LONG2NUM(n_fev));
|
150
169
|
rb_hash_aset(ret, ID2SYM(rb_intern("n_jev")), LONG2NUM(n_jev));
|
170
|
+
#else
|
171
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("n_iter")), INT2NUM(n_iter));
|
172
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("n_fev")), INT2NUM(n_fev));
|
173
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("n_jev")), INT2NUM(n_jev));
|
174
|
+
#endif
|
151
175
|
rb_hash_aset(ret, ID2SYM(rb_intern("success")), strncmp(task, "CONV", 4) == 0 ? Qtrue : Qfalse);
|
152
176
|
|
153
177
|
RB_GC_GUARD(x_val);
|
@@ -162,6 +186,13 @@ void Init_lbfgsbext(void) {
|
|
162
186
|
rb_mLbfgsb = rb_define_module("Lbfgsb");
|
163
187
|
/* The value of double epsilon used in the native extension. */
|
164
188
|
rb_define_const(rb_mLbfgsb, "DBL_EPSILON", DBL2NUM(DBL_EPSILON));
|
189
|
+
#ifdef USE_INT64
|
190
|
+
/* The bit size of fortran integer. */
|
191
|
+
rb_define_const(rb_mLbfgsb, "SZ_F77_INTEGER", INT2NUM(64));
|
192
|
+
#else
|
193
|
+
/* The bit size of fortran integer. */
|
194
|
+
rb_define_const(rb_mLbfgsb, "SZ_F77_INTEGER", INT2NUM(32));
|
195
|
+
#endif
|
165
196
|
/* @!visibility private */
|
166
197
|
rb_define_module_function(rb_mLbfgsb, "min_l_bfgs_b", lbfgsb_min_l_bfgs_b, 12);
|
167
198
|
}
|
data/ext/lbfgsb/lbfgsbext.h
CHANGED
data/ext/lbfgsb/src/blas.c
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
*/
|
6
6
|
#include "blas.h"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
static
|
8
|
+
void daxpy_(F77_int* n, double* da, double* dx, F77_int* incx, double* dy, F77_int* incy) {
|
9
|
+
F77_int i__1;
|
10
|
+
static F77_int i__, m, ix, iy, mp1;
|
11
11
|
|
12
12
|
--dy;
|
13
13
|
--dx;
|
@@ -16,10 +16,10 @@ int lbfgsb_rb_daxpy_(long* n, double* da, double* dx, long* incx, double* dy, lo
|
|
16
16
|
/* uses unrolled loops for increments equal to one. */
|
17
17
|
/* jack dongarra, linpack, 3/11/78. */
|
18
18
|
if (*n <= 0) {
|
19
|
-
return
|
19
|
+
return;
|
20
20
|
}
|
21
21
|
if (*da == 0.) {
|
22
|
-
return
|
22
|
+
return;
|
23
23
|
}
|
24
24
|
if (*incx == 1 && *incy == 1) {
|
25
25
|
goto L20;
|
@@ -41,7 +41,7 @@ int lbfgsb_rb_daxpy_(long* n, double* da, double* dx, long* incx, double* dy, lo
|
|
41
41
|
ix += *incx;
|
42
42
|
iy += *incy;
|
43
43
|
}
|
44
|
-
return
|
44
|
+
return;
|
45
45
|
|
46
46
|
/* code for both increments equal to 1 */
|
47
47
|
/* clean-up loop */
|
@@ -55,7 +55,7 @@ L20:
|
|
55
55
|
dy[i__] += *da * dx[i__];
|
56
56
|
}
|
57
57
|
if (*n < 4) {
|
58
|
-
return
|
58
|
+
return;
|
59
59
|
}
|
60
60
|
L40:
|
61
61
|
mp1 = m + 1;
|
@@ -66,12 +66,12 @@ L40:
|
|
66
66
|
dy[i__ + 2] += *da * dx[i__ + 2];
|
67
67
|
dy[i__ + 3] += *da * dx[i__ + 3];
|
68
68
|
}
|
69
|
-
return
|
69
|
+
return;
|
70
70
|
}
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
static
|
72
|
+
void dcopy_(F77_int* n, double* dx, F77_int* incx, double* dy, F77_int* incy) {
|
73
|
+
F77_int i__1;
|
74
|
+
static F77_int i__, m, ix, iy, mp1;
|
75
75
|
|
76
76
|
--dy;
|
77
77
|
--dx;
|
@@ -80,7 +80,7 @@ int lbfgsb_rb_dcopy_(long* n, double* dx, long* incx, double* dy, long* incy) {
|
|
80
80
|
/* uses unrolled loops for increments equal to one. */
|
81
81
|
/* jack dongarra, linpack, 3/11/78. */
|
82
82
|
if (*n <= 0) {
|
83
|
-
return
|
83
|
+
return;
|
84
84
|
}
|
85
85
|
if (*incx == 1 && *incy == 1) {
|
86
86
|
goto L20;
|
@@ -102,7 +102,7 @@ int lbfgsb_rb_dcopy_(long* n, double* dx, long* incx, double* dy, long* incy) {
|
|
102
102
|
ix += *incx;
|
103
103
|
iy += *incy;
|
104
104
|
}
|
105
|
-
return
|
105
|
+
return;
|
106
106
|
|
107
107
|
/* code for both increments equal to 1 */
|
108
108
|
/* clean-up loop */
|
@@ -116,7 +116,7 @@ L20:
|
|
116
116
|
dy[i__] = dx[i__];
|
117
117
|
}
|
118
118
|
if (*n < 7) {
|
119
|
-
return
|
119
|
+
return;
|
120
120
|
}
|
121
121
|
L40:
|
122
122
|
mp1 = m + 1;
|
@@ -130,13 +130,13 @@ L40:
|
|
130
130
|
dy[i__ + 5] = dx[i__ + 5];
|
131
131
|
dy[i__ + 6] = dx[i__ + 6];
|
132
132
|
}
|
133
|
-
return
|
133
|
+
return;
|
134
134
|
}
|
135
135
|
|
136
|
-
double
|
137
|
-
|
136
|
+
double ddot_(F77_int* n, double* dx, F77_int* incx, double* dy, F77_int* incy) {
|
137
|
+
F77_int i__1;
|
138
138
|
double ret_val;
|
139
|
-
static
|
139
|
+
static F77_int i__, m, ix, iy, mp1;
|
140
140
|
static double dtemp;
|
141
141
|
|
142
142
|
--dy;
|
@@ -199,9 +199,9 @@ L60:
|
|
199
199
|
return ret_val;
|
200
200
|
}
|
201
201
|
|
202
|
-
|
203
|
-
|
204
|
-
static
|
202
|
+
void dscal_(F77_int* n, double* da, double* dx, F77_int* incx) {
|
203
|
+
F77_int i__1, i__2;
|
204
|
+
static F77_int i__, m, mp1, nincx;
|
205
205
|
|
206
206
|
--dx;
|
207
207
|
|
@@ -210,7 +210,7 @@ int lbfgsb_rb_dscal_(long* n, double* da, double* dx, long* incx) {
|
|
210
210
|
/* jack dongarra, linpack, 3/11/78. */
|
211
211
|
/* modified 3/93 to return if incx .le. 0. */
|
212
212
|
if (*n <= 0 || *incx <= 0) {
|
213
|
-
return
|
213
|
+
return;
|
214
214
|
}
|
215
215
|
if (*incx == 1) {
|
216
216
|
goto L20;
|
@@ -223,7 +223,7 @@ int lbfgsb_rb_dscal_(long* n, double* da, double* dx, long* incx) {
|
|
223
223
|
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
|
224
224
|
dx[i__] = *da * dx[i__];
|
225
225
|
}
|
226
|
-
return
|
226
|
+
return;
|
227
227
|
|
228
228
|
/* code for increment equal to 1 */
|
229
229
|
/* clean-up loop */
|
@@ -237,7 +237,7 @@ L20:
|
|
237
237
|
dx[i__] = *da * dx[i__];
|
238
238
|
}
|
239
239
|
if (*n < 5) {
|
240
|
-
return
|
240
|
+
return;
|
241
241
|
}
|
242
242
|
L40:
|
243
243
|
mp1 = m + 1;
|
@@ -249,5 +249,5 @@ L40:
|
|
249
249
|
dx[i__ + 3] = *da * dx[i__ + 3];
|
250
250
|
dx[i__ + 4] = *da * dx[i__ + 4];
|
251
251
|
}
|
252
|
-
return
|
252
|
+
return;
|
253
253
|
}
|
data/ext/lbfgsb/src/blas.h
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#ifndef LBFGSB_RB_BLAS_H_
|
2
2
|
#define LBFGSB_RB_BLAS_H_
|
3
3
|
|
4
|
-
#include
|
4
|
+
#include "common.h"
|
5
5
|
|
6
|
-
extern
|
7
|
-
extern
|
8
|
-
extern double
|
9
|
-
extern
|
6
|
+
extern void daxpy_(F77_int* n, double* da, double* dx, F77_int* incx, double* dy, F77_int* incy);
|
7
|
+
extern void dcopy_(F77_int* n, double* dx, F77_int* incx, double* dy, F77_int* incy);
|
8
|
+
extern double ddot_(F77_int* n, double* dx, F77_int* incx, double* dy, F77_int* incy);
|
9
|
+
extern void dscal_(F77_int* n, double* da, double* dx, F77_int* incx);
|
10
10
|
|
11
11
|
#endif /* LBFGSB_RB_BLAS_H_ */
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef LBFGSB_RB_COMMON_H_
|
2
|
+
#define LBFGSB_RB_COMMON_H_
|
3
|
+
|
4
|
+
#include <stdint.h>
|
5
|
+
#include <inttypes.h>
|
6
|
+
#include <math.h>
|
7
|
+
|
8
|
+
#ifdef USE_INT64
|
9
|
+
typedef int64_t F77_int;
|
10
|
+
#define PRIdF77INT PRId64
|
11
|
+
#else
|
12
|
+
typedef int32_t F77_int;
|
13
|
+
#define PRIdF77INT PRId32
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#endif /* LBFGSB_RB_COMMON_H_ */
|