According to GSL documentation at http://www.gnu.org/software/gsl/manual/html_node/Initializing-the-Minimizer...., gsl_min_fminimizer_set_with_values has the following signature:
int gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * s, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper)
GSLL set-fminimizer-with-values is defined as follows:
(defmfun set-fminimizer-with-values (minimizer function x-minimum x-lower x-upper f-minimum f-lower f-upper) "gsl_min_fminimizer_set_with_values" (((mpointer minimizer) :pointer) (function :pointer) (x-minimum :double) (x-lower :double) (x-upper :double) (f-minimum :double) (f-lower :double) (f-upper :double)) :documentation ; FDL "Set, or reset, an existing minimizer to use the function and the initial search interval [lower, upper], with a guess for the location of the minimum, using supplied rather than computed values of the function.")
Note the different order of argument names. I often use #'describe to see function argument list and this discrepancy confuses me. Please, apply the patch in the attachement.
Also, can you advice me on how to create a callback for this function? The simplest solution I can come up with is the following:
(cffi:defcallback test :double ((x :double) (parameters :pointer)) (1+ (cos x)))
(cffi:with-foreign-object (callback 'gsl::fnstruct) (setf (cffi:foreign-slot-value callback 'gsl::fnstruct 'function) (cffi:callback test)) (let ((minimizer (gsl:make-one-dimensional-minimizer gsl:+brent-fminimizer+))) (gsl:set-fminimizer-with-values minimizer callback ...) ...))
But I don't like that the fnstruct symbol is not exported. What is the supposed way?
It would be nice to be able to provide ordinary Lisp function as callback for set-fminimizer-with-values instead of foreign pointer to gsl_function. I do understand why it is difficult to make though. Maybe you should use gsl_min_fminimizer_set_with_values instead of gsl_min_fminimizer_set as is suggested by the comment in the definition of one-dimensional-minimizer. GSL uses the latter function as conventional interface for the former. In Lisp this can be handled better via key arguments.