casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef SCIMATH_COMPILEDPARAM_H
27#define SCIMATH_COMPILEDPARAM_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/scimath/Functionals/Function.h>
33#include <casacore/scimath/Functionals/FuncExpression.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Parameters for a compiled string function object.
39// </summary>
40//
41// <use visibility=local>
42//
43// <reviewed reviewer="" date="" tests="tFuncExpression" demos="">
44// </reviewed>
45//
46// <prerequisite>
47// <li> <linkto class="FuncExpression">FuncExpression</linkto> class
48// </prerequisite>
49//
50// <synopsis>
51// Given a string describing an expression
52// (see <linkto class=FuncExpression>FuncExpression</linkto> class for
53// details of the expression), the <src>CompiledFunction</src>class wraps
54// this expression as a
55// Function (see <linkto class=Function>Function</linkto> class) which can
56// be used in all places where functions can be used (e.g. see
57// <linkto module=Fitting>Fitting</linkto>).
58//
59// This class takes care of the
60// <linkto class=CompiledFunction>CompiledFunction</linkto> parameter interface
61// (see <linkto class=FunctionParam>FunctionParam</linkto> class for details).
62// </synopsis>
63//
64// <example>
65// In the following example a Gaussian profile with three parameters
66// (height, center and halfwidth) is specified and its value and
67// derivatives with respect to the parameters are calculated at <src>x=2</src>.
68// <srcblock>
69// // the Gaussian
70// CompiledFunction<Double> prof("p0*exp(-((x-p1)/p2)^2)");
71// prof[0] = 2; // the height
72// prof[1] = 1.5; // the center
73// prof[2] = 1; // the width
74// Vector<Double> x(3);
75// X[0] = 1.9; x[1] = 2.0; x[2] = 2.1;
76// cout << "Gaussian at x=" << x << ": " << prof(x) << endl;
77// // and an automatic derivative one:
78// CompiledFunction<AutoDiff<Double> > profad("p0*exp(-((x-p1)/p2)^2)");
79// cout << "Gaussian at x=" << x << ": " << profad(x) << endl;
80// </srcblock>
81// will produce the output:
82// <srcblock>
83// </srcblock>
84// </example>
85
86// <templating arg=T>
87// <li> T should have standard numerical operators and functions.
88// <li> To obtain derivatives, the derivatives should be defined.
89// </templating>
90
91// <thrown>
92// </thrown>
93
94// <motivation>
95// This class was created to allow specialization of the function evaluation in
96// a simple way.
97// </motivation>
98//
99// <todo asof="2002/04/29">
100// <li> Nothing I know of
101// </todo>
102
103template <class T>
104class CompiledParam : public Function<T> {
105 public:
106 // # Constructors
107 // The default constructor -- no functions, no parameters, nothing, the
108 // function operator returns a 0.
110 // Make this object a (deep) copy of other.
111 // <group>
113 template <class W>
115 : Function<T>(other),
116 ndim_p(other.ndim()),
117 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 {
131 static String x("compiled");
132 return x;
133 }
134
135 // Set a function. The return will be False (and an error message will be
136 // set) if a compilation error occurs
137 Bool setFunction(const String &newFunction);
138
139 // Return the error message of the compilation
140 const String &errorMessage() const { return msg_p; }
141
142 // Return the expression
143 const FuncExpression &function() const;
144
145 // Returns the dimension of function
146 virtual uInt ndim() const { return ndim_p; }
147
148 // Returns the text of the function string
149 const String &getText() const { return text_p; }
150
151 // Returns the function pointer (for debugging)
152 const FuncExpression *getFunctionPtr() const { return functionPtr_p; }
153
154 protected:
155 // # Data
156 // Number of dimensions of underlying function
158 // Possible error message
160 // Input text string
162
163 // Pointer to function
165};
166
167} // namespace casacore
168
169#ifndef CASACORE_NO_AUTO_TEMPLATES
170#include <casacore/scimath/Functionals/CompiledParam.tcc>
171#endif // # CASACORE_NO_AUTO_TEMPLATES
172#endif
uInt ndim_p
Number of dimensions of underlying function.
virtual ~CompiledParam()
Destructor.
virtual uInt ndim() const
Returns the dimension of function.
const FuncExpression * getFunctionPtr() const
Returns the function pointer (for debugging).
CompiledParam(const CompiledParam< W > &other)
CompiledParam< T > & operator=(const CompiledParam< T > &other)
Make this object a (deep) copy of other.
CompiledParam(const CompiledParam< T > &other)
Make this object a (deep) copy of other.
String msg_p
Possible error message.
const String & getText() const
Returns the text of the function string.
String text_p
Input text string.
FuncExpression * functionPtr_p
Pointer to function.
const FuncExpression & function() const
Return the expression.
virtual const String & name() const
Give name of function.
Bool setFunction(const String &newFunction)
Set a function.
const String & errorMessage() const
Return the error message of the compilation.
CompiledParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
Function()
Constructors.
Definition Function.h:209
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40