20#ifndef CCGSL_MULTIFIT_FUNCTION_FDF_HPP
21#define CCGSL_MULTIFIT_FUNCTION_FDF_HPP
23#include<gsl/gsl_multifit_nlin.h>
27#if __cplusplus <= 199711L
54 class function_fdf :
public gsl_multifit_function_fdf {
94 virtual size_t size()
const = 0;
98 virtual size_t num_parameters()
const = 0;
109 typedef int (*function_t)(gsl_vector
const*,
void*,gsl_vector*);
113 typedef int (*dfunction_t)(gsl_vector
const*,
void*,gsl_matrix*);
117 typedef int (*fdfunction_t)(gsl_vector
const*,
void*,gsl_vector*,gsl_matrix*);
123 struct F :
public base_F {
139 static int fn( gsl_vector
const* x,
void* params, gsl_vector* fx ){
141 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
142 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
143 ft->fv.wrap_gsl_vector_without_ownership( fx );
144 return ft->t.f( ft->xv, ft->fv ); }
153 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* dfx ){
155 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
156 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
157 ft->dfv.wrap_gsl_matrix_without_ownership( dfx );
158 return ft->t.df( ft->xv, ft->dfv ); }
168 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* fx, gsl_matrix* dfx ){
170 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
171 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
172 ft->fv.wrap_gsl_vector_without_ownership( fx );
173 ft->dfv.wrap_gsl_matrix_without_ownership( dfx );
174 return ft->t.fdf( ft->xv, ft->fv, ft->dfv ); }
196 class Fn :
public base_F {
210 function_t function(){
return &fn; }
214 dfunction_t dfunction(){
return &dfn; }
218 fdfunction_t fdfunction(){
return &fdfn; }
245 static int fn( gsl_vector
const* x,
void* params, gsl_vector* fx ){
247 Fn* ft =
reinterpret_cast<Fn*
>( params );
248 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
249 ft->fv.wrap_gsl_vector_without_ownership( fx );
250 return ft->f( ft->xv, ft->fv ); }
259 static int dfn( gsl_vector
const* x,
void* params, gsl_matrix* dfx ){
261 Fn* ft =
reinterpret_cast<Fn*
>( params );
262 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
263 ft->dfv.wrap_gsl_matrix_without_ownership( dfx );
264 return ft->df( ft->xv, ft->dfv ); }
274 static int fdfn( gsl_vector
const* x,
void* params, gsl_vector* fx, gsl_matrix* dfx ){
276 Fn* ft =
reinterpret_cast<Fn*
>( params );
277 ft->xv.wrap_gsl_vector_without_ownership(
const_cast<gsl_vector*
>( x ) );
278 ft->fv.wrap_gsl_vector_without_ownership( fx );
279 ft->dfv.wrap_gsl_matrix_without_ownership( dfx );
280 return ft->fdf( ft->xv, ft->fv, ft->dfv ); }
326 explicit function_fdf( gsl_multifit_function_fdf& v ){
345 function_fdf( T& t ){ function_constructor<T>( *
this, t ); }
362 this->
fdf = Fn::fdfn;
379 function_fdf( function_fdf
const& v ) :
func( v.
func ), count( v.count ){
386 if( count != 0 ) ++*count;
393 function_fdf& operator=( function_fdf
const& v ){
395 if( count == 0 or --*count == 0 ){
408 if( count != 0 ) ++*count;
411#ifdef __GXX_EXPERIMENTAL_CXX0X__
416 function_fdf( function_fdf&& v ) :
func( v.
func ), count( nullptr ){
418 std::swap(
df, v.df );
419 std::swap(
fdf, v.fdf );
422 std::swap( params, v.params );
423 std::swap( count, v.count );
431 function_fdf& operator=( function_fdf&& v ){
432 std::swap(
func, v.func );
434 std::swap(
df, v.df );
435 std::swap(
fdf, v.fdf );
438 std::swap( params, v.params );
439 std::swap( count, v.count );
448 if( count == 0 or --*count == 0 ){
467 f.func =
new function_fdf::F<T>( t );
468 f.f = &function_fdf::F<T>::fn;
469 f.df = &function_fdf::F<T>::dfn;
470 f.fdf = &function_fdf::F<T>::fdfn;
472 f.p = t.num_parameters();
475 f.count =
new size_t;
485 f.func = v.func; f.count = v.count; f.f = v.f; f.df = v.df; f.fdf = v.fdf; f.n = v.n;
486 f.p = v.p; f.params = v.params;
if( f.count != 0 ) ++*f.count;
495 f.f = v.f; f.df = v.df; f.fdf = v.fdf; f.n = v.n; f.p = v.p; f.params = v.params; }
505 function_fdf fn( t );
506#ifdef __GXX_EXPERIMENTAL_CXX0X__
507 return std::move( fn );
This class handles matrix objects as shared handles.
This class handles vector objects as shared handles.
size_t size(series const &cs)
C++ version of gsl_cheb_size().
void function_constructor(function_fdf &f, T &t)
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().
function make_function(T &t)
Make a gsl::multifit::function from a function object that implements gsl::multifit::function::Concep...
gsl_multilarge_nlinear_fdf fdf
Typedef for shorthand.
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().
double func(int const n, double const x)
C++ version of gsl_sf_hermite_func().
The gsl package creates an interface to the GNU Scientific Library for C++.