20#ifndef CCGSL_MULTIROOT_FUNCTION_FDF_HPP
21#define CCGSL_MULTIROOT_FUNCTION_FDF_HPP
24#if __cplusplus <= 199711L
89 virtual size_t size()
const = 0;
100 typedef int (*function_t)(gsl_vector
const*,
void*,gsl_vector*);
104 typedef int (*dfunction_t)(gsl_vector
const*,
void*,gsl_matrix*);
108 typedef int (*fdfunction_t)(gsl_vector
const*,
void*,gsl_vector*,gsl_matrix*);
114 struct F :
public base_F {
121 xv.wrap_gsl_vector_without_ownership( 0 );
122 fv.wrap_gsl_vector_without_ownership( 0 );
123 dfv.wrap_gsl_matrix_without_ownership( 0 );
134 static int fn( gsl_vector
const* x,
void* params, gsl_vector* fx ){
136 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
137 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
138 ft->fv.ccgsl_pointer = fx;
139 return ft->t.f( ft->xv, ft->fv ); }
148 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* dfx ){
150 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
151 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
152 ft->dfv.ccgsl_pointer = dfx;
153 return ft->t.df( ft->xv, ft->dfv ); }
163 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* fx, gsl_matrix* dfx ){
165 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
166 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
167 ft->fv.ccgsl_pointer = fx;
168 ft->dfv.ccgsl_pointer = dfx;
169 return ft->t.fdf( ft->xv, ft->fv, ft->dfv ); }
191 class Fn :
public base_F {
205 function_t function(){
return &fn; }
209 dfunction_t dfunction(){
return &dfn; }
213 fdfunction_t fdfunction(){
return &fdfn; }
240 static int fn( gsl_vector
const* x,
void* params, gsl_vector* fx ){
242 Fn* ft =
reinterpret_cast<Fn*
>( params );
243 ft->fv.ccgsl_pointer = fx;
244 return ft->f( ft->xv, ft->fv ); }
253 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* dfx ){
255 Fn* ft =
reinterpret_cast<Fn*
>( params );
256 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
257 ft->dfv.ccgsl_pointer = dfx;
258 return ft->df( ft->xv, ft->dfv ); }
268 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* fx, gsl_matrix* dfx ){
270 Fn* ft =
reinterpret_cast<Fn*
>( params );
271 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
272 ft->fv.ccgsl_pointer = fx;
273 ft->dfv.ccgsl_pointer = dfx;
274 return ft->fdf( ft->xv, ft->fv, ft->dfv ); }
293 struct gsl_F :
public base_F {
299 gsl_F( T& t ) : t( t ){}
308 static int fn( gsl_vector
const* x,
void* params, gsl_vector* f ){
309 return reinterpret_cast<F<T>*
>( params )->t.f( x, f ); }
318 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix*
df ){
319 return reinterpret_cast<F<T>*
>( params )->t.df( x,
df ); }
329 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* f, gsl_matrix*
df ){
330 return reinterpret_cast<F<T>*
>( params )->t.fdf( x, f,
df ); }
340 class gsl_Fn :
public base_F {
349 gsl_Fn(
int (*
const f)(gsl_vector
const*,gsl_vector*),
350 int (*
const df)(gsl_vector
const*,gsl_matrix*),
351 int (*
const fdf)(gsl_vector
const*,gsl_vector*,gsl_matrix*),
356 function_t function(){
return &fn; }
360 dfunction_t dfunction(){
return &dfn; }
364 fdfunction_t fdfunction(){
return &fdfn; }
369 int (*
const f)(gsl_vector
const*,gsl_vector*);
373 int (*
const df)(gsl_vector
const*,gsl_matrix*);
377 int (*
const fdf)(gsl_vector
const*,gsl_vector*,gsl_matrix*);
390 static int fn( gsl_vector
const* x,
void* params, gsl_vector* f ){
391 return reinterpret_cast<gsl_Fn*
>( params )->f( x, f ); }
399 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix*
df ){
400 return reinterpret_cast<gsl_Fn*
>( params )->
df( x,
df ); }
409 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* f, gsl_matrix*
df ){
410 return reinterpret_cast<gsl_Fn*
>( params )->
fdf( x, f,
df ); }
477 this->
fdf = Fn::fdfn;
523#ifdef __GXX_EXPERIMENTAL_CXX0X__
530 std::swap(
df, v.df );
531 std::swap(
fdf, v.fdf );
533 std::swap( params, v.params );
534 std::swap(
count, v.count );
543 std::swap(
func, v.func );
545 std::swap(
df, v.df );
546 std::swap(
fdf, v.fdf );
548 std::swap( params, v.params );
549 std::swap(
count, v.count );
577 f.func =
new function_fdf::F<T>( t );
578 f.f = &function_fdf::F<T>::fn;
579 f.df = &function_fdf::F<T>::dfn;
580 f.fdf = &function_fdf::F<T>::fdfn;
584 f.
count =
new size_t;
594 f.func = v.func; f.count = v.count; f.f = v.f; f.df = v.df; f.fdf = v.fdf; f.n = v.n;
595 f.params = v.params;
if( f.count != 0 ) ++*f.count;
604 f.f = v.f; f.df = v.df; f.fdf = v.fdf; f.n = v.n; f.params = v.params; }
615#ifdef __GXX_EXPERIMENTAL_CXX0X__
616 return std::move( fn );
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_multiroot_function_fdf so that it can be constructed from arbitrary function o...
~function_fdf()
The destructor unshares any shared resource.
function_fdf & operator=(function_fdf &&v)
Move operator.
function_fdf(function_fdf &&v)
Move constructor.
function_fdf(function_fdf const &v)
The copy constructor.
function_fdf(T &t)
Construct from an object that implements gsl::multiroot::function_fdf::Concept.
function_fdf & operator=(function_fdf const &v)
The assignment operator.
size_t * count
The shared reference count: used for copying this.
friend void function_constructor(function_fdf &, T &)
function_fdf(gsl_multiroot_function_fdf &v)
Could construct from a gsl_multiroot_function_fdf.
function_fdf()
The default constructor is only really useful for assigning to.
base_F * func
This gives something for params to point to.
function_fdf(int(*const f)(gsl::vector const &, gsl::vector &), int(*const df)(gsl::vector const &, gsl::matrix &), int(*const fdf)(gsl::vector const &, gsl::vector &, gsl::matrix &), size_t n)
Construct from a function with no parameters (but with n function values and arguments).
This class handles vector objects as shared handles.
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.
void function_constructor(function &, T &)
function_fdf make_function_fdf(T &t)
Make a gsl::multiroot::function_fdf from a function object that implements gsl::multiroot::function_f...
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 empty abstract base class.
virtual int fdf(gsl::vector const &x, gsl::vector &f, gsl::matrix &J)=0
The function (returned as a vector) and derivatives (as Jacobian matrix)
virtual int f(gsl::vector const &x, gsl::vector &f)=0
The function.
virtual int df(gsl::vector const &x, gsl::matrix &J)=0
The derivatives (as Jacobian matrix)
virtual size_t size() const =0
This function should return the number of elements of x and f in f().