casacore
AutoDiffRep.h
Go to the documentation of this file.
1 //# AutoDiffRep.h: Representation of an automatic differential class data
2 //# Copyright (C) 2001
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_AUTODIFFREP_H
30 #define SCIMATH_AUTODIFFREP_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Arrays/Vector.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 
40 // <summary>
41 // Representation of an automatic differential class data
42 // </summary>
43 //
44 // <use visibility=local>
45 //
46 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tAutoDiff.cc" demos="">
47 // </reviewed>
48 //
49 // <prerequisite>
50 // <li> <linkto class=AutoDiff>AutoDiff</linkto>
51 // </prerequisite>
52 //
53 // <etymology>
54 // Class that represents partial derivatives obtained by automatic
55 // differentiation.
56 // </etymology>
57 //
58 // <synopsis>
59 // Structure (only a class since cxx2html cannot handle struct) representing
60 // the data necessary for automatic differentiation. The structure contains a
61 // value, and the derivatives of the value with respect to the number of
62 // dependend variables.
63 //
64 // The actual differentiation and access is done through the
65 // <linkto class=AutoDiff>AutoDiff</linkto> class.
66 //
67 // <example>
68 // See the example in <linkto class=AutoDiff>AutoDiff</linkto>
69 // </example>
70 //
71 // <motivation>
72 // To separate the data container from the actual calculations.
73 // To be able to create special conatiners; constructors and destructors
74 // (including memory allocation) to speed up processes.
75 //
76 // <templating arg=T>
77 // <li> any class that has the standard mathematical and comparison
78 // operators defined
79 // </templating>
80 //
81 // <todo asof="20001/06/07">
82 // <li> Nothing I know off
83 // </todo>
84 
85 template <class T> class AutoDiffRep {
86  public:
87  //# Typedefs
88  typedef T value_type;
89  typedef value_type& reference;
90  typedef const value_type& const_reference;
91  typedef value_type* iterator;
92  typedef const value_type* const_iterator;
93 
94  //# Constructors
95  // Construct a constant with a value of zero. Zero derivatives.
96  AutoDiffRep();
97 
98  // Construct a constant with a value of v. Zero derivatives.
99  explicit AutoDiffRep(const T &v);
100 
101  // Given a function f(x0,x1,...,xn,...). Construct with
102  // a total number of derivatives ndiffs. The nth derivative is one, and all
103  // others are zero. The value v is the value of xn.
104  AutoDiffRep(const T &v, const uInt ndiffs, const uInt n);
105 
106  // Given a function f(x0,x1,...,xn,...). Construct with
107  // a total number of derivatives ndiffs, and a value of xn.
108  // All derivatives are zero.
109  AutoDiffRep(const T &v, const uInt ndiffs);
110 
111  // Construct with ndiffs derivatives. All values and derivatives zero
112  AutoDiffRep(const uInt ndiffs);
113 
114  // Construct one from another (deep copy)
115  AutoDiffRep(const AutoDiffRep<T> &other);
116 
117  // Construct a function f(x0,x1,...,xn) of a value v and a vector of
118  // derivatives derivs(0) = df/dx0, derivs(1) = df/dx1, ...
119  AutoDiffRep(const T &v, const Vector<T> &derivs);
120 
121  // Destructor
122  ~AutoDiffRep();
123 
124  //# Operators
125  // Assign a constant to variable. All derivatives
126  // are zero.
127  AutoDiffRep<T> &operator=(const T &v);
128 
129  // Assign one to another (deep copy).
130  AutoDiffRep<T> &operator=(const AutoDiffRep<T> &other);
131 
132  //# Member functions
133 
134  //# Data
135  // The function value
136  T val_p;
137  // The number of derivatives
139  // A flag indicating that value will not be used anymore (to stop
140  // superfluous copying)
142  // The derivatives
144 };
145 
146 
147 } //# NAMESPACE CASACORE - END
148 
149 #ifndef CASACORE_NO_AUTO_TEMPLATES
150 #include <casacore/scimath/Mathematics/AutoDiffRep.tcc>
151 #endif //# CASACORE_NO_AUTO_TEMPLATES
152 #endif
A 1-D Specialization of the Array class.
Definition: ArrayIO.h:45
AutoDiffRep()
Construct a constant with a value of zero.
uInt nd_p
The number of derivatives.
Definition: AutoDiffRep.h:138
AutoDiffRep< T > & operator=(const T &v)
Assign a constant to variable.
const value_type * const_iterator
Definition: AutoDiffRep.h:92
T val_p
The function value.
Definition: AutoDiffRep.h:136
~AutoDiffRep()
Destructor.
value_type & reference
Definition: AutoDiffRep.h:89
const value_type & const_reference
Definition: AutoDiffRep.h:90
value_type * iterator
Definition: AutoDiffRep.h:91
Bool nocopy_p
A flag indicating that value will not be used anymore (to stop superfluous copying) ...
Definition: AutoDiffRep.h:141
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Representation of an automatic differential class data.
Definition: AutoDiffRep.h:85
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
Vector< T > grad_p
The derivatives.
Definition: AutoDiffRep.h:143