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>
89class Polynomial : public PolynomialParam<T> {
90 public:
91 // # Enumerations
92
93 // # Constructors
94 // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
96 // Makes a polynomial of the given order, with all coeficcients set to
97 // zero.
99 // Copy constructor/assignment (deep copy)
100 // <group>
101 Polynomial(const Polynomial<T> &other) : PolynomialParam<T>(other) {}
102 template <class W>
103 Polynomial(const Polynomial<W> &other) : PolynomialParam<T>(other) {}
106 return *this;
107 }
108 // </group>
109
110 // Destructor
111 virtual ~Polynomial() {}
112
113 // # Operators
114 // Evaluate the polynomial at <src>x</src>.
115 virtual T eval(typename Function1D<T>::FunctionArg x) const;
116
117 // # Member functions
118 // Return the polynomial which is the derivative of this one. <em>e.g.,</em>
119 // <src> 2+4x+5x^2 --> 0+4+10x </src>.
121
122 // Return a copy of this object from the heap. The caller is responsible for
123 // deleting the pointer.
124 // <group>
125 virtual Function<T> *clone() const { return new Polynomial<T>(*this); }
132 // </group>
133
134 // # Make members of parent classes known.
135 protected:
136 using PolynomialParam<T>::param_p;
137
138 public:
139 using PolynomialParam<T>::nparameters;
140 using PolynomialParam<T>::order;
141};
142
143#define Polynomial_PS Polynomial
144
145// <summary> Partial specialization of Polynomial for <src>AutoDiff</src>
146// </summary>
147
148// <synopsis>
149// <note role=warning> The name <src>Polynomial_PS</src> is only for cxx2html
150// documentation problems. Use <src>Polynomial</src> in your code.</note>
151// </synopsis>
152
153template <class T>
154class Polynomial_PS<AutoDiff<T>> : public PolynomialParam<AutoDiff<T>> {
155 public:
156 // # Constructors
157 // Constructs one dimensional Polynomials.
158 // <group>
161 // </group>
162
163 // Copy constructor (deep copy)
164 // <group>
165 Polynomial_PS(const Polynomial_PS<AutoDiff<T>> &other) : PolynomialParam<AutoDiff<T>>(other) {}
166 template <class W>
167 Polynomial_PS(const Polynomial_PS<W> &other) : PolynomialParam<AutoDiff<T>>(other) {}
168 // </group>
169
170 // Copy assignment (deep copy)
172 PolynomialParam<AutoDiff<T>>::operator=(other);
173 return *this;
174 }
175
176 // Destructor
177 virtual ~Polynomial_PS() {}
178
179 // # Operators
180 // Evaluate the polynomial and its derivatives at <src>x</src> <em>wrt</em>
181 // to the coefficients.
182 // <group>
183 virtual AutoDiff<T> eval(typename Function<AutoDiff<T>>::FunctionArg x) const;
184 // </group>
185
186 // # Member functions
187 // Return a copy of this object from the heap. The caller is responsible
188 // for deleting this pointer.
189 // <group>
190 virtual Function<AutoDiff<T>> *clone() const { return new Polynomial<AutoDiff<T>>(*this); }
191 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
192 return new Polynomial<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
194 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
195 return new Polynomial<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
196 }
197 // </group>
198
199 // # Make members of parent classes known.
200 protected:
201 using PolynomialParam<AutoDiff<T>>::param_p;
202
203 public:
204 using PolynomialParam<AutoDiff<T>>::nparameters;
205 using PolynomialParam<AutoDiff<T>>::order;
206};
207
208#undef Polynomial_PS
209
210} // namespace casacore
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:143
const T * FunctionArg
Definition Function1D.h:76
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Polynomial.h:190
Polynomial_PS()
Constructs one dimensional Polynomials.
Definition Polynomial.h:158
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:170
Polynomial_PS(const Polynomial_PS< W > &other)
Definition Polynomial.h:166
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:189
Polynomial_PS(const Polynomial_PS< AutoDiff< T > > &other)
Copy constructor (deep copy).
Definition Polynomial.h:164
PolynomialParam()
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
Polynomial< T > derivative() const
Return the polynomial which is the derivative of this one.
virtual ~Polynomial()
Destructor.
Definition Polynomial.h:111
unsigned int uInt
Definition aipstype.h:49
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
uInt order() const
What is the order of the polynomial, i.e.
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:129
RecordInterface * clone() const override
Make a copy of this object.
Definition Polynomial.h:125
Block< T > & operator=(const T &val)
Set all values in the block to "val".
Definition Block.h:536