help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] GSL, C++, and function pointers


From: eknecronzontas
Subject: Re: [Help-gsl] GSL, C++, and function pointers
Date: Mon, 5 Mar 2007 17:05:56 -0800 (PST)

Hello!

     Since you're not working with the usual C-types
(double instead of linalg::double), the easiest 
solution is to write a global (or static member)
function wrapper with the same form as GSL expects and
then calling your function instead. 

     My solution to this problem is usually to rewrite
the GSL routines as templates so they call
type::operator() instead of using a function pointer.
For some related function objects, see:

http://tharkad.pa.msu.edu/~asteiner/hal/html/classfunct__fptr__nopar.html

     Unfortunately, my gsl_deriv class template

http://tharkad.pa.msu.edu/~asteiner/hal/html/classgsl__deriv.html

uses a lazier approach (for historical reasons and I
haven't gotten around to fixing it), but you might
want to check out, for example, 

http://tharkad.pa.msu.edu/~asteiner/hal/html/classcern__root.html

which uses operator() in an implementation of the
CERNLIB 1-d equation solver.

I should note the GSL derivative function is quite
simple and probably not to difficult to rewrite...in
case you decide you want to do that instead.

Later,
Andrew Steiner



--- Jordi Gutierrez Hermoso <address@hidden> wrote:

> Sometimes I think that besides joke languages like
> Brainfuck, C++ must
> be the most complicated language ever... I'll try to
> explain, but I
> tend to be verbose and chatty when I write.
> 
> Here's what's happening: I want to use GSL's
> differentation routines,
> but due to the vicissitudes of OOP, my functions
> take in
> linalg::vector objects and return doubles. A
> linalg::vector is pretty
> much what its name suggests, and in fact, it's just
> my own wrapper for
> GSL vectors. So my functions are from \mathbb{R}^n
> to \mathbb{R}.
> 
> I want partial derivatives now for a differential
> operator class I'm
> building for giving some flexibility in defining and
> solving BVPs, but
> I have just realised that differentiation is one of
> those things
> that's harder than it looks to accomplish
> gracefully. I trust the GSL
> has better differentiation routines than anything I
> could come up
> with, but they all take function pointers to
> functions that take in
> doubles and return doubles.
> 
> Now, C++'s STL, I just discovered, provides some
> routines and classes
> for creating functors (function-like objects) out of
> any function by
> binding some variables (e.g. the index of the
> coordinate along which I
> would like to differentiate my multi-variable
> function). However, I
> don't see how to adapt these C++ functors into the
> function pointers
> that the GSL expects. This is one of those times
> when I wish C++ would
> allow function definition at runtime. :-(
> 
> Help, ideas? It's mostly a design issue, and I'd
> rather resolve it
> cleanly so as to avoid rewriting any code, if
> possible.
> 
> Thanks,
> - Jordi G. H.
> 
> 
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]