casacore
Loading...
Searching...
No Matches
SparseDiffA.h
Go to the documentation of this file.
1// # SparseDiff!A.h: An automatic differentiating class for functions
2// # Copyright (C) 2001,2002
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_SPARSEDIFFA_H
27#define SCIMATH_SPARSEDIFFA_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/scimath/Mathematics/SparseDiff.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Class that computes partial derivatives by automatic differentiation.
38// </summary>
39//
40// <use visibility=export>
41//
42// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSparseDiff.cc"
43// demos="dSparseDiff.cc">
44// </reviewed>
45//
46// <prerequisite>
47// <li> <linkto class=SparseDiff>SparseDiff</linkto>
48// </prerequisite>
49//
50// <etymology>
51// Class that computes partial derivatives by automatic differentiation, thus
52// SparseDiff.
53// </etymology>
54//
55// <synopsis>
56// SparseDiffA is an <linkto class=SparseDiff>SparseDiff</linkto>. It is used
57// to be able to distinguish between two template incarnations; e.g. to
58// have one or more specializations, in addition to the general template
59// version.
60// </synopsis>
61//
62// <example>
63// See for an extensive example the demo program dSparseDiff. It is
64// based on the example given in the <linkto class=SparseDiff>SparseDiff</linkto>
65// class, and shows how to have both an automatic and a specific version
66// of a function object.
67// <srcblock>
68// // The function, with fixed parameters a,b:
69// template <class T> class f {
70// public:
71// T operator()(const T& x) { return a_p*a_p*a_p*b_p*b_p*x; }
72// void set(const T& a, const T& b) { a_p = a; b_p = b; }
73// private:
74// T a_p;
75// T b_p;
76// };
77// // The specialized function
78// template <> class f<SparseDiffA<Double> > {
79// public:
80// T operator()(const T& x) { return a_p*a_p*a_p*b_p*b_p*x; }
81// void set(const T& a, const T& b) { a_p = a; b_p = b; }
82// private:
83// T a_p;
84// T b_p;
85// };
86// // Call it with different template arguments:
87// SparseDiff<Double> a1(2,0), b1(3,1), x1(7);
88// f<SparseDiff<Double> > f1; f1.set(a1, b1);
89// cout << "Diff a,b: " << f1(x1) << endl;
90//
91// f<SparseDiffA<Double> > f12; f12.set(a1, b1);
92// cout << "Same....: " << f12(x1) << endl;
93//
94// // Result will be:
95// // Diff a,b: (504, [756, 336])
96// // Same....: (504, [756, 336])
97//
98// // It needed the template instantiations definitions:
99// template class f<SparseDiff<Double> >;
100// </srcblock>
101// </example>
102//
103// <motivation>
104// The class was created to enable separate calculations of the same
105// function.
106// </motivation>
107//
108// <templating arg=T>
109// <li> any class that has the standard mathematical and comparisons
110// defined
111// </templating>
112//
113// <todo asof="2001/06/07">
114// <li> Nothing I know
115// </todo>
116
117template <class T>
118class SparseDiffA : public SparseDiff<T> {
119 public:
120 // # Constructors
121 // Construct a constant with a value of zero. Zero derivatives.
123
124 // Construct a constant with a value of v. Zero derivatives.
125 SparseDiffA(const T &v) : SparseDiff<T>(v) {}
126
127 // A function f(x0,x1,...,xn,...) with a value of v.
128 // The nth derivative is one, and all others are zero.
129 SparseDiffA(const T &v, const uInt n) : SparseDiff<T>(v, n) {}
130
131 // A function f(x0,x1,...,xn,...) with a value of v. The
132 // nth derivative is der, and all other derivatives are zero.
133 SparseDiffA(const T &v, const uInt n, const T &der) : SparseDiff<T>(v, n, der) {}
134
135 // Construct one from another
136 SparseDiffA(const SparseDiff<T> &other) : SparseDiff<T>(other) {}
137
139
140 // Assignment operator. Assign a constant to variable. All derivatives
141 // are zero.
144 return *this;
145 }
146
147 // Assignment operator. Add a gradient to variable.
148 SparseDiffA<T> &operator=(const pair<uInt, T> &der) {
150 return *this;
151 }
152
153 // Assignment operator. Assign gradients to variable.
154 SparseDiffA<T> &operator=(const vector<pair<uInt, T>> &der) {
156 return *this;
157 }
158
159 // Assign one to another (deep copy).
162 return *this;
163 }
164
165 private:
166 // # Data
167};
168
169} // namespace casacore
170
171#endif
SparseDiffA(const SparseDiff< T > &other)
Construct one from another.
SparseDiffA(const T &v, const uInt n, const T &der)
A function f(x0,x1,...,xn,...) with a value of v.
SparseDiffA()
Construct a constant with a value of zero.
SparseDiffA(const T &v, const uInt n)
A function f(x0,x1,...,xn,...) with a value of v.
SparseDiffA< T > & operator=(const vector< pair< uInt, T > > &der)
Assignment operator.
SparseDiffA< T > & operator=(const pair< uInt, T > &der)
Assignment operator.
SparseDiffA< T > & operator=(const SparseDiff< T > &other)
Assign one to another (deep copy).
SparseDiffA(const T &v)
Construct a constant with a value of v.
SparseDiffA< T > & operator=(const T &v)
Assignment operator.
SparseDiff()
Construct a constant with a value of zero.
SparseDiff< T > & operator=(const T &v)
Assignment operator.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49