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> class CompiledParam : public Function<T> {
104 public:
105 //# Constructors
106 // The default constructor -- no functions, no parameters, nothing, the
107 // function operator returns a 0.
109 // Make this object a (deep) copy of other.
110 // <group>
112 template <class W>
114 Function<T>(other), ndim_p(other.ndim()), msg_p(other.errorMessage()),
115 text_p(other.getText()),
117 // </group>
118 // Make this object a (deep) copy of other.
120 // Destructor
121 virtual ~CompiledParam();
122
123 //# Operators
124
125 //# Member functions
126 // Give name of function
127 virtual const String &name() const { static String x("compiled");
128 return x; }
129
130 // Set a function. The return will be False (and an error message will be
131 // set) if a compilation error occurs
132 Bool setFunction(const String &newFunction);
133
134 // Return the error message of the compilation
135 const String &errorMessage() const { return msg_p; }
136
137 // Return the expression
138 const FuncExpression &function() const;
139
140 // Returns the dimension of function
141 virtual uInt ndim() const { return ndim_p; }
142
143 // Returns the text of the function string
144 const String &getText() const { return text_p; }
145
146 // Returns the function pointer (for debugging)
148 return functionPtr_p; }
149
150protected:
151 //# Data
152 // Number of dimensions of underlying function
154 // Possible error message
156 // Input text string
158
159 // Pointer to function
161
162};
163
164
165} //# NAMESPACE CASACORE - END
166
167#ifndef CASACORE_NO_AUTO_TEMPLATES
168#include <casacore/scimath/Functionals/CompiledParam.tcc>
169#endif //# CASACORE_NO_AUTO_TEMPLATES
170#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.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40