[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gsl] another suggestion for - "Re: using gsl callback routine from
From: |
Vinicius Miranda |
Subject: |
[Bug-gsl] another suggestion for - "Re: using gsl callback routine from c++ / pointer to member, function (Jonathan Taylor)" |
Date: |
Thu, 14 Feb 2013 12:02:32 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
I'm trying to use GSL's multimin routine from C++, but the same issue
arises with integration and any functionality that uses a callback function
to calculate a user function f(x). The calls to GSL and to the callback
function are in a class. I am using g++ 4.1.2 and GSL 1.13.
l define a function myF() to compute f(x), and pass GSL a pointer to myF().
The problem is that the compiler won't convert from "pointer to myF ()" to
the way that GSL declares the pointer. This is because C++ treats a
"pointer to member function" differently from how it treats a pointer to a
function that is not part of a class. I understand the C++ issue; I hope
that somebody on this list knows how to get around it.
Hi,
Another standard suggestion is the following
class gsl_function_pp : public gsl_function
{
public:
gsl_function_pp(boost::function<double(double)> const& func) :
_func(func)
{
function=&gsl_function_pp::invoke;
params=this;
}
private:
boost::function<double(double)> _func;
static double invoke(double x, void *params)
{
return static_cast<gsl_function_pp*>(params)->_func(x);
}
};
When I need to invoke member functions with parameters,
Class::integrand(double x, double par1)
{...}
I use something like this
gsl_function_pp Fp( boost::bind(&Class::integrand, this, z, _2 ) );
gsl_function *F = static_cast<gsl_function*>(&Fp);
Best
Vinicius
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gsl] another suggestion for - "Re: using gsl callback routine from c++ / pointer to member, function (Jonathan Taylor)",
Vinicius Miranda <=