casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompiledParam.h
Go to the documentation of this file.
1 //# CompiledParam.h: Parameters for a compiled string function
2 //# Copyright (C) 2002,2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef SCIMATH_COMPILEDPARAM_H
30 #define SCIMATH_COMPILEDPARAM_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 // <summary>
41 // Parameters for a compiled string function object.
42 // </summary>
43 //
44 // <use visibility=local>
45 //
46 // <reviewed reviewer="" date="" tests="tFuncExpression" demos="">
47 // </reviewed>
48 //
49 // <prerequisite>
50 // <li> <linkto class="FuncExpression">FuncExpression</linkto> class
51 // </prerequisite>
52 //
53 // <synopsis>
54 // Given a string describing an expression
55 // (see <linkto class=FuncExpression>FuncExpression</linkto> class for
56 // details of the expression), the <src>CompiledFunction</src>class wraps
57 // this expression as a
58 // Function (see <linkto class=Function>Function</linkto> class) which can
59 // be used in all places where functions can be used (e.g. see
60 // <linkto module=Fitting>Fitting</linkto>).
61 //
62 // This class takes care of the
63 // <linkto class=CompiledFunction>CompiledFunction</linkto> parameter interface
64 // (see <linkto class=FunctionParam>FunctionParam</linkto> class for details).
65 // </synopsis>
66 //
67 // <example>
68 // In the following example a Gaussian profile with three parameters
69 // (height, center and halfwidth) is specified and its value and
70 // derivatives with respect to the parameters are calculated at <src>x=2</src>.
71 // <srcblock>
72 // // the Gaussian
73 // CompiledFunction<Double> prof("p0*exp(-((x-p1)/p2)^2)");
74 // prof[0] = 2; // the height
75 // prof[1] = 1.5; // the center
76 // prof[2] = 1; // the width
77 // Vector<Double> x(3);
78 // X[0] = 1.9; x[1] = 2.0; x[2] = 2.1;
79 // cout << "Gaussian at x=" << x << ": " << prof(x) << endl;
80 // // and an automatic derivative one:
81 // CompiledFunction<AutoDiff<Double> > profad("p0*exp(-((x-p1)/p2)^2)");
82 // cout << "Gaussian at x=" << x << ": " << profad(x) << endl;
83 // </srcblock>
84 // will produce the output:
85 // <srcblock>
86 // </srcblock>
87 // </example>
88 
89 // <templating arg=T>
90 // <li> T should have standard numerical operators and functions.
91 // <li> To obtain derivatives, the derivatives should be defined.
92 // </templating>
93 
94 // <thrown>
95 // </thrown>
96 
97 // <motivation>
98 // This class was created to allow specialization of the function evaluation in
99 // a simple way.
100 // </motivation>
101 //
102 // <todo asof="2002/04/29">
103 // <li> Nothing I know of
104 // </todo>
105 
106 template <class T> class CompiledParam : public Function<T> {
107  public:
108  //# Constructors
109  // The default constructor -- no functions, no parameters, nothing, the
110  // function operator returns a 0.
111  CompiledParam();
112  // Make this object a (deep) copy of other.
113  // <group>
114  CompiledParam(const CompiledParam<T> &other);
115  template <class W>
117  Function<T>(other), ndim_p(other.ndim()), msg_p(other.errorMessage()),
118  text_p(other.getText()),
120  // </group>
121  // Make this object a (deep) copy of other.
123  // Destructor
124  virtual ~CompiledParam();
125 
126  //# Operators
127 
128  //# Member functions
129  // Give name of function
130  virtual const String &name() const { static String x("compiled");
131  return x; }
132 
133  // Set a function. The return will be False (and an error message will be
134  // set) if a compilation error occurs
135  Bool setFunction(const String &newFunction);
136 
137  // Return the error message of the compilation
138  const String &errorMessage() const { return msg_p; }
139 
140  // Return the expression
141  const FuncExpression &function() const;
142 
143  // Returns the dimension of function
144  virtual uInt ndim() const { return ndim_p; }
145 
146  // Returns the text of the function string
147  const String &getText() const { return text_p; }
148 
149  // Returns the function pointer (for debugging)
151  return functionPtr_p; }
152 
153 protected:
154  //# Data
155  // Number of dimensions of underlying function
157  // Possible error message
159  // Input text string
161 
162  // Pointer to function
164 
165 };
166 
167 
168 } //# NAMESPACE CASACORE - END
169 
170 #ifndef CASACORE_NO_AUTO_TEMPLATES
171 #include <casacore/scimath/Functionals/CompiledParam.tcc>
172 #endif //# CASACORE_NO_AUTO_TEMPLATES
173 #endif
Parameters for a compiled string function object.
uInt ndim_p
Number of dimensions of underlying function.
virtual uInt ndim() const
Returns the dimension of function.
CompiledParam< T > & operator=(const CompiledParam< T > &other)
Make this object a (deep) copy of other.
CompiledParam(const CompiledParam< W > &other)
String msg_p
Possible error message.
virtual const String & name() const
Give name of function.
String text_p
Input text string.
Numerical functional interface class.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
CompiledParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0...
An expression executable as function.
Bool setFunction(const String &newFunction)
Set a function.
FuncExpression * functionPtr_p
Pointer to function.
const String & getText() const
Returns the text of the function string.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const String & errorMessage() const
Return the error message of the compilation.
virtual ~CompiledParam()
Destructor.
unsigned int uInt
Definition: aipstype.h:51
const FuncExpression * getFunctionPtr() const
Returns the function pointer (for debugging)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42