Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions go/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The package can be directly installed with command go if libLBFGS is
installed to standard locations. Otherwise, change the lines starting
with #cgo above

import "C"

in lbfgs.go to

#cgo LDFLAGS: -Lpath_to_lbfgs_lib -llbfgs
#cgo CFLAGS: -Ipath_to_lbfgs_include

to let the compiler know your custom install location. For more
information, see [http://golang.org/cmd/cgo].
24 changes: 24 additions & 0 deletions go/cgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef __LIBLBFGS_GO_WRAP_H__
#define __LIBLBFGS_GO_WRAP_H__

#include <lbfgs.h>

// Exported function from lbfgs.go.
extern lbfgsfloatval_t goLbfgsEvaluate(void *instance, lbfgsfloatval_t *x,
lbfgsfloatval_t *g, int n,
lbfgsfloatval_t step);

// Exported function from lbfgs.go.
extern int goLbfgsProgress(void *instance, lbfgsfloatval_t *x,
lbfgsfloatval_t *g, lbfgsfloatval_t fx,
lbfgsfloatval_t xnorm, lbfgsfloatval_t gnorm,
lbfgsfloatval_t step, int n, int k, int ls);

// Uses evaluate and progress function exported from go to call C lbfgs.
static inline int goLbfgs(int n, lbfgsfloatval_t *x, lbfgsfloatval_t *ptr_fx,
void *instance, lbfgs_parameter_t *param) {
return lbfgs(n, x, ptr_fx, (lbfgs_evaluate_t)goLbfgsEvaluate,
(lbfgs_progress_t)goLbfgsProgress, instance, param);
}

#endif // __LIBLBFGS_GO_WRAP_H__
Loading