casacore
Loading...
Searching...
No Matches
Polynomial.h
Go to the documentation of this file.
1//# Polynomial.h: A one dimensional polynomial class
2//# Copyright (C) 1994,1995,1996,2001,2002,2005
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_POLYNOMIAL_H
27#define SCIMATH_POLYNOMIAL_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/PolynomialParam.h>
32#include <casacore/scimath/Functionals/Function1D.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34#include <casacore/scimath/Mathematics/AutoDiffMath.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward declarations
39
40// <summary> A one dimensional polynomial class
41// </summary>
42
43// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tPolynomial"
44// demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class=Function>Function</linkto>
49// </prerequisite>
50//
51// <synopsis>
52// A Polynomial<T> contains a set of coefficients; its fundamental operations
53// is evaluating itself at some "x". The number of coefficients is the order
54// of the polynomial plus one, so is the number of available parameters.
55//
56// <note role=tip>
57// The present implementation merely stores the coefficients in a Block. In the
58// unlikely case that we need to deal with polynomials with many zero
59// coefficients, a more efficient representation would be possible.
60// </note>
61// </synopsis>
62//
63// <example>
64// <srcblock>
65// Polynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
66// pf.setCoefficient(1, 1.0);
67// pf[2] = 2.0;
68// pf.setCoefficient(3, 3.0); // 3x^3 + 2x^2 + x
69// pf(2); // == 34
70// </srcblock>
71// </example>
72
73// <templating arg=T>
74// <li> T should have standard numerical operators. Current
75// implementation only tested for real types (and their AutoDiffs).
76// </templating>
77
78// <thrown>
79// <li> Assertion in debug mode if attempt is made to address incorrect
80// coefficients
81// </thrown>
82
83// <todo asof="1995/08/25">
84// <li> Global functions to make various ``special'' polynomials of various
85// orders will be useful eventually.
86// </todo>
87
88template<class T> class Polynomial: public PolynomialParam<T> {
89public:
90 //# Enumerations
91
92 //# Constructors
93 // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
95 // Makes a polynomial of the given order, with all coeficcients set to
96 // zero.
98 // Copy constructor/assignment (deep copy)
99 // <group>
100 Polynomial(const Polynomial<T> &other) : PolynomialParam<T>(other) {}
101 template <class W>
102 Polynomial(const Polynomial<W> &other) : PolynomialParam<T>(other) {}
104 PolynomialParam<T>::operator=(other); return *this; }
105 // </group>
106
107 // Destructor
108 virtual ~Polynomial() {}
109
110 //# Operators
111 // Evaluate the polynomial at <src>x</src>.
112 virtual T eval(typename Function1D<T>::FunctionArg x) const;
113
114 //# Member functions
115 // Return the polynomial which is the derivative of this one. <em>e.g.,</em>
116 // <src> 2+4x+5x^2 --> 0+4+10x </src>.
118
119 // Return a copy of this object from the heap. The caller is responsible for
120 // deleting the pointer.
121 // <group>
122 virtual Function<T> *clone() const { return new Polynomial<T>(*this); }
127 // </group>
128
129 //# Make members of parent classes known.
130protected:
132public:
134 using PolynomialParam<T>::order;
135
136};
137
138#define Polynomial_PS Polynomial
139
140// <summary> Partial specialization of Polynomial for <src>AutoDiff</src>
141// </summary>
142
143// <synopsis>
144// <note role=warning> The name <src>Polynomial_PS</src> is only for cxx2html
145// documentation problems. Use <src>Polynomial</src> in your code.</note>
146// </synopsis>
148template <class T> class Polynomial_PS<AutoDiff<T> > :
149public PolynomialParam<AutoDiff<T> > {
150public:
151 //# Constructors
152 // Constructs one dimensional Polynomials.
153 // <group>
155 explicit Polynomial_PS(uInt order) :
156 PolynomialParam<AutoDiff<T> >(order) {}
157 // </group>
158
159 // Copy constructor (deep copy)
160 // <group>
161 Polynomial_PS(const Polynomial_PS<AutoDiff<T> > &other) :
162 PolynomialParam<AutoDiff<T> >(other) {}
163 template <class W>
164 Polynomial_PS(const Polynomial_PS<W> &other) :
165 PolynomialParam<AutoDiff<T> >(other) {}
166 // </group>
167
168 // Copy assignment (deep copy)
169 Polynomial_PS<AutoDiff<T> > &
170 operator=(const Polynomial_PS<AutoDiff<T> > &other) {
171 PolynomialParam<AutoDiff<T> >::operator=(other); return *this; }
172
173 // Destructor
174 virtual ~Polynomial_PS() {}
175
176 //# Operators
177 // Evaluate the polynomial and its derivatives at <src>x</src> <em>wrt</em>
178 // to the coefficients.
179 // <group>
180 virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
181 // </group>
182
183 //# Member functions
184 // Return a copy of this object from the heap. The caller is responsible
185 // for deleting this pointer.
186 // <group>
187 virtual Function<AutoDiff<T> > *clone() const {
188 return new Polynomial<AutoDiff<T> >(*this); }
190 *cloneAD() const {
192 (*this); }
194 *cloneNonAD() const {
196 (*this); }
197 // </group>
198
199 //# Make members of parent classes known.
200protected:
201 using PolynomialParam<AutoDiff<T> >::param_p;
202public:
203 using PolynomialParam<AutoDiff<T> >::nparameters;
204 using PolynomialParam<AutoDiff<T> >::order;
205};
206
207#undef Polynomial_PS
208
209
210} //# NAMESPACE CASACORE - END
211
212#ifndef CASACORE_NO_AUTO_TEMPLATES
213#include <casacore/scimath/Functionals/Polynomial.tcc>
214#include <casacore/scimath/Functionals/Polynomial2.tcc>
215#endif //# CASACORE_NO_AUTO_TEMPLATES
216#endif
#define Polynomial_PS
Definition Polynomial.h:138
const T * FunctionArg
Definition Function1D.h:76
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
PolynomialParam< T > & operator=(const PolynomialParam< T > &other)
uInt order() const
What is the order of the polynomial, i.e.
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Polynomial.h:189
Polynomial_PS()
Constructs one dimensional Polynomials.
Definition Polynomial.h:153
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Polynomial.h:193
Polynomial_PS< AutoDiff< T > > & operator=(const Polynomial_PS< AutoDiff< T > > &other)
Copy assignment (deep copy)
Definition Polynomial.h:169
Polynomial_PS(const Polynomial_PS< W > &other)
Definition Polynomial.h:163
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the polynomial and its derivatives at x wrt to the coefficients.
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition Polynomial.h:186
Polynomial_PS(const Polynomial_PS< AutoDiff< T > > &other)
Copy constructor (deep copy)
Definition Polynomial.h:160
Polynomial(uInt order)
Makes a polynomial of the given order, with all coeficcients set to zero.
Definition Polynomial.h:97
Polynomial< T > derivative() const
Return the polynomial which is the derivative of this one.
Polynomial()
Constructs a zero'th order polynomial, with a coeficcient of 0.0.
Definition Polynomial.h:94
Polynomial(const Polynomial< T > &other)
Copy constructor/assignment (deep copy)
Definition Polynomial.h:100
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition Polynomial.h:122
Polynomial(const Polynomial< W > &other)
Definition Polynomial.h:102
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:123
virtual ~Polynomial()
Destructor.
Definition Polynomial.h:108
Polynomial< T > & operator=(const Polynomial< T > &other)
Definition Polynomial.h:103
virtual T eval(typename Function1D< T >::FunctionArg x) const
Evaluate the polynomial at x.
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:125
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
PtrHolder< T > & operator=(const PtrHolder< T > &other)