casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
OddPolynomial.h
Go to the documentation of this file.
00001 //# OddPolynomial.h: A one dimensional odd polynomial class
00002 //# Copyright (C) 2002,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 //# $Id: OddPolynomial.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_ODDPOLYNOMIAL_H
00029 #define SCIMATH_ODDPOLYNOMIAL_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/OddPolynomialParam.h>
00034 #include <scimath/Functionals/Function1D.h>
00035 #include <scimath/Mathematics/AutoDiff.h>
00036 #include <scimath/Mathematics/AutoDiffMath.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward declarations
00041 
00042 // <summary> A one dimensional odd polynomial class
00043 // </summary>
00044 
00045 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tSpecialPolynomial"
00046 // demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class=Function>Function</linkto>
00051 // </prerequisite>
00052 //
00053 // <synopsis> 
00054 // A OddPolynomial<T> contains a set of coefficients;
00055 // its fundamental operation is evaluating itself at some "x".
00056 // The number of coefficients is the order of the polynomial divided by two,
00057 // plus one, so is the number of available parameters. 
00058 //
00059 // </synopsis> 
00060 //
00061 // <example>
00062 // <srcblock>
00063 //  OddPolynomial<Float> pf(3);  // Third order polynomial - coeffs 0 by default
00064 //  pf.setCoefficient(0, 1.0);
00065 //  pf[1] = 2.0;                // 2x^3 + 1x^1
00066 //  pf(2); // == 18
00067 // </srcblock>
00068 // </example>
00069 
00070 // <templating arg=T>
00071 //  <li> T should have standard numerical operators. Current
00072 //      implementation only tested for real types (and their AutoDiffs).
00073 // </templating>
00074 
00075 // <thrown>
00076 //    <li> Assertion in debug mode if attempt is made to address incorrect
00077 //              coefficients
00078 // </thrown>
00079 
00080 // <todo asof="2002/02/26">
00081 //   <li> Nothing I know off
00082 // </todo>
00083 
00084 template<class T> class OddPolynomial: public OddPolynomialParam<T>
00085 {
00086 public:
00087   //# Enumerations
00088   
00089   //# Constructors
00090   // Constructs a first order polynomial, with a coeficcient of 0.0.
00091   OddPolynomial() : OddPolynomialParam<T>() {}
00092   // Makes a polynomial of the given order, with all coeficcients set to
00093   // zero. 
00094   explicit OddPolynomial(uInt order) : OddPolynomialParam<T>(order) {}
00095   // Copy constructor/assignment (deep copy)
00096   // <group>
00097   OddPolynomial(const OddPolynomial<T> &other) :
00098     OddPolynomialParam<T>(other) {}
00099   template <class W>
00100     OddPolynomial(const OddPolynomial<W> &other) :
00101     OddPolynomialParam<T>(other) {}
00102   OddPolynomial<T> &operator=(const OddPolynomial<T> &other) {
00103     OddPolynomialParam<T>::operator=(other); return *this; }
00104   // </group>
00105   
00106   // Destructor
00107   virtual ~OddPolynomial() {}
00108   
00109   //# Operators    
00110   // Evaluate the polynomial at <src>x</src>.
00111   virtual T eval(typename Function1D<T>::FunctionArg x) const;
00112   
00113   //# Member functions
00114   // Return a copy of this object from the heap. The caller is responsible for
00115   // deleting the pointer.
00116   // <group>
00117   virtual Function<T> *clone() const { return new OddPolynomial<T>(*this); }
00118   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00119     return new OddPolynomial<typename FunctionTraits<T>::DiffType>(*this); }
00120   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00121     return new OddPolynomial<typename FunctionTraits<T>::BaseType>(*this); }
00122   // </group>
00123 
00124   //# Make members of parent classes known.
00125 protected:
00126   using OddPolynomialParam<T>::param_p;
00127 public:
00128   using OddPolynomialParam<T>::nparameters;
00129 };
00130 
00131 #define OddPolynomial_PS OddPolynomial
00132 
00133 // <summary> Partial specialization of OddPolynomial for <src>AutoDiff</src>
00134 // </summary>
00135 
00136 // <synopsis>
00137 // <note role=warning> The name <src>OddPolynomial_PS</src> is only for cxx2html
00138 // documentation problems. Use <src>OddPolynomial</src> in your code.</note>
00139 // </synopsis>
00140 
00141 template <class T> class OddPolynomial_PS<AutoDiff<T> > : 
00142 public OddPolynomialParam<AutoDiff<T> >
00143 {
00144 public:
00145   //# Constructors
00146   // Constructs one dimensional OddPolynomials.
00147   // <group>
00148   OddPolynomial_PS() : OddPolynomialParam<AutoDiff<T> >() {}
00149   explicit OddPolynomial_PS(uInt order) :
00150     OddPolynomialParam<AutoDiff<T> >(order) {}
00151   // </group>
00152 
00153   // Copy constructor (deep copy)
00154   // <group>
00155   OddPolynomial_PS(const OddPolynomial_PS<AutoDiff<T> > &other) :
00156   OddPolynomialParam<AutoDiff<T> >(other) {}
00157   template <class W>
00158     OddPolynomial_PS(const OddPolynomial_PS<W> &other) :
00159     OddPolynomialParam<AutoDiff<T> >(other) {}
00160   // </group>
00161   // Copy assignment (deep copy)
00162   OddPolynomial_PS<AutoDiff<T> > &
00163     operator=(const OddPolynomial_PS<AutoDiff<T> > &other) {
00164     OddPolynomialParam<AutoDiff<T> >::operator=(other); return *this; }
00165     
00166   // Destructor
00167   virtual ~OddPolynomial_PS() {}
00168 
00169   //# Operators    
00170   // Evaluate the polynomial and its derivatives at <src>x</src> <em>wrt</em>
00171   // to the coefficients.
00172   // <group>
00173   virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
00174   // </group>
00175 
00176   //# Member functions
00177   // Return a copy of this object from the heap. The caller is responsible 
00178   // for deleting this pointer.
00179   // <group>
00180   virtual Function<AutoDiff<T> > *clone() const {
00181     return new OddPolynomial<AutoDiff<T> >(*this); }
00182   virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType>
00183     *cloneAD() const {
00184     return new OddPolynomial<typename FunctionTraits<AutoDiff<T> >::DiffType>
00185       (*this); }
00186   virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType>
00187     *cloneNonAD() const {
00188     return new OddPolynomial<typename FunctionTraits<AutoDiff<T> >::BaseType>
00189       (*this); }
00190   // </group>
00191 
00192   //# Make members of parent classes known.
00193 protected:
00194   using OddPolynomialParam<AutoDiff<T> >::param_p;
00195 public:
00196   using OddPolynomialParam<AutoDiff<T> >::nparameters;
00197 };
00198 
00199 #undef OddPolynomial_PS
00200 
00201 
00202 } //# NAMESPACE CASA - END
00203 
00204 #ifndef CASACORE_NO_AUTO_TEMPLATES
00205 #include <scimath/Functionals/OddPolynomial.tcc>
00206 #include <scimath/Functionals/OddPolynomial2.tcc>
00207 #endif //# CASACORE_NO_AUTO_TEMPLATES
00208 #endif