Loading...
Searching...
No Matches
casacore::CompiledFunction< T > Class Template Reference
scimath package (libcasa_scimath) » Functionals_module

More...

`#include <CompiledFunction.h>`

## Public Member Functions

| CompiledFunction ()
| The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
| CompiledFunction (const CompiledFunction< T > &other)
| Make this object a (deep) copy of other.
template<class W>
| CompiledFunction (const CompiledFunction< W > &other)
CompiledFunction< T > & | operator= (const CompiledFunction< T > &other)
| Make this object a (deep) copy of other.
virtual | ~CompiledFunction ()
| Destructor.
virtual T | eval (typename Function< T >::FunctionArg x) const
| Evaluate the function at x.
virtual Function< T > * | clone () const
| Return a copy of this object from the heap.
virtual Function< typename FunctionTraits< T >::DiffType > * | cloneAD () const
virtual Function< typename FunctionTraits< T >::BaseType > * | cloneNonAD () const
Public Member Functions inherited from casacore::CompiledParam< T >
| CompiledParam ()
| The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
| CompiledParam (const CompiledParam< T > &other)
| Make this object a (deep) copy of other.
template<class W>
| CompiledParam (const CompiledParam< W > &other)
CompiledParam< T > & | operator= (const CompiledParam< T > &other)
| Make this object a (deep) copy of other.
virtual | ~CompiledParam ()
| Destructor.
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.
const FuncExpression & | function () const
| Return the expression.
virtual uInt | ndim () const
| Returns the dimension of function.
const String & | getText () const
| Returns the text of the function string.
const FuncExpression * | getFunctionPtr () const
| Returns the function pointer (for debugging).
Public Member Functions inherited from casacore::Function< T, U >
| Function ()
| Constructors.
| Function (const uInt n)
| Function (const Vector< T > &in)
| Function (const FunctionParam< T > &other)
template<class W, class X>
| Function (const Function< W, X > &other)
virtual | ~Function ()
| Destructor.
uInt | nparameters () const
| Returns the number of parameters.
virtual U | eval (FunctionArg x) const =0
| Evaluate the function object.
T & | operator[] (const uInt n)
| Manipulate the nth parameter (0-based) with no index check.
const T & | operator[] (const uInt n) const
virtual U | operator() () const
| Evaluate this function object at xor at x, y.
virtual U | operator() (const ArgType &x) const
virtual U | operator() (const Vector< ArgType > &x) const
virtual U | operator() (FunctionArg x) const
virtual U | operator() (const ArgType &x, const ArgType &y) const
virtual U | operator() (const ArgType &x, const ArgType &y, const ArgType &z) const
Bool & | mask (const uInt n)
| Manipulate the mask associated with the nth parameter (e.g.
const Bool & | mask (const uInt n) const
const FunctionParam< T > & | parameters () const
| Return the parameter interface.
FunctionParam< T > & | parameters ()
const Vector< ArgType > & | argp () const
| Get arg_p and parset_p.
Bool | parsetp () const
void | lockParam ()
| Compiler cannot always find the correct 'const' version of parameter access.
void | unlockParam ()
virtual void | setMode (const RecordInterface &mode)
| get/set the function mode.
virtual void | getMode (RecordInterface &mode) const
virtual Bool | hasMode () const
| return True if the implementing function supports a mode.
ostream & | print (ostream &os) const
| Print the function (i.e.
Public Member Functions inherited from casacore::Functional< FunctionTraits< T >::ArgType, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const FunctionTraits< T >::ArgType &x) const=0
| Map a Domain x into a Range y value.
Public Member Functions inherited from casacore::Functional< Vector< FunctionTraits< T >::ArgType >, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const Vector< FunctionTraits< T >::ArgType > &x) const=0
| Map a Domain x into a Range y value.

## Additional Inherited Members

Public Types inherited from casacore::Function< T, U >
typedef FunctionTraits< T >::ArgType | ArgType
typedef const ArgType * | FunctionArg
Protected Attributes inherited from casacore::CompiledParam< T >
uInt | ndim_p
| Number of dimensions of underlying function.
String | msg_p
| Possible error message.
String | text_p
| Input text string.
FuncExpression * | functionPtr_p
| Pointer to function.
Protected Attributes inherited from casacore::Function< T, U >
FunctionParam< T > | param_p
| The parameters and masks.
Vector< ArgType > | arg_p
| Aid for non-contiguous argument storage.
Bool | parset_p
| Indicate parameter written.
Bool | locked_p
| Indicate that parameters are expected to be locked from changing.

## Detailed Description

template<class T>
class casacore::CompiledFunction< T >

Form a linear combination of function objects.

### Intended use:

Public interface

### Review Status

Test programs:
  tFuncExpression

### Prerequisite

- Function class

### Synopsis

Given a string describing an expression (see FuncExpression class for details of the expression), the CompiledFunctionclass wraps this expression as a Function (see Function class) which can be used in all places where functions can be used (e.g. see Fitting).

The CompiledParam class takes care of the parameter interface.

### Example

In the following example a Gaussian profile with three parameters (height, center and halfwidth) is specified and its value and derivatives with respect to the parameters are calculated at x=[1.9,2,2.1].

