FunctionTraits.h
Classes
- FunctionTraits -- Function data types for parameters and arguments (full description)
- FunctionTraits_P -- FunctionTraits specialization for AutoDiff (full description)
- FunctionTraits_PA -- FunctionTraits specialization for AutoDiffA (full description)
- FunctionTraits_PX -- FunctionTraits specialization for AutoDiffX (full description)
Interface
- Public Members
- static const T &getValue(const T &in)
- static void setValue(T &out, const T &val, const uInt, const uInt)
Review Status
- Reviewed By:
- UNKNOWN
- Date Reviewed:
- before2004/08/25
- Programs:
- Tests:
Prerequisite
Etymology
A trait is a characteristic feature. FunctionTraits defines relationships
between the data types of result, parameters and arguments of function
objects.
Synopsis
This templated class contains a number of typedefs that
describe the relationship between different numeric data types used for
the calculation of Function and the function parameter and
arguments.
Its main use is to optimize the speed of the calculation of function
values and derivatives in the case of AutoDiff use and
manual calculation of derivatives, by allowing the data type of the
the arguments and/or parameters to be plain numeric in cases where the
derivatives wrt these are not needed.
To enable this, the following definitions are used for the use of the
Function template. Bear in mind that the Function operator is defined
as result = f<T>(x; parameters).
- Simple numeric type (Double, Complex, etc): result, parameters and
arguments: all the one defined templated type.
- AutoDiff<T> indicates the calculation (either automatic or
with specialized implementations) of the result with a T
function value for T arg, and AutoDiff<T>
parameters.
- AutoDiffA calculate form AutoDiff<T>
arguments and parameters (note that either could be simple
values with zero derivatives)
- AutoDiffX<T> : calculate only with respect to
the arguments the derivatives, by using T
parameters
The following types are defined:
- Type
- The template argument
- BaseType
- One down in the template hierarchy if possible (e.g. Double
for AutoDiff<Double>)
- NumericType
- Ultimate numeric type (e.g. Double for
AutoDiff<AutoDiff<Double> >
- ParamType
- Type used for parameters
- ArgType
- Type used for arguments
- DiffType
- The default differentiation type (e.g. AutoDiff<Double>
for AutoDiff<Double>)
- getValue()
- get the value of a simple numeric or of an AutoDiff
- setValue()
- set the value of a simple numeric or of an AutoDiff
The specializations are done in such a way that higher order
derivatives (e.g. AutoDiff<AutoDiff<Double> >) are catered for.
Note that the class names in the following definitions are extended with
some individual id (like _PA): do not use them in programming,
they are only necessary for the cxx2html interpreter)
Example
See the Function class code.
Motivation
To keep the Function class single templated
Template Type Argument Requirements (T)
This class is implemented as a number of specializations for the
following data types.
- T
- AutoDiff<T>
- AutoDiffA<T>
- AutoDiffX<T>
To Do
- Additional AutoDiff* classes if and when needed
Member Description
static const T &getValue(const T &in)
Get the value
static void setValue(T &out, const T &val, const uInt, const uInt)
Set a value (and possible derivative)
template <class T> class FunctionTraits_P<AutoDiff<T> >
Interface
- static const T &getValue(const Type &in)
- static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Member Description
static const T &getValue(const Type &in)
Get the value
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative)
template <class T> class FunctionTraits_PA<AutoDiffA<T> >
Interface
- static const T &getValue(const Type &in)
- static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Member Description
static const T &getValue(const Type &in)
Get the value
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative)
template <class T> class FunctionTraits_PX<AutoDiffX<T> >
Interface
- static const T &getValue(const Type &in)
- static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Member Description
static const T &getValue(const Type &in)
Get the value
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative)