20#ifndef CCGSL_MULTIFIT_NLINEAR_FUNCTION_FDF_HPP
21#define CCGSL_MULTIFIT_NLINEAR_FUNCTION_FDF_HPP
24#if __cplusplus <= 199711L
29#include<gsl/gsl_multifit_nlinear.h>
77 virtual size_t xSize()
const = 0;
81 virtual size_t fSize()
const = 0;
123 typedef int (*f_t)(gsl_vector
const*,
void*,gsl_vector*);
124 typedef int (*df_t)(gsl_vector
const*,
void*,gsl_matrix*);
125 typedef int (*fvv_t)(gsl_vector
const*,gsl_vector
const*,
void*,gsl_vector*);
127 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector&)>
129 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector&) const>
131 template<
typename U>
static f_t f(fSfinae<U,&U::f>*){
return &F<U>::fn;}
132 template<
typename U>
static f_t f(fSfinaeC<U,&U::f>*){
return &F<U>::fn;}
133 template<
typename U>
static f_t f(...){
return 0;}
135 template<
typename U,
int (U::*)(gsl::vector const&, gsl::matrix&)>
137 template<
typename U,
int (U::*)(gsl::vector const&, gsl::matrix&) const>
139 template<
typename U>
static df_t
df(dfSfinae<U,&U::df>*){
return &F<U>::dfn;}
140 template<
typename U>
static df_t
df(dfSfinaeC<U,&U::df>*){
return &F<U>::dfn;}
141 template<
typename U>
static df_t
df(...){
return 0;}
143 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector const&, gsl::vector&)>
147 struct fvvSfinaeC {};
148 template<
typename U>
static fvv_t fvv(fvvSfinae<U,&U::fvv>*){
return &F<U>::fvvn;}
149 template<
typename U>
static fvv_t fvv(fvvSfinaeC<U,&U::fvv>*){
return &F<U>::fvvn;}
150 template<
typename U>
static fvv_t fvv(...){
return 0;}
161 typedef int (*function_t)(gsl_vector
const*,
void*,gsl_vector*);
165 typedef int (*dfunction_t)(gsl_vector
const*,
void*,gsl_matrix*);
169 typedef int (*fvvfunction_t)(gsl_vector
const*,gsl_vector
const*,
void*,gsl_vector*);
175 struct F :
public base_F {
182 xv.wrap_gsl_vector_without_ownership( 0 );
183 vv.wrap_gsl_vector_without_ownership( 0 );
184 fv.wrap_gsl_vector_without_ownership( 0 );
185 Jv.wrap_gsl_matrix_without_ownership( 0 );
196 static int fn( gsl_vector
const* x,
void* params, gsl_vector* f ){
198 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
199 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
200 ft->fv.ccgsl_pointer = f;
201 return ft->t.f( ft->xv, ft->fv ); }
210 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* J ){
212 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
213 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
214 ft->Jv.ccgsl_pointer = J;
215 return ft->t.df( ft->xv, ft->Jv ); }
225 static int fvvn( gsl_vector
const* x, gsl_vector
const* v,
226 void* params, gsl_vector* f ){
228 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
229 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
230 ft->vv.ccgsl_pointer =
const_cast<gsl_vector*
>( v );
231 ft->fv.ccgsl_pointer = f;
232 return ft->t.fvv( ft->xv, ft->vv, ft->fv ); }
258 class Fn :
public base_F {
268 size_t const xSize,
size_t fSize )
269 : f( f ),
df(
df ), fvv( fvv ), xSize( xSize ), fSize( fSize ){}
273 function_t function(){
return &fn; }
277 dfunction_t dfunction(){
return &dfn; }
281 fvvfunction_t fvvfunction(){
return &fvvn; }
312 static int fn( gsl_vector
const* x,
void* params, gsl_vector* f ){
314 Fn* ft =
reinterpret_cast<Fn*
>( params );
315 ft->fv.ccgsl_pointer = f;
316 return ft->f( ft->xv, ft->fv ); }
325 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* J ){
327 Fn* ft =
reinterpret_cast<Fn*
>( params );
328 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
329 ft->Jv.ccgsl_pointer = J;
330 return ft->df( ft->xv, ft->Jv ); }
340 static int fvvn( gsl_vector
const* x, gsl_vector
const* v,
341 void* params, gsl_vector* f ){
343 Fn* ft =
reinterpret_cast<Fn*
>( params );
344 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
345 ft->vv.ccgsl_pointer =
const_cast<gsl_vector*
>( v );
346 ft->fv.ccgsl_pointer = f;
347 return ft->fvv( ft->xv, ft->vv, ft->fv ); }
430 size_t const xSize,
size_t const fSize ){
433 func =
new function_fdf::Fn( f,
df, fvv, xSize, fSize );
434 this->f = (0 == f) ? 0 : Fn::fn;
435 this->
df = (0 ==
df) ? 0 : Fn::dfn;
436 this->fvv = (0 == fvv) ? 0 : Fn::fvvn;
485#ifdef __GXX_EXPERIMENTAL_CXX0X__
492 std::swap(
df, v.df );
493 std::swap( fvv, v.fvv );
496 std::swap( params, v.params );
497 std::swap(
count, v.count );
506 std::swap(
func, v.func );
508 std::swap(
df, v.df );
509 std::swap( fvv, v.fvv );
512 std::swap( params, v.params );
513 std::swap(
count, v.count );
541 f.func =
new function_fdf::F<T>( t );
542 f.f = function_fdf::address_of::f<T>(0);
543 f.df = function_fdf::address_of::df<T>(0);
544 f.fvv = function_fdf::address_of::fvv<T>(0);
550 f.
count =
new size_t;
560 f.func = v.func; f.
count = v.
count; f.f = v.f; f.df = v.df; f.fvv = v.fvv;
561 f.n = v.n; f.p = v.p; f.params = v.params;
if( f.
count != 0 ) ++*f.
count;
570 f.f = v.f; f.df = v.df; f.fvv = v.fvv; f.n = v.n; f.p = v.p; f.params = v.params; }
Class that extends gsl_function_fdf so that it can be constructed from arbitrary function objects.
size_t * count
The shared reference count: used for copying this.
This class handles matrix objects as shared handles.
Class that extends gsl_multifit_nlinear_fdf so that it can be constructed from arbitrary function obj...
function_fdf & operator=(function_fdf const &v)
The assignment operator.
function_fdf & operator=(function_fdf &&v)
Move operator.
size_t * count
The shared reference count: used for copying this.
function_fdf()
The default constructor is only really useful for assigning to.
function_fdf(gsl_multifit_nlinear_fdf &v)
Could construct from a gsl_multifit_nlinear_fdf.
base_F * func
This gives something for params to point to.
friend void function_constructor(function_fdf &, T &)
function_fdf(function_fdf const &v)
The copy constructor.
function_fdf(int(*const f)(gsl::vector const &, gsl::vector &), int(*const df)(gsl::vector const &, gsl::matrix &), int(*const fvv)(gsl::vector const &, gsl::vector &, gsl::vector &), size_t const xSize, size_t const fSize)
Construct from a function with no parameters (but with n function values and arguments).
~function_fdf()
The destructor unshares any shared resource.
function_fdf(function_fdf &&v)
Move constructor.
function_fdf(T &t)
Construct from an object that implements gsl::multifit::nlinear::function_fdf::concept.
This class handles vector objects as shared handles.
void function_constructor(function_fdf &f, T &t)
function_fdf make_function_fdf(T &t)
Make a gsl::multifit::nlinear::function_fdf from a function object that implements gsl::multifit::nli...
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().
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
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++.
This is an abstract base class.
virtual int df(gsl::vector const &x, gsl::matrix &J)=0
The derivatives (as Jacobian matrix).
This is an abstract base class.
virtual int f(gsl::vector const &x, gsl::vector &f)=0
The function.
virtual size_t xSize() const =0
This function should return the number of elements of x in f().
virtual size_t fSize() const =0
This function should return the number of elements of f in f().
This is an abstract base class.
virtual int fvv(gsl::vector const &x, gsl::vector const &v, gsl::vector &fvv)=0
The second directional derivatives.