casacore
Loading...
Searching...
No Matches
ConstantND.h
Go to the documentation of this file.
1// # HyperPlane.h: Form a hyper plane function
2// # Copyright (C) 2001,2002,2004,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_CONSTANT_H
27#define SCIMATH_CONSTANT_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/ConstantNDParam.h>
32#include <casacore/scimath/Functionals/Function.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34#include <casacore/scimath/Mathematics/AutoDiffMath.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// <summary> A constant function.
39// </summary>
40//
41// <use visibility=export>
42// <reviewed reviewer="" date="" tests="tConstant" demos="">
43// </reviewed>
44//
45// <prerequisite>
46// <li> <linkto class=Function>Function</linkto>
47// </prerequisite>
48//
49// <synopsis>
50// This class represents a constant function in a space
51// of arbitrary dimension
52// f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) = constant
53// where x<sub>i</sub>
54// are independent arguments and m is the number of dimensions of the space.
55//
56//
57// Since the <src>Constant</src> is a <src>Function</src>, the derivatives
58// can be obtained as well (and are in fact 0 of course).
59//
60// The parameter interface (see
61// <linkto class="FunctionParam">FunctionParam</linkto> class),
62// is used to provide an interface to the
63// <linkto module="Fitting">Fitting</linkto> classes.
64//
65// This class is in general used implicitly by the <src>Constant</src>
66// class only.
67// </synopsis>
68//
69// <example>
70// <srcblock>
71// // form the constant function in 4-D space
72// Constant<Double> constant(4); // 4-dim hyperplane
73// constant.parameters()[0] = 22;
74// // Evaluate at x0=5, x3=7
75// Vector<Double> x(4);
76// x=0; x[0]=5; x[3]=7;
77// cout << "constant value: " << constant(x) << endl;
78// constant value: 22
79// </srcblock>
80// </example>
81
82// <templating arg=T>
83// <li> T should have standard numerical operators. Current
84// implementation only tested for real types (and their AutoDiffs).
85// </templating>
86
87// <thrown>
88// <li> Assertion in debug mode if attempt is made to address incorrect
89// coefficients
90// </thrown>
91
92// <motivation>
93// This class was created because HyperPlane does not support a constant
94// offset and modifying that class really required an interface change
95// (ie that the constant offset be at the beginning of the parameter vector
96// and that the parameter vector increase by one) so rather than breaking
97// any code that already used HyperPlane I simply made a trivial Constant
98// class.
99// </motivation>
100//
101// <todo asof="2011/07/01">
102// <li> Nothing I know of
103// </todo>
104
105template <class T>
106class ConstantND : public ConstantNDParam<T> {
107 public:
108 // # Constructors
109 // Construct a constant in an a space of dimensionality <src>m</src>. By
110 // default, the constant value is initialised to zero, and <src>m=0</src>
111 explicit ConstantND(const uInt m = 0) : ConstantNDParam<T>(m) { ; };
112 // Copy constructor/assignment (deep copy)
113 // <group>
114 ConstantND(const ConstantND<T> &other) : ConstantNDParam<T>(other) {};
115 template <class W>
116 ConstantND(const ConstantND<W> &other) : ConstantNDParam<T>(other) {}
119 return *this;
120 };
121 // </group>
122
123 // Destructor
124 virtual ~ConstantND() {};
125
126 // # Operators
127 // Evaluate the hyper plane function at
128 // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
129 virtual T eval(typename Function<T>::FunctionArg x) const;
130
131 // Return a copy of this object from the heap. The caller is responsible for
132 // deleting the pointer.
133 // <group>
134 virtual Function<T> *clone() const { return new ConstantND<T>(*this); };
141 // </group>
142
143 // # Make members of parent classes known.
144 protected:
146
147 public:
149};
150
151#define ConstantND_PS ConstantND
152
153// <summary> Partial specialization of ConstantND for <src>AutoDiff</src>
154// </summary>
155
156// <synopsis>
157// <note role=warning> The name <src>HyperPlane_PS</src> is only for cxx2html
158// documentation problems. Use <src>HyperPlane</src> in your code.</note>
159// </synopsis>
160
161template <class T>
162class ConstantND_PS<AutoDiff<T>> : public ConstantNDParam<AutoDiff<T>> {
163 public:
164 // # Construct
165 // Constructors a constant in a space of dimensionality <src>m</src>. By
166 // default, the coefficients are initialized to zero, and <src>m=0</src>
167 explicit ConstantND_PS(const uInt m = 0) : ConstantNDParam<AutoDiff<T>>(m) {};
168 // Copy constructor/assignment (deep copy)
169 // <group>
170 ConstantND_PS(const ConstantND_PS<AutoDiff<T>> &other) : ConstantNDParam<AutoDiff<T>>(other) {};
171 template <class W>
174 ConstantNDParam<AutoDiff<T>>::operator=(other);
175 return *this;
176 };
177 // </group>
178
179 // Destructor
180 virtual ~ConstantND() {};
181
182 // # Operators
183 // Evaluate the constant function at
184 // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
185 virtual AutoDiff<T> eval(typename Function<AutoDiff<T>>::FunctionArg x) const;
186
187 // Return a copy of this object from the heap. The caller is responsible for
188 // deleting the pointer.
189 // <group>
190 virtual Function<AutoDiff<T>> *clone() const { return new ConstantND_PS<AutoDiff<T>>(*this); };
191 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
192 return new ConstantND<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
193 };
194 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
195 return new ConstantND<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
196 };
197 // </group>
198
199 // # Make members of parent classes known.
200 protected:
201 using ConstantNDParam<AutoDiff<T>>::param_p;
202
203 public:
204 using ConstantNDParam<AutoDiff<T>>::nparameters;
205};
206
207#undef ConstantND_PS
208
209} // namespace casacore
210
211#ifndef CASACORE_NO_AUTO_TEMPLATES
212#include <casacore/scimath/Functionals/ConstantND.tcc>
213#endif // # CASACORE_NO_AUTO_TEMPLATES
214#endif
#define ConstantND_PS
Definition ConstantND.h:151
ConstantNDParam< T > & operator=(const ConstantNDParam< T > &other)
Copy assignment (deep copy).
ConstantNDParam(uInt m=0)
Construct a constant in m-dimensional space.
ConstantND_PS(const ConstantND_PS< AutoDiff< T > > &other)
Copy constructor/assignment (deep copy).
Definition ConstantND.h:169
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition ConstantND.h:193
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition ConstantND.h:189
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition ConstantND.h:190
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the constant function at (x0,x1,..,xm-1).
ConstantND_PS(const uInt m=0)
Constructors a constant in a space of dimensionality m.
Definition ConstantND.h:166
ConstantND_PS(const ConstantND_PS< W > &other)
Definition ConstantND.h:171
ConstantND_PS< AutoDiff< T > > & operator=(const ConstantND_PS< AutoDiff< T > > &other)
Definition ConstantND.h:172
ConstantND(const ConstantND< T > &other)
Copy constructor/assignment (deep copy).
Definition ConstantND.h:114
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition ConstantND.h:135
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition ConstantND.h:134
ConstantND< T > & operator=(const ConstantND< T > &other)
Definition ConstantND.h:117
virtual ~ConstantND()
Destructor.
Definition ConstantND.h:124
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the hyper plane function at (x0,x1,..,xm-1).
ConstantND(const uInt m=0)
Construct a constant in an a space of dimensionality m.
Definition ConstantND.h:111
ConstantND(const ConstantND< W > &other)
Definition ConstantND.h:116
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition ConstantND.h:138
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:337
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:226
const ArgType * FunctionArg
Definition Function.h:204
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129
Block< T > & operator=(const T &val)
Set all values in the block to "val".
Definition Block.h:536