casa
$Rev:20696$
|
00001 //# AutoDiffRep.h: Representation of an automatic differential class data 00002 //# Copyright (C) 2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: AutoDiffRep.h 20229 2008-01-29 15:19:06Z gervandiepen $ 00028 00029 #ifndef SCIMATH_AUTODIFFREP_H 00030 #define SCIMATH_AUTODIFFREP_H 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <casa/Arrays/Vector.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 //# Forward declarations 00039 00040 // <summary> 00041 // Representation of an automatic differential class data 00042 // </summary> 00043 // 00044 // <use visibility=local> 00045 // 00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tAutoDiff.cc" demos=""> 00047 // </reviewed> 00048 // 00049 // <prerequisite> 00050 // <li> <linkto class=AutoDiff>AutoDiff</linkto> 00051 // </prerequisite> 00052 // 00053 // <etymology> 00054 // Class that represents partial derivatives obtained by automatic 00055 // differentiation. 00056 // </etymology> 00057 // 00058 // <synopsis> 00059 // Structure (only a class since cxx2html cannot handle struct) representing 00060 // the data necessary for automatic differentiation. The structure contains a 00061 // value, and the derivatives of the value with respect to the number of 00062 // dependend variables. 00063 // 00064 // The actual differentiation and access is done through the 00065 // <linkto class=AutoDiff>AutoDiff</linkto> class. 00066 // 00067 // <example> 00068 // See the example in <linkto class=AutoDiff>AutoDiff</linkto> 00069 // </example> 00070 // 00071 // <motivation> 00072 // To separate the data container from the actual calculations. 00073 // To be able to create special conatiners; constructors and destructors 00074 // (including memory allocation) to speed up processes. 00075 // 00076 // <templating arg=T> 00077 // <li> any class that has the standard mathematical and comparison 00078 // operators defined 00079 // </templating> 00080 // 00081 // <todo asof="20001/06/07"> 00082 // <li> Nothing I know off 00083 // </todo> 00084 00085 template <class T> class AutoDiffRep { 00086 public: 00087 //# Typedefs 00088 typedef T value_type; 00089 typedef value_type& reference; 00090 typedef const value_type& const_reference; 00091 typedef value_type* iterator; 00092 typedef const value_type* const_iterator; 00093 00094 //# Constructors 00095 // Construct a constant with a value of zero. Zero derivatives. 00096 AutoDiffRep(); 00097 00098 // Construct a constant with a value of v. Zero derivatives. 00099 explicit AutoDiffRep(const T &v); 00100 00101 // Given a function f(x0,x1,...,xn,...). Construct with 00102 // a total number of derivatives ndiffs. The nth derivative is one, and all 00103 // others are zero. The value v is the value of xn. 00104 AutoDiffRep(const T &v, const uInt ndiffs, const uInt n); 00105 00106 // Given a function f(x0,x1,...,xn,...). Construct with 00107 // a total number of derivatives ndiffs, and a value of xn. 00108 // All derivatives are zero. 00109 AutoDiffRep(const T &v, const uInt ndiffs); 00110 00111 // Construct with ndiffs derivatives. All values and derivatives zero 00112 AutoDiffRep(const uInt ndiffs); 00113 00114 // Construct one from another (deep copy) 00115 AutoDiffRep(const AutoDiffRep<T> &other); 00116 00117 // Construct a function f(x0,x1,...,xn) of a value v and a vector of 00118 // derivatives derivs(0) = df/dx0, derivs(1) = df/dx1, ... 00119 AutoDiffRep(const T &v, const Vector<T> &derivs); 00120 00121 // Destructor 00122 ~AutoDiffRep(); 00123 00124 //# Operators 00125 // Assign a constant to variable. All derivatives 00126 // are zero. 00127 AutoDiffRep<T> &operator=(const T &v); 00128 00129 // Assign one to another (deep copy). 00130 AutoDiffRep<T> &operator=(const AutoDiffRep<T> &other); 00131 00132 //# Member functions 00133 00134 //# Data 00135 // The function value 00136 T val_p; 00137 // The number of derivatives 00138 uInt nd_p; 00139 // A flag indicating that value will not be used anymore (to stop 00140 // superfluous copying) 00141 Bool nocopy_p; 00142 // The derivatives 00143 Vector<T> grad_p; 00144 }; 00145 00146 00147 } //# NAMESPACE CASA - END 00148 00149 #ifndef CASACORE_NO_AUTO_TEMPLATES 00150 #include <scimath/Mathematics/AutoDiffRep.tcc> 00151 #endif //# CASACORE_NO_AUTO_TEMPLATES 00152 #endif