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" demos="dSparseDiff.cc">
43 // </reviewed>
44 //
45 // <prerequisite>
46 // <li> <linkto class=SparseDiff>SparseDiff</linkto>
47 // </prerequisite>
48 //
49 // <etymology>
50 // Class that computes partial derivatives by automatic differentiation, thus
51 // SparseDiff.
52 // </etymology>
53 //
54 // <synopsis>
55 // SparseDiffA is an <linkto class=SparseDiff>SparseDiff</linkto>. It is used
56 // to be able to distinguish between two template incarnations; e.g. to
57 // have one or more specializations, in addition to the general template
58 // version.
59 // </synopsis>
60 //
61 // <example>
62 // See for an extensive example the demo program dSparseDiff. It is
63 // based on the example given in the <linkto class=SparseDiff>SparseDiff</linkto>
64 // class, and shows how to have both an automatic and a specific version
65 // of a function object.
66 // <srcblock>
67 // // The function, with fixed parameters a,b:
68 // template <class T> class f {
69 // public:
70 // T operator()(const T& x) { return a_p*a_p*a_p*b_p*b_p*x; }
71 // void set(const T& a, const T& b) { a_p = a; b_p = b; }
72 // private:
73 // T a_p;
74 // T b_p;
75 // };
76 // // The specialized function
77 // template <> class f<SparseDiffA<Double> > {
78 // public:
79 // T operator()(const T& x) { return a_p*a_p*a_p*b_p*b_p*x; }
80 // void set(const T& a, const T& b) { a_p = a; b_p = b; }
81 // private:
82 // T a_p;
83 // T b_p;
84 // };
85 // // Call it with different template arguments:
86 // SparseDiff<Double> a1(2,0), b1(3,1), x1(7);
87 // f<SparseDiff<Double> > f1; f1.set(a1, b1);
88 // cout << "Diff a,b: " << f1(x1) << endl;
89 //
90 // f<SparseDiffA<Double> > f12; f12.set(a1, b1);
91 // cout << "Same....: " << f12(x1) << endl;
92 //
93 // // Result will be:
94 // // Diff a,b: (504, [756, 336])
95 // // Same....: (504, [756, 336])
96 //
97 // // It needed the template instantiations definitions:
98 // template class f<SparseDiff<Double> >;
99 // </srcblock>
100 // </example>
101 //
102 // <motivation>
103 // The class was created to enable separate calculations of the same
104 // function.
105 // </motivation>
106 //
107 // <templating arg=T>
108 // <li> any class that has the standard mathematical and comparisons
109 // defined
110 // </templating>
111 //
112 // <todo asof="2001/06/07">
113 // <li> Nothing I know
114 // </todo>
115
116 template <class T> class SparseDiffA : public SparseDiff<T> {
117 public:
118 //# Constructors
119 // Construct a constant with a value of zero. Zero derivatives.
121
122 // Construct a constant with a value of v. Zero derivatives.
123 SparseDiffA(const T &v) : SparseDiff<T>(v) {}
124
125 // A function f(x0,x1,...,xn,...) with a value of v.
126 // The nth derivative is one, and all others are zero.
127 SparseDiffA(const T &v, const uInt n) :
128 SparseDiff<T>(v, n) {}
129
130 // A function f(x0,x1,...,xn,...) with a value of v. The
131 // nth derivative is der, and all other derivatives are zero.
132 SparseDiffA(const T &v, const uInt n, const T &der) :
133 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
170
171} //# NAMESPACE CASACORE - END
172
173#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< T > & operator=(const T &v)
Assignment operator.
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49