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