Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLFunctionAdapter.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 GSLFunctionAdapter
26//
27// Generic adapter for gsl_function signature
28// usable for any c++ class which defines operator( )
29//
30// Created by: Lorenzo Moneta at Fri Nov 12 16:58:51 2004
31//
32// Last update: Fri Nov 12 16:58:51 2004
33//
34#ifndef ROOT_Math_GSLFunctionAdapter
35#define ROOT_Math_GSLFunctionAdapter
36
37
38namespace ROOT {
39namespace Math {
40
41 /**
42 Function pointer corresponding to gsl_function signature
43 */
44
45 typedef double ( * GSLFuncPointer ) ( double, void *);
46
47
48 /**
49 Class for adapting any C++ functor class to C function pointers used by GSL.
50 The templated C++ function class must implement:
51
52 <em> double operator( double x)</em>
53 and if the derivatives are required:
54 <em> double Gradient( double x)</em>
55
56 This class defines static methods with will be used to fill the
57 \a gsl_function and \a gsl_function_fdf structs used by GSL.
58 See for examples the <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_32.html#SEC432">GSL online manual</A>
59 */
60
61
62 template<class UserFunc>
64
65 public:
66
69
70 static double F( double x, void * p) {
71
72 UserFunc * function = reinterpret_cast< UserFunc *> (p);
73 return (*function)( x );
74 }
75
76
77 static double Df( double x, void * p) {
78
79 UserFunc * function = reinterpret_cast< UserFunc *> (p);
80 return (*function).Derivative( x );
81 }
82
83 static void Fdf( double x, void * p, double *f, double *df ) {
84
85 UserFunc * function = reinterpret_cast< UserFunc *> (p);
86 *f = (*function) ( x );
87 *df = (*function).Derivative( x );
88 }
89
90 };
91
92
93} // namespace Math
94} // namespace ROOT
95
96
97#endif /* ROOT_Math_GSLFunctionAdapter */
#define f(i)
Definition RSha256.hxx:104
winID h TVirtualViewer3D TVirtualGLPainter p
Class for adapting any C++ functor class to C function pointers used by GSL.
static void Fdf(double x, void *p, double *f, double *df)
static double F(double x, void *p)
static double Df(double x, void *p)
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
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...