Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLFunctionWrapper.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Authors: L. Moneta, A. Zsenei 08/2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class GSLFunctionWrapper
26//
27// Created by: moneta at Sat Nov 13 14:54:41 2004
28//
29// Last update: Sat Nov 13 14:54:41 2004
30//
31#ifndef ROOT_Math_GSLFunctionWrapper
32#define ROOT_Math_GSLFunctionWrapper
33
34#include "gsl/gsl_math.h"
35
37
38#include <cassert>
39
40namespace ROOT {
41namespace Math {
42
43
44
45typedef double ( * GSLFuncPointer ) ( double, void *);
46typedef void ( * GSLFdfPointer ) ( double, void *, double *, double *);
47
48
49/**
50 Wrapper class to the gsl_function C structure.
51 This class to fill the GSL C structure gsl_function with
52 the C++ function objcet.
53 Use the class ROOT::Math::GSLFunctionAdapter to adapt the
54 C++ function object to the right signature (function pointer type)
55 requested by GSL
56*/
58
59public:
60
62 {
63 fFunc.function = nullptr;
64 fFunc.params = nullptr;
65 }
66
67 /// set in the GSL C struct the pointer to the function evaluation
69
70 /// set in the GSL C struct the extra-object pointer
71 void SetParams ( void * p) { fFunc.params = p; }
72
73 /// fill the GSL C struct from a generic C++ callable object
74 /// implementing operator()
75 template<class FuncType>
76 void SetFunction(const FuncType &f) {
77 const void * p = &f;
78 assert (p != nullptr);
80 SetParams(const_cast<void *>(p));
81 }
82
83 gsl_function * GetFunc() { return &fFunc; }
84
86
87 // evaluate the function
88 double operator() (double x) { return GSL_FN_EVAL(&fFunc, x); }
89
90 /// check if function is valid (has been set)
91 bool IsValid() {
92 return (fFunc.function != nullptr) ? true : false;
93 }
94
95private:
97
98
99};
100
101
102 /**
103 class to wrap a gsl_function_fdf (with derivatives)
104 */
106
107 public:
108
110 {
111 fFunc.f = nullptr;
112 fFunc.df = nullptr;
113 fFunc.fdf = nullptr;
114 fFunc.params = nullptr;
115 }
116
117
121 void SetParams ( void * p) { fFunc.params = p; }
122
123
124 gsl_function_fdf * GetFunc() { return &fFunc; }
125
126 // evaluate the function and derivatives
127 double operator() (double x) { return GSL_FN_FDF_EVAL_F(&fFunc, x); }
128
129 double Derivative (double x) { return GSL_FN_FDF_EVAL_DF(&fFunc, x); }
130
131 void Fdf(double x, double & f, double & df) {
132 return GSL_FN_FDF_EVAL_F_DF(&fFunc, x, &f, &df);
133 }
134
135 /// check if function is valid (has been set)
136 bool IsValid() {
137 return (fFunc.f != nullptr ) ? true : false;
138 }
139
140 private:
141 gsl_function_fdf fFunc;
142
143 };
144
145
146
147} // namespace Math
148} // namespace ROOT
149
150#endif /* ROOT_Math_GSLFunctionWrapper */
#define f(i)
Definition RSha256.hxx:104
#define GSL_FN_EVAL(F, x)
winID h TVirtualViewer3D TVirtualGLPainter p
Class for adapting any C++ functor class to C function pointers used by GSL.
class to wrap a gsl_function_fdf (with derivatives)
bool IsValid()
check if function is valid (has been set)
void Fdf(double x, double &f, double &df)
Wrapper class to the gsl_function C structure.
void SetFunction(const FuncType &f)
fill the GSL C struct from a generic C++ callable object implementing operator()
void SetFuncPointer(GSLFuncPointer f)
set in the GSL C struct the pointer to the function evaluation
void SetParams(void *p)
set in the GSL C struct the extra-object pointer
bool IsValid()
check if function is valid (has been set)
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
void(* GSLFdfPointer)(double, void *, double *, double *)
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
double(* function)(double x, void *params)