35#ifndef ROOT_Math_GSLMultiRootFunctionAdapter
36#define ROOT_Math_GSLMultiRootFunctionAdapter
38#include "gsl/gsl_vector.h"
39#include "gsl/gsl_matrix.h"
67template<
class FuncVector>
74 static int F(
const gsl_vector *
x,
void * p, gsl_vector *
f ) {
76 unsigned int n =
f->size;
78 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
79 if (
n == 0)
return -1;
80 for (
unsigned int i = 0; i <
n ; ++i) {
81 gsl_vector_set(
f, i, (*funcVec[i])(
x->data) );
87 static int Df(
const gsl_vector *
x,
void * p, gsl_matrix *
h) {
90 unsigned int n =
h->size1;
91 unsigned int npar =
h->size2;
92 if (
n == 0)
return -1;
93 if (npar == 0)
return -2;
94 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
95 for (
unsigned int i = 0; i <
n ; ++i) {
96 double *
g = (
h->data)+i*npar;
97 assert ( npar == (funcVec[i])->NDim() );
98 (funcVec[i])->Gradient(
x->data,
g);
104 static int FDf(
const gsl_vector *
x,
void * p, gsl_vector *
f, gsl_matrix *
h) {
107 unsigned int n =
h->size1;
108 unsigned int npar =
h->size2;
109 if (
n == 0)
return -1;
110 if (npar == 0)
return -2;
111 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
112 assert (
f->size ==
n);
113 for (
unsigned int i = 0; i <
n ; ++i) {
114 assert ( npar == (funcVec[i])->NDim() );
116 double *
g = (
h->data)+i*npar;
117 (funcVec[i])->FdF(
x->data, fval,
g);
118 gsl_vector_set(
f, i, fval );
Class for adapting a C++ functor class to C function pointers used by GSL MultiRoot Algorithm The tem...
static int FDf(const gsl_vector *x, void *p, gsl_vector *f, gsl_matrix *h)
evaluate derivative and function at the same time
static int F(const gsl_vector *x, void *p, gsl_vector *f)
static int Df(const gsl_vector *x, void *p, gsl_matrix *h)
Namespace for new Math classes and functions.