GslMultiminFunctionAdapter.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_GSLMULTIMINFUNCTIONADAPTER_HPP
2 #define JULIAN_GSLMULTIMINFUNCTIONADAPTER_HPP
3 
4 #include <gsl/gsl_multimin.h>
5 
6 namespace julian {
7 
22  template< typename F >
23  class GslMultiminFunctionAdapter : public gsl_multimin_function {
24  public:
30  GslMultiminFunctionAdapter(const F& func,unsigned int n_) : func_(func) {
32  n = n_;
33  params=this;
34 
35  }
36  private:
39  static double call(const gsl_vector* x, void *params) {
40  std::vector<double> x_std;
41 
42  for(unsigned int i = 0; i < static_cast<GslMultiminFunctionAdapter*>(params)->n; ++i) {
43  x_std.push_back( gsl_vector_get(x,i));
44  }
45  return static_cast<GslMultiminFunctionAdapter*>(params)->func_(x_std);
46  }
47 
48  const F& func_;
49  };
50 }
51 #endif /* GSLMULTIMINFUNCTIONADAPTER_HPP */
Definition: cadHoliday.cpp:3
Class implements adapter for gsl_multimin_function.
Definition: GslMultiminFunctionAdapter.hpp:23
GslMultiminFunctionAdapter(const F &func, unsigned int n_)
Constructor.
Definition: GslMultiminFunctionAdapter.hpp:30
const F & func_
F must be a functor.
Definition: GslMultiminFunctionAdapter.hpp:48
static double call(const gsl_vector *x, void *params)
Method called by the GSL algorithm.
Definition: GslMultiminFunctionAdapter.hpp:39