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