casacore
Loading...
Searching...
No Matches
EvenPolynomialParam.h
Go to the documentation of this file.
1// # EvenPolynomialParam.h: Parameter handling for even polynomials
2// # Copyright (C) 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_EVENPOLYNOMIALPARAM_H
27#define SCIMATH_EVENPOLYNOMIALPARAM_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/scimath/Functionals/Function1D.h>
33#include <casacore/casa/Utilities/Assert.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary> Parameter handling for even polynomials
38// </summary>
39
40// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tSpecialPolynomial"
41// demos="">
42// </reviewed>
43
44// <prerequisite>
45// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
46// <li> <linkto class=Function1D>Function1D</linkto>
47// </prerequisite>
48
49// <etymology>
50// A 1-dimensional EvenPolynomial's parameters.
51// </etymology>
52//
53// <synopsis>
54// An <src>EvenPolynomial</src> is described by a set of coefficients;
55// its fundamental operation is evaluating itself at some "x".
56// The number of coefficients is the order of the polynomial divided
57// by two, plus one.
58//
59// Since the <src>EvenPolynomial</src> is a <src>Function</src>,
60// the derivatives can be obtained as well.
61//
62// The parameter interface (see
63// <linkto class="FunctionParam">FunctionParam</linkto> class),
64// is used to provide an interface to the
65// <linkto module="Fitting">Fitting</linkto> classes.
66//
67// This class is in general used implicitly by the <src>EvenPolynomial</src>
68// class only.
69// </synopsis>
70//
71// <example>
72// <srcblock>
73// EvenPolynomial<Float> pf(3); // Second order polynomial - coeffs 0 by default
74// pf.setCoefficient(0, 1.0);
75// pf[1] = 2.0; // 2x^2 + 1x^0
76// pf(2); // == 8
77// </srcblock>
78// </example>
79
80// <templating arg=T>
81// <li> T should have standard numerical operators. Current
82// implementation only tested for real types (and their AutoDiffs).
83// </templating>
84
85// <thrown>
86// <li> Assertion in debug mode if attempt is made to address incorrect
87// coefficients
88// </thrown>
89
90// <todo asof="2002/02/26">
91// <li> Nothing I know of
92// </todo>
93
94template <class T>
96 public:
97 // # Constructors
98 // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
100
101 // Makes a polynomial of the given order, with all coeficcients set to
102 // zero.
104
105 // Make this a copy of other (deep copy).
106 // <group>
108 template <class W>
111 // </group>
112
113 // Destructor
115
116 // # Operators
117 // Comparisons.
118 // EvenPolynomials are equal if they are the same order
119 // <group>
120 Bool operator==(const EvenPolynomialParam<T> &other) const { return (param_p == other.param_p); }
121 Bool operator!=(const EvenPolynomialParam<T> &other) const { return (param_p != other.param_p); }
122 // </group>
123
124 // # Member functions
125 // Give name of function
126 virtual const String &name() const {
127 static String x("evenpolynomial");
128 return x;
129 }
130
131 // What is the order of the polynomial, i.e. maximum exponent of "x".
132 uInt order() const { return 2 * param_p.nelements() - 2; }
133
134 // What is the <em>which</em>'th coefficient of the polynomial. For an nth
135 // degree polynomial, <em>which</em> varies between zero and n/2.
136 T coefficient(uInt which) const {
137 DebugAssert(which <= order(), AipsError);
138 return param_p[which];
139 }
140
141 // Return all the coefficients as a vector.
142 const Vector<T> &coefficients() const;
143
144 // Set the <em>which</em>'th coefficient to <em>value</em>.
145 void setCoefficient(uInt which, const T value) {
146 DebugAssert(which <= order(), AipsError);
147 param_p[which] = value;
148 }
149
150 // Set all the coefficients at once, throw away all existing coefficients.
152
153 // # Make members of parent classes known.
154 protected:
155 using Function1D<T>::param_p;
156
157 public:
159};
160
161} // namespace casacore
162
163#ifndef CASACORE_NO_AUTO_TEMPLATES
164#include <casacore/scimath/Functionals/EvenPolynomialParam.tcc>
165#endif // # CASACORE_NO_AUTO_TEMPLATES
166#endif
#define DebugAssert(expr, exception)
Definition Assert.h:161
Bool operator==(const EvenPolynomialParam< T > &other) const
Comparisons.
Bool operator!=(const EvenPolynomialParam< T > &other) const
const Vector< T > & coefficients() const
Return all the coefficients as a vector.
T coefficient(uInt which) const
What is the which'th coefficient of the polynomial.
EvenPolynomialParam(const EvenPolynomialParam< T > &other)
Make this a copy of other (deep copy).
void setCoefficient(uInt which, const T value)
Set the which'th coefficient to value.
EvenPolynomialParam(const EvenPolynomialParam< W > &other)
EvenPolynomialParam()
Constructs a zero'th order polynomial, with a coeficcient of 0.0.
uInt order() const
What is the order of the polynomial, i.e.
void setCoefficients(const Vector< T > &coefficients)
Set all the coefficients at once, throw away all existing coefficients.
EvenPolynomialParam(uInt order)
Makes a polynomial of the given order, with all coeficcients set to zero.
EvenPolynomialParam< T > & operator=(const EvenPolynomialParam< T > &other)
virtual const String & name() const
Give name of function.
Function1D()
Constructors.
Definition Function1D.h:81
FunctionParam< T > param_p
Definition Function.h:337
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360