ext/lbfgsb/lbfgsbext.c in lbfgsb-0.3.2 vs ext/lbfgsb/lbfgsbext.c in lbfgsb-0.4.0
- old
+ new
@@ -1,15 +1,11 @@
#include "lbfgsbext.h"
VALUE rb_mLbfgsb;
-static
-VALUE lbfgsb_min_l_bfgs_b(VALUE self,
- VALUE fnc, VALUE x_val, VALUE jcb, VALUE args,
- VALUE l_val, VALUE u_val, VALUE nbd_val,
- VALUE maxcor, VALUE ftol, VALUE gtol, VALUE maxiter, VALUE disp)
-{
+static VALUE lbfgsb_min_l_bfgs_b(VALUE self, VALUE fnc, VALUE x_val, VALUE jcb, VALUE args, VALUE l_val, VALUE u_val,
+ VALUE nbd_val, VALUE maxcor, VALUE ftol, VALUE gtol, VALUE maxiter, VALUE disp) {
long n_iter;
long n_fev;
long n_jev;
long max_iter = NUM2LONG(maxiter);
narray_t* x_nary;
@@ -113,14 +109,11 @@
strcpy(task, "START");
n_fev = 0;
n_jev = 0;
for (n_iter = 0; n_iter < max_iter;) {
- setulb_(
- &n, &m, x_ptr, l_ptr, u_ptr, nbd_ptr, &f, g, &factr, &pgtol, wa, iwa,
- task, &iprint, csave, lsave, isave, dsave
- );
+ setulb_(&n, &m, x_ptr, l_ptr, u_ptr, nbd_ptr, &f, g, &factr, &pgtol, wa, iwa, task, &iprint, csave, lsave, isave, dsave);
if (strncmp(task, "FG", 2) == 0) {
if (RB_TYPE_P(jcb, T_TRUE)) {
fg_arr = rb_funcall(self, rb_intern("fnc"), 3, fnc, x_val, args);
f = NUM2DBL(rb_ary_entry(fg_arr, 0));
g_val = rb_ary_entry(fg_arr, 1);
@@ -128,12 +121,14 @@
f = NUM2DBL(rb_funcall(self, rb_intern("fnc"), 3, fnc, x_val, args));
g_val = rb_funcall(self, rb_intern("jcb"), 3, jcb, x_val, args);
}
n_fev++;
n_jev++;
- if (CLASS_OF(g_val) != numo_cDFloat) g_val = rb_funcall(numo_cDFloat, rb_intern("cast"), 1, g_val);
- if (!RTEST(nary_check_contiguous(g_val))) g_val = nary_dup(g_val);
+ if (CLASS_OF(g_val) != numo_cDFloat)
+ g_val = rb_funcall(numo_cDFloat, rb_intern("cast"), 1, g_val);
+ if (!RTEST(nary_check_contiguous(g_val)))
+ g_val = nary_dup(g_val);
memcpy(g, na_get_pointer_for_read(g_val), n * sizeof(*g));
RB_GC_GUARD(g_val);
} else if (strncmp(task, "NEW_X", 5) == 0) {
n_iter++;
} else {
@@ -161,12 +156,10 @@
RB_GC_GUARD(nbd_val);
return ret;
}
-void
-Init_lbfgsbext(void)
-{
+void Init_lbfgsbext(void) {
rb_mLbfgsb = rb_define_module("Lbfgsb");
/* The value of double epsilon used in the native extension. */
rb_define_const(rb_mLbfgsb, "DBL_EPSILON", DBL2NUM(DBL_EPSILON));
/* @!visibility private */
rb_define_module_function(rb_mLbfgsb, "min_l_bfgs_b", lbfgsb_min_l_bfgs_b, 12);