casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ConstantND.h
Go to the documentation of this file.
00001 //# HyperPlane.h: Form a hyper plane function
00002 //# Copyright (C) 2001,2002,2004,2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: HyperPlane.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef SCIMATH_CONSTANT_H
00030 #define SCIMATH_CONSTANT_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <scimath/Functionals/ConstantNDParam.h>
00035 #include <scimath/Functionals/Function.h>
00036 #include <scimath/Mathematics/AutoDiff.h>
00037 #include <scimath/Mathematics/AutoDiffMath.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 // <summary> A constant function.
00042 // </summary>
00043 //
00044 // <use visibility=export>
00045 // <reviewed reviewer="" date="" tests="tConstant" demos="">
00046 // </reviewed>
00047 //
00048 // <prerequisite>
00049 //   <li> <linkto class=Function>Function</linkto>
00050 // </prerequisite>
00051 //
00052 // <synopsis>
00053 // This class represents a constant function in a space
00054 // of arbitrary dimension
00055 // f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) = constant
00056 // where x<sub>i</sub>
00057 // are independent arguments and m is the number of dimensions of the space.
00058 //
00059 //
00060 // Since the <src>Constant</src> is a <src>Function</src>, the derivatives
00061 // can be obtained as well (and are in fact 0 of course).
00062 //
00063 // The parameter interface (see 
00064 // <linkto class="FunctionParam">FunctionParam</linkto> class), 
00065 // is used to provide an interface to the
00066 // <linkto module="Fitting">Fitting</linkto> classes. 
00067 //
00068 // This class is in general used implicitly by the <src>Constant</src>
00069 // class only.
00070 // </synopsis>
00071 //
00072 // <example>
00073 // <srcblock>
00074 // // form the constant function in 4-D space
00075 //  Constant<Double> constant(4); // 4-dim hyperplane
00076 //  constant.parameters()[0] = 22;
00077 //  // Evaluate at x0=5, x3=7
00078 //  Vector<Double> x(4);
00079 //  x=0; x[0]=5; x[3]=7;
00080 //  cout << "constant value: " << constant(x) << endl;
00081 //  constant value: 22
00082 // </srcblock>
00083 // </example>
00084 
00085 // <templating arg=T>
00086 //  <li> T should have standard numerical operators. Current
00087 //      implementation only tested for real types (and their AutoDiffs).
00088 // </templating>
00089 
00090 // <thrown>
00091 //    <li> Assertion in debug mode if attempt is made to address incorrect
00092 //         coefficients
00093 // </thrown>
00094 
00095 // <motivation>
00096 // This class was created because HyperPlane does not support a constant
00097 // offset and modifying that class really required an interface change
00098 // (ie that the constant offset be at the beginning of the parameter vector
00099 // and that the parameter vector increase by one) so rather than breaking
00100 // any code that already used HyperPlane I simply made a trivial Constant
00101 // class.
00102 // </motivation>
00103 //
00104 // <todo asof="2011/07/01">
00105 //  <li> Nothing I know of
00106 // </todo>
00107 
00108 template<class T> class ConstantND : public ConstantNDParam<T>
00109 {
00110 public:
00111   //# Constructors
00112   // Construct a constant in an a space of dimensionality <src>m</src>.  By
00113   // default, the constant value is initialised to zero, and <src>m=0</src>
00114   explicit ConstantND(const uInt m=0) : ConstantNDParam<T>(m) {;};
00115   // Copy constructor/assignment (deep copy)
00116   // <group>
00117   ConstantND(const ConstantND<T> &other) : ConstantNDParam<T>(other) {};
00118   template <class W>
00119     ConstantND(const ConstantND<W> &other) : ConstantNDParam<T>(other) {}
00120   ConstantND<T> &operator=(const ConstantND<T> &other) {
00121     ConstantNDParam<T>::operator=(other); return *this; };
00122   // </group>
00123 
00124   // Destructor
00125   virtual ~ConstantND() {};
00126 
00127   //# Operators    
00128   // Evaluate the hyper plane function at
00129   // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
00130   virtual T eval(typename Function<T>::FunctionArg x) const;
00131   
00132   // Return a copy of this object from the heap. The caller is responsible for
00133   // deleting the pointer.
00134   // <group>
00135   virtual Function<T> *clone() const { return new ConstantND<T>(*this); };
00136   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00137     return new ConstantND<typename FunctionTraits<T>::DiffType>(*this); };
00138   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00139     return new ConstantND<typename FunctionTraits<T>::BaseType>(*this); };
00140   // </group>
00141 
00142   //# Make members of parent classes known.
00143 protected:
00144   using ConstantNDParam<T>::param_p;
00145 public:
00146   using ConstantNDParam<T>::nparameters;
00147 };
00148 
00149 
00150 #define ConstantND_PS ConstantND
00151 
00152 // <summary> Partial specialization of ConstantND for <src>AutoDiff</src>
00153 // </summary>
00154 
00155 // <synopsis>
00156 // <note role=warning> The name <src>HyperPlane_PS</src> is only for cxx2html
00157 // documentation problems. Use <src>HyperPlane</src> in your code.</note>
00158 // </synopsis>
00159 
00160 template <class T> class ConstantND_PS<AutoDiff<T> > :
00161 public ConstantNDParam<AutoDiff<T> >
00162 {
00163 public:
00164   //# Construct
00165   // Constructors a constant in a space of dimensionality <src>m</src>.  By
00166   // default, the coefficients are initialized to zero, and <src>m=0</src>
00167   explicit ConstantND_PS(const uInt m=0) :
00168     ConstantNDParam<AutoDiff<T> >(m) {};
00169   // Copy constructor/assignment (deep copy)
00170   // <group>
00171   ConstantND_PS(const ConstantND_PS<AutoDiff<T> > &other) :
00172     ConstantNDParam<AutoDiff<T> >(other) {};
00173   template <class W>
00174     ConstantND_PS(const ConstantND_PS<W> &other) :
00175     ConstantNDParam<AutoDiff<T> >(other) {}
00176   ConstantND_PS<AutoDiff<T> > &
00177     operator=(const ConstantND_PS<AutoDiff<T> > &other) {
00178     ConstantNDParam<AutoDiff<T> >::operator=(other); return *this; };
00179   // </group>
00180   
00181   // Destructor
00182   virtual ~ConstantND() {};
00183   
00184   //# Operators    
00185   // Evaluate the constant function at
00186   // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
00187   virtual AutoDiff<T> 
00188     eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
00189   
00190   // Return a copy of this object from the heap. The caller is responsible for
00191   // deleting the pointer.
00192   // <group>
00193   virtual Function<AutoDiff<T> > *clone() const {
00194     return new ConstantND_PS<AutoDiff<T> >(*this); };
00195   virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType>
00196     *cloneAD() const {
00197     return new ConstantND<typename FunctionTraits<AutoDiff<T> >::DiffType>
00198       (*this); };
00199   virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType>
00200     *cloneNonAD() const {
00201     return new ConstantND<typename FunctionTraits<AutoDiff<T> >::BaseType>
00202       (*this); };
00203   // </group>
00204 
00205   //# Make members of parent classes known.
00206 protected:
00207   using ConstantNDParam<AutoDiff<T> >::param_p;
00208 public:
00209   using ConstantNDParam<AutoDiff<T> >::nparameters;
00210 };
00211 
00212 #undef ConstantND_PS
00213 
00214 
00215 } //# NAMESPACE CASA - END
00216 
00217 #ifndef CASACORE_NO_AUTO_TEMPLATES
00218 #include <scimath/Functionals/ConstantND.tcc>
00219 #endif //# CASACORE_NO_AUTO_TEMPLATES
00220 #endif