20#ifndef CCGSL_FUNCTION_FDF_HPP
21#define CCGSL_FUNCTION_FDF_HPP
26#if __cplusplus <= 199711L
95 virtual double f(
double x ) = 0;
101 virtual double df(
double x ) = 0;
107 virtual std::pair<double,double>
fdf(
double x ) = 0;
118 typedef double (*function_t)(double,
void*);
122 typedef void (*function_fdf_t)(double,
void*,
double*,
double*);
128 struct FDF :
public base_F {
134 FDF( T& t ) : t( t ){}
142 static double fn(
double x,
void* params ){
143 return reinterpret_cast<FDF<T>*
>( params )->t.f( x ); }
150 static double dfn(
double x,
void* params ){
151 return reinterpret_cast<FDF<T>*
>( params )->t.df( x ); }
158 static void fdfn(
double x,
void* params,
double* d,
double*
df ){
159 std::pair<double,double> pair =
reinterpret_cast<FDF<T>*
>( params )->t.fdf( x );
160 *d = pair.first; *
df = pair.second; }
171 struct function_scl_adapter :
public base_F,
public Concept {
173 function_scl_adapter( function_scl&
function, function_scl& dfunction )
174 : scl_function(
function ), scl_dfunction( dfunction ){}
180 double f(
double x ){
return fn_eval( scl_function, x ); }
186 double df(
double x ){
return fn_eval( scl_dfunction, x ); }
192 std::pair<double,double>
fdf(
double x ){
193 return std::make_pair(
fn_eval( scl_function, x ),
fn_eval( scl_dfunction, x ) ); }
201 static double fn(
double x,
void* params ){
202 return reinterpret_cast<function_scl_adapter*
>( params )->f( x ); }
209 static double dfn(
double x,
void* params ){
210 return reinterpret_cast<function_scl_adapter*
>( params )->
df( x ); }
217 static void fdfn(
double x,
void* params,
double* d,
double*
df ){
218 std::pair<double,double> pair =
reinterpret_cast<function_scl_adapter*
>( params )->
fdf( x );
219 *d = pair.first; *
df = pair.second; }
224 function_scl& scl_function;
228 function_scl& scl_dfunction;
276 function_fdf_constructor<T>( *
this, t );
288 this->function =
new function_scl_adapter(
function, dfunction );
289 f = &function_scl_adapter::fn;
290 df = &function_scl_adapter::dfn;
291 fdf = &function_scl_adapter::fdfn;
333#ifdef __GXX_EXPERIMENTAL_CXX0X__
340 std::swap(
df, v.df );
341 std::swap(
fdf, v.fdf );
342 std::swap( params, v.params );
343 std::swap(
count, v.count );
344 v.function =
nullptr;
354 std::swap(
df, v.df );
355 std::swap(
fdf, v.fdf );
356 std::swap( params, v.params );
357 std::swap(
count, v.count );
383 fdf.function =
new function_fdf::FDF<T>( t );
384 fdf.f = &function_fdf::FDF<T>::fn;
385 fdf.df = &function_fdf::FDF<T>::dfn;
386 fdf.fdf = &function_fdf::FDF<T>::fdfn;
387 fdf.params =
fdf.function;
389 fdf.count =
new size_t;
397 fdf.function = v.function;
fdf.count = v.count;
fdf.f = v.f;
fdf.df = v.df;
398 fdf.fdf = v.fdf;
fdf.params = v.params;
if(
fdf.count != 0 ) ++*
fdf.count;
405 fdf.f = v.f;
fdf.df = v.df;
fdf.fdf = v.fdf;
fdf.params = v.params; }
425 return (
F->f)( x,
F->params );
435 return (
F.f)( x,
F.params );
445 return (
F->df)( x,
F->params );
455 return (
F.df)( x,
F.params );
466 double* f,
double*
df ){
467 return (
F->fdf)( x,
F->params, f,
df );
478 double& f,
double&
df ){
479 return (
F.fdf)( x,
F.params, &f, &
df );
Class that extends gsl_function_fdf so that it can be constructed from arbitrary function objects.
function_fdf & operator=(function_fdf const &v)
The assignment operator.
function_fdf(function_fdf &&v)
Move constructor.
function_fdf(gsl_function_fdf &v)
Could construct from a gsl_function_fdf.
function_fdf()
The default constructor is only really useful for assigning to.
function_fdf & operator=(function_fdf &&v)
Move operator.
base_F * function
This gives something for params to point to.
size_t * count
The shared reference count: used for copying this.
function_fdf(function_fdf const &v)
The copy constructor.
~function_fdf()
The destructor unshares any shared resource.
friend void function_fdf_constructor(function_fdf &fdf, T &t)
function_fdf(function_scl &function, function_scl &dfunction)
Construct from function_scl objects for function and derivative.
function_fdf(T &t)
Construct from an object that implements gsl::function_fdf::Concept.
Class that extends gsl_function so that it can be constructed from arbitrary function objects.
int df(double const h, gsl_multifit_nlinear_fdtype const fdtype, vector const &x, vector const &wts, gsl::multifit::nlinear::function_fdf &fdf, vector const &f, matrix &J, vector &work)
C++ version of gsl_multifit_nlinear_df().
gsl_multilarge_nlinear_fdf fdf
Typedef for shorthand.
double F(double phi, double k, mode_t mode)
C++ version of gsl_sf_ellint_F().
The gsl package creates an interface to the GNU Scientific Library for C++.
function_fdf make_function_fdf(T &t)
Make a gsl::function_fdf from a function object that implements gsl::function_fdf::Concept.
void function_fdf_constructor(function_fdf &fdf, T &t)
double fn_eval(gsl_function const &F, double const x)
Evaluate a gsl::function (or gsl_function).
double fn_fdf_eval_f(gsl_function_fdf const *const F, double const x)
Evaluate a gsl::function_fdf (or gsl_function_fdf).
double fn_fdf_eval_df(gsl_function_fdf const *const F, double const x)
Evaluate a gsl::function_fdf (or gsl_function_fdf).
This is an empty abstract base class.
virtual std::pair< double, double > fdf(double x)=0
The function and derivative.
virtual double df(double x)=0
The derivative.
virtual double f(double x)=0
The function.