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