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