20#ifndef CCGSL_MULTILARGE_NLINEAR_FUNCTION_FDF_HPP
21#define CCGSL_MULTILARGE_NLINEAR_FUNCTION_FDF_HPP
24#if __cplusplus <= 199711L
29#include<gsl/gsl_multilarge_nlinear.h>
34 namespace multilarge {
91 virtual size_t xSize()
const = 0;
95 virtual size_t fSize()
const = 0;
118 typedef int (*f_t)(gsl_vector
const*,
void*,gsl_vector*);
119 typedef int (*df_t)(CBLAS_TRANSPOSE_t,gsl_vector
const*,
120 gsl_vector
const*,
void*,gsl_vector*,gsl_matrix*);
121 typedef int (*fvv_t)(gsl_vector
const*,gsl_vector
const*,
void*,gsl_vector*);
123 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector&)>
125 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector&) const>
127 template<
typename U>
static f_t f(fSfinae<U,&U::f>*){
return &F<U>::fn;}
128 template<
typename U>
static f_t f(fSfinaeC<U,&U::f>*){
return &F<U>::fn;}
129 template<
typename U>
static f_t f(...){
return 0;}
131 template<
typename U, int (U::*)(CBLAS_TRANSPOSE_t,
gsl::vector const&,
134 template<
typename U, int (U::*)(CBLAS_TRANSPOSE_t,
gsl::vector const&,
137 template<
typename U>
static df_t
df(dfSfinae<U,&U::df>*){
return &F<U>::dfn;}
138 template<
typename U>
static df_t
df(dfSfinaeC<U,&U::df>*){
return &F<U>::dfn;}
139 template<
typename U>
static df_t
df(...){
return 0;}
141 template<
typename U,
int (U::*)(gsl::vector const&, gsl::vector const&, gsl::vector&)>
145 struct fvvSfinaeC {};
146 template<
typename U>
static fvv_t fvv(fvvSfinae<U,&U::fvv>*){
return &F<U>::fvvn;}
147 template<
typename U>
static fvv_t fvv(fvvSfinaeC<U,&U::fvv>*){
return &F<U>::fvvn;}
148 template<
typename U>
static fvv_t fvv(...){
return 0;}
159 typedef int (*function_t)(gsl_vector
const*,
void*,gsl_vector*);
163 typedef int (*dfunction_t)(CBLAS_TRANSPOSE_t,gsl_vector
const*,
164 gsl_vector
const*,
void*,gsl_vector*,gsl_matrix*);
168 typedef int (*fvvfunction_t)(gsl_vector
const*,gsl_vector
const*,
void*,gsl_vector*);
174 struct F :
public base_F {
181 xv.wrap_gsl_vector_without_ownership( 0 );
182 uv.wrap_gsl_vector_without_ownership( 0 );
183 vv.wrap_gsl_vector_without_ownership( 0 );
184 fv.wrap_gsl_vector_without_ownership( 0 );
185 JTJv.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 ); }
213 static int dfn( CBLAS_TRANSPOSE_t TransJ, gsl_vector
const* x, gsl_vector
const* u,
214 void* params, gsl_vector* v, gsl_matrix* JTJ ){
216 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
217 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
218 ft->uv.ccgsl_pointer =
const_cast<gsl_vector*
>( u );
219 ft->vv.ccgsl_pointer = v;
220 ft->JTJv.ccgsl_pointer = JTJ;
221 return ft->t.df( TransJ, ft->xv, ft->uv, ft->vv, ft->JTJv ); }
231 static int fvvn( gsl_vector
const* x, gsl_vector
const* v,
232 void* params, gsl_vector* f ){
234 F<T>* ft =
reinterpret_cast<F<T>*
>( params );
235 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
236 ft->vv.ccgsl_pointer =
const_cast<gsl_vector*
>( v );
237 ft->fv.ccgsl_pointer = f;
238 return ft->t.fvv( ft->xv, ft->vv, ft->fv ); }
268 class Fn :
public base_F {
279 size_t const xSize,
size_t fSize )
280 : f( f ),
df(
df ), fvv( fvv ), xSize( xSize ), fSize( fSize ){}
284 function_t function(){
return &fn; }
288 dfunction_t dfunction(){
return &dfn; }
292 fvvfunction_t fvvfunction(){
return &fvvn; }
324 static int fn( gsl_vector
const* x,
void* params, gsl_vector* f ){
326 Fn* ft =
reinterpret_cast<Fn*
>( params );
327 ft->fv.ccgsl_pointer = f;
328 return ft->f( ft->xv, ft->fv ); }
340 static int dfn( CBLAS_TRANSPOSE_t TransJ, gsl_vector
const* x, gsl_vector
const* u,
341 void* params, gsl_vector* v, gsl_matrix* JTJ ){
343 Fn* ft =
reinterpret_cast<Fn*
>( params );
344 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
345 ft->uv.ccgsl_pointer =
const_cast<gsl_vector*
>( u );
346 ft->vv.ccgsl_pointer = v;
347 ft->JTJv.ccgsl_pointer = JTJ;
348 return ft->df( TransJ, ft->xv, ft->uv, ft->vv, ft->JTJv ); }
358 static int fvvn( gsl_vector
const* x, gsl_vector
const* v,
359 void* params, gsl_vector* f ){
361 Fn* ft =
reinterpret_cast<Fn*
>( params );
362 ft->xv.ccgsl_pointer =
const_cast<gsl_vector*
>( x );
363 ft->vv.ccgsl_pointer =
const_cast<gsl_vector*
>( v );
364 ft->fv.ccgsl_pointer = f;
365 return ft->fvv( ft->xv, ft->vv, ft->fv ); }
453 size_t const xSize,
size_t const fSize ){
456 func =
new function_fdf::Fn( f,
df, fvv, xSize, fSize );
457 this->f = (0 == f) ? 0 : Fn::fn;
458 this->
df = (0 ==
df) ? 0 : Fn::dfn;
459 this->fvv = (0 == fvv) ? 0 : Fn::fvvn;
508#ifdef __GXX_EXPERIMENTAL_CXX0X__
515 std::swap(
df, v.df );
516 std::swap( fvv, v.fvv );
519 std::swap( params, v.params );
520 std::swap(
count, v.count );
529 std::swap(
func, v.func );
531 std::swap(
df, v.df );
532 std::swap( fvv, v.fvv );
535 std::swap( params, v.params );
536 std::swap(
count, v.count );
564 f.func =
new function_fdf::F<T>( t );
565 f.f = function_fdf::address_of::f<T>(0);
566 f.df = function_fdf::address_of::df<T>(0);
567 f.fvv = function_fdf::address_of::fvv<T>(0);
573 f.
count =
new size_t;
583 f.func = v.func; f.
count = v.
count; f.f = v.f; f.df = v.df; f.fvv = v.fvv;
584 f.n = v.n; f.p = v.p; f.params = v.params;
if( f.
count != 0 ) ++*f.
count;
593 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_multilarge_nlinear_fdf so that it can be constructed from arbitrary function o...
function_fdf(T &t)
Construct from an object that implements gsl::multilarge::nlinear::function_fdf::concept.
base_F * func
This gives something for params to point to.
friend void function_constructor(function_fdf &, T &)
function_fdf & operator=(function_fdf const &v)
The assignment operator.
function_fdf()
The default constructor is only really useful for assigning to.
function_fdf(gsl_multilarge_nlinear_fdf &v)
Could construct from a gsl_multilarge_nlinear_fdf.
function_fdf(int(*const f)(gsl::vector const &, gsl::vector &), int(*const df)(CBLAS_TRANSPOSE_t, gsl::vector const &, gsl::vector const &, gsl::vector &, 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 & operator=(function_fdf &&v)
Move operator.
function_fdf(function_fdf const &v)
The copy constructor.
size_t * count
The shared reference count: used for copying this.
function_fdf(function_fdf &&v)
Move constructor.
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::multilarge::nlinear::function_fdf from a function object that implements gsl::multilarge:...
int df(double const h, fdtype const fdtype, vector const &x, vector const &wts, gsl::multilarge::nlinear::function_fdf &fdf, vector const &f, matrix &J, vector &work)
C++ version of gsl_multilarge_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 f(gsl::vector const &x, gsl::vector &f)=0
The function.
virtual size_t fSize() const =0
This function should return the number of elements of f in f().
virtual size_t xSize() const =0
This function should return the number of elements of x in f().
virtual int df(CBLAS_TRANSPOSE_t TransJ, gsl::vector const &x, gsl::vector const &u, gsl::vector &v, gsl::matrix &JTJ)=0
The derivatives (as Jacobian matrix).
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.