Loading...
Searching...
No Matches
FunctionTraits.h
Go to the documentation of this file.
//# FunctionTraits.h: Function data types for parameters and arguments
//# Copyright (C) 2001,2002
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef SCIMATH_FUNCTIONTRAITS_H
#define SCIMATH_FUNCTIONTRAITS_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/scimath/Mathematics/AutoDiff.h>
#include <casacore/scimath/Mathematics/AutoDiffA.h>
#include <casacore/scimath/Mathematics/AutoDiffX.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//
// <summary> Function data types for parameters and arguments
// </summary>
// <use visibility=local>
//
// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="t">
// </reviewed>
// <prerequisite>
// <li> <linkto class="Function">Function</linkto>
// <li> <linkto class="AutoDiff">AutoDiff</linkto>
// </prerequisite>
// <etymology>
// A trait is a characteristic feature. FunctionTraits defines relationships
// between the data types of result, parameters and arguments of function
// objects.
// </etymology>
//
// <synopsis>
// This templated class contains a number of typedefs that
// describe the relationship between different numeric data types used for
// the calculation of <src>Function</src> 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 <src>AutoDiff</src> 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 <src>result = f<T>(x; parameters)</src>.
// <ol>
// <li> Simple numeric type (Double, Complex, etc): result, parameters and
// arguments: all the one defined templated type.
// <li> <src>AutoDiff<T></src> indicates the calculation (either automatic or
// with specialized implementations) of the result with a <src>T</src>
// function value for <src>T</src> arg, and <src>AutoDiff<T></src>
// parameters.
// <li> <src>AutoDiffA</src> calculate form <src>AutoDiff<T></src>
// arguments and parameters (note that either could be simple
// values with zero derivatives)
// <li> <src>AutoDiffX<T></src> : calculate only with respect to
// the arguments the derivatives, by using <src>T</src>
// parameters
// </ol>
// The following types are defined:
// <dl>
// <dt> <src>Type</src>
// <dd> The template argument
// <dt> <src>BaseType</src>
// <dd> One down in the template hierarchy if possible (e.g. <src>Double</src>
// for <src>AutoDiff<Double></src>)
// <dt> <src>NumericType</src>
// <dd> Ultimate numeric type (e.g. <src>Double</src> for
// <src>AutoDiff<AutoDiff<Double> ></src>
// <dt> <src>ParamType</src>
// <dd> Type used for parameters
// <dt> <src>ArgType</src>
// <dd> Type used for arguments
// <dt> <src>DiffType</src>
// <dd> The default differentiation type (e.g. <src>AutoDiff<Double></src>
// for <src>AutoDiff<Double></src>)
// <dt> <src>getValue()</src>
// <dd> get the value of a simple numeric or of an <src>AutoDiff</src>
// <dt> <src>setValue()</src>
// <dd> set the value of a simple numeric or of an <src>AutoDiff</src>
// </dl>
//
// The specializations are done in such a way that higher order
// derivatives (e.g. <src>AutoDiff<AutoDiff<Double> ></src>) are catered for.
//
// Note that the class names in the following definitions are extended with
// some individual id (like <src>_PA</src>): do not use them in programming,
// they are only necessary for the <src>cxx2html</src> interpreter)
//
// This class is implemented as a number of specializations for the
// following data types.
// <ul>
// <li> <src>T</src>
// <li> <src>AutoDiff<T></src>
// <li> <src>AutoDiffA<T></src>
// <li> <src>AutoDiffX<T></src>
// </ul>
// </synopsis>
//
// <example>
// See the <linkto class=Function>Function</linkto> class code.
// </example>
//
// <motivation>
// To keep the Function class single templated
// </motivation>
//
// <todo asof="2002/06/19">
// <li> Additional <src>AutoDiff*</src> classes if and when needed
// </todo>
//
template <class T> class FunctionTraits {
public:
// Actual template type
typedef T Type;
// Template base type
typedef T BaseType;
// Numeric type of template
typedef T NumericType;
// Type for parameters
typedef T ParamType;
// Type for arguments
typedef T ArgType;
// Default type for differentiation
typedef AutoDiff<T> DiffType;
// Get the value
static const T &getValue(const T &in) { return in; }
// Set a value (and possible derivative)
static void setValue(T &out, const T &val, const uInt,
const uInt) { out = val; }
};
//# Following are specializations. Naming only for documentation
//# purposes (a problem with cxx2html)
#define FunctionTraits_P FunctionTraits
// <summary> FunctionTraits specialization for AutoDiff
// </summary>
template <class T> class FunctionTraits_P<AutoDiff<T> > {
public:
// Actual template type
typedef AutoDiff<T> Type;
// Template base type
typedef T BaseType;
// Template numeric type
typedef typename FunctionTraits_P<T>::NumericType NumericType;
// Type for parameters
typedef AutoDiff<T> ParamType;
// Type for arguments
typedef T ArgType;
// Default type for differentiation
typedef AutoDiff<T> DiffType;
// Get the value
static const T &getValue(const Type &in) {
return FunctionTraits<T>::getValue(in.value()); }
// Set a value (and possible derivative)
static void setValue(Type &out, const T &val, const uInt nder,
const uInt i) { out = Type(val, nder, i); }
};
#undef FunctionTraits_P
#define FunctionTraits_PA FunctionTraits
// <summary> FunctionTraits specialization for AutoDiffA
// </summary>
template <class T> class FunctionTraits_PA<AutoDiffA<T> > {
public:
// Actual template type
typedef AutoDiffA<T> Type;
// Template base type
typedef T BaseType;
// Template numeric type
typedef typename FunctionTraits_PA<T>::NumericType NumericType;
// Type for parameters
typedef AutoDiffA<T> ParamType;
// Type for arguments
typedef AutoDiffA<T> ArgType;
// Default type for differentiation
typedef AutoDiffA<T> DiffType;
// Get the value
static const T &getValue(const Type &in) {
return FunctionTraits<T>::getValue(in.value()); }
// Set a value (and possible derivative)
static void setValue(Type &out, const T &val, const uInt nder,
const uInt i) { out = Type(val, nder, i); }
};
#undef FunctionTraits_PA
#define FunctionTraits_PX FunctionTraits
// <summary> FunctionTraits specialization for AutoDiffX
// </summary>
template <class T> class FunctionTraits_PX<AutoDiffX<T> > {
public:
// Actual template type
typedef AutoDiffX<T> Type;
// Template base type
typedef T BaseType;
// Template numeric type
typedef typename FunctionTraits_PX<T>::NumericType NumericType;
// Type for parameters
typedef T ParamType;
// Type for arguments
typedef AutoDiffX<T> ArgType;
// Default type for differentiation
typedef AutoDiffX<T> DiffType;
// Get the value
static const T &getValue(const Type &in) {
return FunctionTraits<T>::getValue(in.value()); }
// Set a value (and possible derivative)
static void setValue(Type &out, const T &val, const uInt nder,
const uInt i) { out = Type(val, nder, i); }
};
#undef FunctionTraits_PX
} //# NAMESPACE CASACORE - END
#endif
FunctionTraits_PA
#define FunctionTraits_PA
Definition FunctionTraits.h:190
FunctionTraits_P
#define FunctionTraits_P
Definition FunctionTraits.h:161
FunctionTraits_PX
#define FunctionTraits_PX
Definition FunctionTraits.h:219
casacore::AutoDiffA
Definition AutoDiffA.h:116
casacore::AutoDiffX
Definition AutoDiffX.h:116
casacore::AutoDiff
Definition AutoDiff.h:254
casacore::AutoDiff::value
T & value()
Returns the value of the function.
Definition AutoDiff.h:310
casacore::FunctionTraits_PA< AutoDiffA< T > >::BaseType
T BaseType
Template base type.
Definition FunctionTraits.h:200
casacore::FunctionTraits_PA< AutoDiffA< T > >::ArgType
AutoDiffA< T > ArgType
Type for arguments.
Definition FunctionTraits.h:206
casacore::FunctionTraits_PA< AutoDiffA< T > >::setValue
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative).
Definition FunctionTraits.h:213
casacore::FunctionTraits_PA< AutoDiffA< T > >::getValue
static const T & getValue(const Type &in)
Get the value.
Definition FunctionTraits.h:210
casacore::FunctionTraits_PA< AutoDiffA< T > >::DiffType
AutoDiffA< T > DiffType
Default type for differentiation.
Definition FunctionTraits.h:208
casacore::FunctionTraits_PA< AutoDiffA< T > >::Type
AutoDiffA< T > Type
Actual template type.
Definition FunctionTraits.h:198
casacore::FunctionTraits_PA< AutoDiffA< T > >::ParamType
AutoDiffA< T > ParamType
Type for parameters.
Definition FunctionTraits.h:204
casacore::FunctionTraits_PA< AutoDiffA< T > >::NumericType
FunctionTraits_PA< T >::NumericType NumericType
Template numeric type.
Definition FunctionTraits.h:202
casacore::FunctionTraits_PX< AutoDiffX< T > >::getValue
static const T & getValue(const Type &in)
Get the value.
Definition FunctionTraits.h:239
casacore::FunctionTraits_PX< AutoDiffX< T > >::Type
AutoDiffX< T > Type
Actual template type.
Definition FunctionTraits.h:227
casacore::FunctionTraits_PX< AutoDiffX< T > >::ParamType
T ParamType
Type for parameters.
Definition FunctionTraits.h:233
casacore::FunctionTraits_PX< AutoDiffX< T > >::BaseType
T BaseType
Template base type.
Definition FunctionTraits.h:229
casacore::FunctionTraits_PX< AutoDiffX< T > >::DiffType
AutoDiffX< T > DiffType
Default type for differentiation.
Definition FunctionTraits.h:237
casacore::FunctionTraits_PX< AutoDiffX< T > >::NumericType
FunctionTraits_PX< T >::NumericType NumericType
Template numeric type.
Definition FunctionTraits.h:231
casacore::FunctionTraits_PX< AutoDiffX< T > >::ArgType
AutoDiffX< T > ArgType
Type for arguments.
Definition FunctionTraits.h:235
casacore::FunctionTraits_PX< AutoDiffX< T > >::setValue
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative).
Definition FunctionTraits.h:242
casacore::FunctionTraits_P< AutoDiff< T > >::Type
AutoDiff< T > Type
Actual template type.
Definition FunctionTraits.h:169
casacore::FunctionTraits_P< AutoDiff< T > >::setValue
static void setValue(Type &out, const T &val, const uInt nder, const uInt i)
Set a value (and possible derivative).
Definition FunctionTraits.h:184
casacore::FunctionTraits_P< AutoDiff< T > >::DiffType
AutoDiff< T > DiffType
Default type for differentiation.
Definition FunctionTraits.h:179
casacore::FunctionTraits_P< AutoDiff< T > >::ArgType
T ArgType
Type for arguments.
Definition FunctionTraits.h:177
casacore::FunctionTraits_P< AutoDiff< T > >::getValue
static const T & getValue(const Type &in)
Get the value.
Definition FunctionTraits.h:181
casacore::FunctionTraits_P< AutoDiff< T > >::ParamType
AutoDiff< T > ParamType
Type for parameters.
Definition FunctionTraits.h:175
casacore::FunctionTraits_P< AutoDiff< T > >::BaseType
T BaseType
Template base type.
Definition FunctionTraits.h:171
casacore::FunctionTraits_P< AutoDiff< T > >::NumericType
FunctionTraits_P< T >::NumericType NumericType
Template numeric type.
Definition FunctionTraits.h:173
casacore::FunctionTraits
Definition FunctionTraits.h:137
casacore::FunctionTraits::setValue
static void setValue(T &out, const T &val, const uInt, const uInt)
Set a value (and possible derivative).
Definition FunctionTraits.h:154
casacore::ArgType::DiffType
AutoDiff< T > DiffType
Definition FunctionTraits.h:150
casacore::ArgType::ArgType
T ArgType
Definition FunctionTraits.h:148
casacore::ArgType::Type
T Type
Definition FunctionTraits.h:140
casacore::ArgType::BaseType
T BaseType
Definition FunctionTraits.h:142
casacore::ArgType::ParamType
T ParamType
Definition FunctionTraits.h:146
casacore::ArgType::NumericType
T NumericType
Definition FunctionTraits.h:144
casacore::FunctionTraits::getValue
static const T & getValue(const T &in)
Get the value.
Definition FunctionTraits.h:152
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uInt
unsigned int uInt
Definition aipstype.h:49