// the Gaussian
CompiledFunction<Double> prof;
prof.setFunction("p0*exp(-((x-p1)/p2)^2)");
prof[0] = 2; // the height
prof[1] = 1.5; // the center
prof[2] = 1; // the width
Vector<Double> x(3);
x[0] = 1.9; x[1] = 2.0; x[2] = 2.1;
for (uInt i=0; i<3; ++i) {
cout << "Gaussian at x=" << x[i] << ": " << prof(x[i]) << endl;
}
// Calculate automatic derivatives of same function:
CompiledFunction<AutoDiff<Double> > profad;
profad.setFunction("p0*exp(-((x-p1)/p2)^2)");
// Set the parameters (note the specification of the number of
// derivatives and which derivative the parameter is)
profad[0] = AutoDiff<Double>(2, 3,0); // the height
profad[1] = AutoDiff<Double>(1.5,3,1); // the center
profad[2] = AutoDiff<Double>(1, 3,2); // the width
for (uInt i=0; i<3; ++i) {
cout << "Gaussian at x=" << x[i] << ": " << profad(x[i]) << endl;
}
cout << "Value (x=2): " << profad(x[1]).value() << endl;
cout << "Derivatives: " << profad(x[1]).derivatives() << endl;
cout << "Derivative1: " << profad(x[1]).derivatives()[1] << endl;
casacore::AutoDiff
Definition AutoDiff.h:254
casacore::CompiledFunction
Definition CompiledFunction.h:128
casacore::CompiledFunction::CompiledFunction
CompiledFunction()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
Definition CompiledFunction.h:133
casacore::CompiledParam::setFunction
Bool setFunction(const String &newFunction)
Set a function.
casacore::Vector
Definition Vector.h:82
casacore::uInt
unsigned int uInt
Definition aipstype.h:49

will produce the output:

Gaussian at x=1.9: 1.70429
Gaussian at x=2: 1.5576
Gaussian at x=2.1: 1.39535
Gaussian at x=1.9: (1.70429, [0.852144, 1.36343, 0.545372])
Gaussian at x=2: (1.5576, [0.778801, 1.5576, 0.778801])
Gaussian at x=2.1: (1.39535, [0.697676, 1.67442, 1.00465])
Value (x=2): 1.5576
Derivatives: [0.778801, 1.5576, 0.778801]
Derivative1: 1.5576

### Template Type Argument Requirements (T)

- T should have standard numerical operators and functions.
- To obtain derivatives, the derivatives should be defined.

### Motivation

This class was created to allow specialization of the function evaluation in a simple way.

### To Do

- Nothing I know of

Definition at line 128 of file CompiledFunction.h.

## Constructor & Destructor Documentation

## CompiledFunction() [1/3]

template<class T>

casacore::CompiledFunction< T >::CompiledFunction | ( |  | ) |

inline

The default constructor – no functions, no parameters, nothing, the function operator returns a 0.

Definition at line 133 of file CompiledFunction.h.

References casacore::CompiledParam< T >::CompiledParam().

Referenced by clone(), cloneAD(), cloneNonAD(), CompiledFunction(), CompiledFunction(), and operator=().

## CompiledFunction() [2/3]

template<class T>

casacore::CompiledFunction< T >::CompiledFunction | ( | const CompiledFunction< T > & | other | ) |

inline

Make this object a (deep) copy of other.

Definition at line 136 of file CompiledFunction.h.

References CompiledFunction(), and casacore::CompiledParam< T >::CompiledParam().

## CompiledFunction() [3/3]

template<class T>
template<class W>

casacore::CompiledFunction< T >::CompiledFunction | ( | const CompiledFunction< W > & | other | ) |

inline

Definition at line 139 of file CompiledFunction.h.

References CompiledFunction(), and casacore::CompiledParam< T >::CompiledParam().

## ~CompiledFunction()

template<class T>

virtual casacore::CompiledFunction< T >::~CompiledFunction | ( |  | ) |

inline virtual

Destructor.

Definition at line 147 of file CompiledFunction.h.

## Member Function Documentation

## clone()

template<class T>

virtual Function< T > * casacore::CompiledFunction< T >::clone | ( |  | ) | const

inline virtual

Return a copy of this object from the heap.

The caller is responsible for deleting the pointer.

Implements casacore::Function< T, U >.

Definition at line 157 of file CompiledFunction.h.

References CompiledFunction().

## cloneAD()

template<class T>

virtual Function< typename FunctionTraits< T >::DiffType > * casacore::CompiledFunction< T >::cloneAD | ( |  | ) | const

inline virtual

Reimplemented from casacore::Function< T, U >.

Definition at line 159 of file CompiledFunction.h.

References CompiledFunction().

## cloneNonAD()

template<class T>

virtual Function< typename FunctionTraits< T >::BaseType > * casacore::CompiledFunction< T >::cloneNonAD | ( |  | ) | const

inline virtual

Reimplemented from casacore::Function< T, U >.

Definition at line 161 of file CompiledFunction.h.

References CompiledFunction().

## eval()

template<class T>

virtual T casacore::CompiledFunction< T >::eval | ( | typename Function< T >::FunctionArg | x | ) | const

virtual

Evaluate the function at x.

## operator=()

template<class T>

CompiledFunction< T > & casacore::CompiledFunction< T >::operator= | ( | const CompiledFunction< T > & | other | ) |

inline

Make this object a (deep) copy of other.

Definition at line 143 of file CompiledFunction.h.

References CompiledFunction(), and casacore::CompiledParam< T >::operator=().

The documentation for this class was generated from the following file:

- scimath/Functionals/CompiledFunction.h