casa
$Rev:20696$
|
00001 //# EvenPolynomial.h: A one dimensional even 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: EvenPolynomial.h 21024 2011-03-01 11:46:18Z gervandiepen $ 00027 00028 #ifndef SCIMATH_EVENPOLYNOMIAL_H 00029 #define SCIMATH_EVENPOLYNOMIAL_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <scimath/Functionals/EvenPolynomialParam.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 // An EvenPolynomial<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 // EvenPolynomial<Float> pf(3); // Second order polynomial - coeffs 0 by default 00064 // pf.setCoefficient(0, 1.0); 00065 // pf[1] = 2.0; // 2x^2 + 1x^0 00066 // pf(2); // == 8 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 of 00082 // </todo> 00083 00084 template<class T> class EvenPolynomial: public EvenPolynomialParam<T> 00085 { 00086 public: 00087 //# Enumerations 00088 00089 //# Constructors 00090 // Constructs a zeroth order polynomial, with a coeficcient of 0.0. 00091 EvenPolynomial() : EvenPolynomialParam<T>() {} 00092 // Makes a polynomial of the given order, with all coeficcients set to 00093 // zero. 00094 explicit EvenPolynomial(uInt order) : EvenPolynomialParam<T>(order) {} 00095 // Copy constructor/assignment (deep copy) 00096 // <group> 00097 EvenPolynomial(const EvenPolynomial<T> &other) : 00098 EvenPolynomialParam<T>(other) {} 00099 template <class W> 00100 EvenPolynomial(const EvenPolynomial<W> &other) : 00101 EvenPolynomialParam<T>(other) {} 00102 EvenPolynomial<T> &operator=(const EvenPolynomial<T> &other) { 00103 EvenPolynomialParam<T>::operator=(other); return *this; } 00104 // </group> 00105 00106 // Destructor 00107 virtual ~EvenPolynomial() {} 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 EvenPolynomial<T>(*this); } 00118 virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const { 00119 return new EvenPolynomial<typename FunctionTraits<T>::DiffType>(*this); } 00120 virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const { 00121 return new EvenPolynomial<typename FunctionTraits<T>::BaseType>(*this); } 00122 // </group> 00123 00124 //# Make members of parent classes known. 00125 protected: 00126 using EvenPolynomialParam<T>::param_p; 00127 public: 00128 using EvenPolynomialParam<T>::nparameters; 00129 }; 00130 00131 #define EvenPolynomial_PS EvenPolynomial 00132 00133 // <summary> Partial specialization of EvenPolynomial for <src>AutoDiff</src> 00134 // </summary> 00135 00136 // <synopsis> 00137 // <note role=warning> The name <src>EvenPolynomial_PS</src> is only for cxx2html 00138 // documentation problems. Use <src>EvenPolynomial</src> in your code.</note> 00139 // </synopsis> 00140 00141 template <class T> class EvenPolynomial_PS<AutoDiff<T> > : 00142 public EvenPolynomialParam<AutoDiff<T> > 00143 { 00144 public: 00145 //# Constructors 00146 // Constructs one dimensional EvenPolynomials. 00147 // <group> 00148 EvenPolynomial_PS() : EvenPolynomialParam<AutoDiff<T> >() {} 00149 explicit EvenPolynomial_PS(uInt order) : 00150 EvenPolynomialParam<AutoDiff<T> >(order) {} 00151 // </group> 00152 00153 // Copy constructor (deep copy) 00154 // <group> 00155 EvenPolynomial_PS(const EvenPolynomial_PS<AutoDiff<T> > &other) : 00156 EvenPolynomialParam<AutoDiff<T> >(other) {} 00157 template <class W> 00158 EvenPolynomial_PS(const EvenPolynomial_PS<W> &other) : 00159 EvenPolynomialParam<AutoDiff<T> >(other) {} 00160 // </group> 00161 // Copy assignment (deep copy) 00162 EvenPolynomial_PS<AutoDiff<T> > & 00163 operator=(const EvenPolynomial_PS<AutoDiff<T> > &other) { 00164 EvenPolynomialParam<AutoDiff<T> >::operator=(other); return *this; } 00165 00166 // Destructor 00167 virtual ~EvenPolynomial_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 EvenPolynomial<AutoDiff<T> >(*this); } 00182 virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType> 00183 *cloneAD() const { 00184 return new EvenPolynomial<typename FunctionTraits<AutoDiff<T> >::DiffType> 00185 (*this); } 00186 virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType> 00187 *cloneNonAD() const { 00188 return new EvenPolynomial<typename FunctionTraits<AutoDiff<T> >::BaseType> 00189 (*this); } 00190 // </group> 00191 00192 //# Make members of parent classes known. 00193 protected: 00194 using EvenPolynomialParam<AutoDiff<T> >::param_p; 00195 public: 00196 using EvenPolynomialParam<AutoDiff<T> >::nparameters; 00197 }; 00198 00199 #undef EvenPolynomial_PS 00200 00201 00202 } //# NAMESPACE CASA - END 00203 00204 #ifndef CASACORE_NO_AUTO_TEMPLATES 00205 #include <scimath/Functionals/EvenPolynomial.tcc> 00206 #include <scimath/Functionals/EvenPolynomial2.tcc> 00207 #endif //# CASACORE_NO_AUTO_TEMPLATES 00208 #endif