CppAD: A C++ Algorithmic Differentiation Package 20110419
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_DEFINE_INCLUDED 00003 # define CPPAD_DEFINE_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Common Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 00016 /*! 00017 \file define.hpp 00018 Define processor symbols and macros that are used by CppAD. 00019 00020 */ 00021 00022 /*! 00023 \def CPPAD_USE_FORWARD0SWEEP 00024 If ture, use compute zero order sweeps using a specialized routine. 00025 00026 The value of this define should be zero or one. 00027 If it is one, a specialized routine is used for zero order forward sweeps. 00028 Otherwise, use the general forward routine is used for zero order. 00029 Using the specialized routine is an optimization that makes the source 00030 more complicated and a significant speed improvement has not been 00031 verified (as yet). 00032 This preprocessor symbol makes it easier to compare these two options. 00033 */ 00034 # define CPPAD_USE_FORWARD0SWEEP 1 00035 00036 /*! 00037 \def CPPAD_BEGIN_NAMESPACE 00038 Declares beginning of the CppAD namespace is a way not reconized by doxygen. 00039 00040 \def CPPAD_END_NAMESPACE 00041 Used for end that matches the beginning of a CppAD namespace section 00042 */ 00043 00044 # define CPPAD_BEGIN_NAMESPACE namespace CppAD { 00045 # define CPPAD_END_NAMESPACE } 00046 00047 00048 /*! 00049 \def CPPAD_INLINE 00050 A version of the inline command that works with MC compiler. 00051 00052 Microsoft Visual C++ version 9.0 generates a warning if a template 00053 function is declared as a friend 00054 (this was not a problem for version 7.0). 00055 The warning identifier is 00056 \verbatim 00057 warning C4396 00058 \endverbatim 00059 and it contains the text 00060 \verbatim 00061 the inline specifier cannot be used when a friend declaration refers 00062 to a specialization of a function template 00063 \endverbatim 00064 This happens even if the function is not a specialization. 00065 The macro CPPAD_INLINE is defined as empty for Microsoft compilers. 00066 */ 00067 # ifdef _MSC_VER 00068 # define CPPAD_INLINE 00069 # else 00070 # define CPPAD_INLINE inline 00071 # endif 00072 00073 /*! 00074 \def CPPAD_NULL 00075 This preprocessor symbol is used for a null pointer. 00076 00077 If it is not yet defined, 00078 it is defined when cppad/local/define.hpp is included. 00079 */ 00080 # ifndef CPPAD_NULL 00081 # define CPPAD_NULL 0 00082 # endif 00083 00084 /*! 00085 \def CPPAD_MAX_NUM_THREADS 00086 Specifies the maximum number of OpenMp threads that can be used with CppAD. 00087 00088 If it is not yet defined, 00089 it is defined when cppad/local/define.hpp is included. 00090 If the preprocessor symbol _OPENMP is not defined, 00091 CPPAD_MAX_NUM_THREADS one. Otheriwse it is 32. 00092 */ 00093 # ifndef CPPAD_MAX_NUM_THREADS 00094 # ifdef _OPENMP 00095 # define CPPAD_MAX_NUM_THREADS 32 00096 # else 00097 # define CPPAD_MAX_NUM_THREADS 1 00098 # endif 00099 # endif 00100 00101 /*! 00102 \def CPPAD_FOLD_ASSIGNMENT_OPERATOR(Op) 00103 Declares automatic coercion for certain AD assignment operations. 00104 00105 This macro assumes that the operator 00106 \verbatim 00107 left Op right 00108 \endverbatim 00109 is defined for the case where left and right have type AD<Base>. 00110 It uses this case to define the cases where 00111 left has type AD<Base> and right has type 00112 VecAD_reference<Base>, 00113 Base, or 00114 double. 00115 The argument right is const and call by reference. 00116 This macro converts the operands to AD<Base> and then 00117 uses the definition of the same operation for that case. 00118 */ 00119 00120 # define CPPAD_FOLD_ASSIGNMENT_OPERATOR(Op) \ 00121 /* ----------------------------------------------------------------*/ \ 00122 template <class Base> \ 00123 inline AD<Base>& operator Op \ 00124 (AD<Base> &left, double right) \ 00125 { return left Op AD<Base>(right); } \ 00126 \ 00127 template <class Base> \ 00128 inline AD<Base>& operator Op \ 00129 (AD<Base> &left, const Base &right) \ 00130 { return left Op AD<Base>(right); } \ 00131 \ 00132 inline AD<double>& operator Op \ 00133 (AD<double> &left, const double &right) \ 00134 { return left Op AD<double>(right); } \ 00135 \ 00136 template <class Base> \ 00137 inline AD<Base>& operator Op \ 00138 (AD<Base> &left, const VecAD_reference<Base> &right) \ 00139 { return left Op right.ADBase(); } 00140 00141 // ===================================================================== 00142 /*! 00143 \def CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(Op) 00144 Declares automatic coercion for certain binary operations with AD result. 00145 00146 This macro assumes that the operator 00147 \verbatim 00148 left Op right 00149 \endverbatim 00150 is defined for the case where left and right 00151 and the result of the operation all 00152 have type AD<Base>. 00153 It uses this case to define the cases either left 00154 or right has type VecAD_reference<Base> or AD<Base> 00155 and the type of the other operand is one of the following: 00156 VecAD_reference<Base>, AD<Base>, Base, double. 00157 All of the arguments are const and call by reference. 00158 This macro converts the operands to AD<Base> and then 00159 uses the definition of the same operation for that case. 00160 */ 00161 # define CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(Op) \ 00162 /* ----------------------------------------------------------------*/ \ 00163 /* Operations with VecAD_reference<Base> and AD<Base> only*/ \ 00164 \ 00165 template <class Base> \ 00166 inline AD<Base> operator Op \ 00167 (const AD<Base> &left, const VecAD_reference<Base> &right) \ 00168 { return left Op right.ADBase(); } \ 00169 \ 00170 template <class Base> \ 00171 inline AD<Base> operator Op \ 00172 (const VecAD_reference<Base> &left, const VecAD_reference<Base> &right)\ 00173 { return left.ADBase() Op right.ADBase(); } \ 00174 \ 00175 template <class Base> \ 00176 inline AD<Base> operator Op \ 00177 (const VecAD_reference<Base> &left, const AD<Base> &right) \ 00178 { return left.ADBase() Op right; } \ 00179 /* ----------------------------------------------------------------*/ \ 00180 /* Operations Base */ \ 00181 \ 00182 template <class Base> \ 00183 inline AD<Base> operator Op \ 00184 (const Base &left, const AD<Base> &right) \ 00185 { return AD<Base>(left) Op right; } \ 00186 \ 00187 template <class Base> \ 00188 inline AD<Base> operator Op \ 00189 (const Base &left, const VecAD_reference<Base> &right) \ 00190 { return AD<Base>(left) Op right.ADBase(); } \ 00191 \ 00192 template <class Base> \ 00193 inline AD<Base> operator Op \ 00194 (const AD<Base> &left, const Base &right) \ 00195 { return left Op AD<Base>(right); } \ 00196 \ 00197 template <class Base> \ 00198 inline AD<Base> operator Op \ 00199 (const VecAD_reference<Base> &left, const Base &right) \ 00200 { return left.ADBase() Op AD<Base>(right); } \ 00201 \ 00202 /* ----------------------------------------------------------------*/ \ 00203 /* Operations double */ \ 00204 \ 00205 template <class Base> \ 00206 inline AD<Base> operator Op \ 00207 (const double &left, const AD<Base> &right) \ 00208 { return AD<Base>(left) Op right; } \ 00209 \ 00210 template <class Base> \ 00211 inline AD<Base> operator Op \ 00212 (const double &left, const VecAD_reference<Base> &right) \ 00213 { return AD<Base>(left) Op right.ADBase(); } \ 00214 \ 00215 template <class Base> \ 00216 inline AD<Base> operator Op \ 00217 (const AD<Base> &left, const double &right) \ 00218 { return left Op AD<Base>(right); } \ 00219 \ 00220 template <class Base> \ 00221 inline AD<Base> operator Op \ 00222 (const VecAD_reference<Base> &left, const double &right) \ 00223 { return left.ADBase() Op AD<Base>(right); } \ 00224 /* ----------------------------------------------------------------*/ \ 00225 /* Special case to avoid ambuigity when Base is double */ \ 00226 \ 00227 inline AD<double> operator Op \ 00228 (const double &left, const AD<double> &right) \ 00229 { return AD<double>(left) Op right; } \ 00230 \ 00231 inline AD<double> operator Op \ 00232 (const double &left, const VecAD_reference<double> &right) \ 00233 { return AD<double>(left) Op right.ADBase(); } \ 00234 \ 00235 inline AD<double> operator Op \ 00236 (const AD<double> &left, const double &right) \ 00237 { return left Op AD<double>(right); } \ 00238 \ 00239 inline AD<double> operator Op \ 00240 (const VecAD_reference<double> &left, const double &right) \ 00241 { return left.ADBase() Op AD<double>(right); } 00242 00243 // ======================================================================= 00244 00245 /*! 00246 \def CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(Op) 00247 Declares automatic coercion for certain binary operations with bool result. 00248 00249 This macro assumes that the operator 00250 \verbatim 00251 left Op right 00252 \endverbatim 00253 is defined for the case where left and right 00254 have type AD<Base> and the result has type bool. 00255 It uses this case to define the cases either left 00256 or right has type 00257 VecAD_reference<Base> or AD<Base> 00258 and the type of the other operand is one of the following: 00259 VecAD_reference<Base>, AD<Base>, Base, double. 00260 All of the arguments are const and call by reference. 00261 This macro converts the operands to AD<Base> and then 00262 uses the definition of the same operation for that case. 00263 */ 00264 # define CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(Op) \ 00265 /* ----------------------------------------------------------------*/ \ 00266 /* Operations with VecAD_reference<Base> and AD<Base> only*/ \ 00267 \ 00268 template <class Base> \ 00269 inline bool operator Op \ 00270 (const AD<Base> &left, const VecAD_reference<Base> &right) \ 00271 { return left Op right.ADBase(); } \ 00272 \ 00273 template <class Base> \ 00274 inline bool operator Op \ 00275 (const VecAD_reference<Base> &left, const VecAD_reference<Base> &right)\ 00276 { return left.ADBase() Op right.ADBase(); } \ 00277 \ 00278 template <class Base> \ 00279 inline bool operator Op \ 00280 (const VecAD_reference<Base> &left, const AD<Base> &right) \ 00281 { return left.ADBase() Op right; } \ 00282 /* ----------------------------------------------------------------*/ \ 00283 /* Operations Base */ \ 00284 \ 00285 template <class Base> \ 00286 inline bool operator Op \ 00287 (const Base &left, const AD<Base> &right) \ 00288 { return AD<Base>(left) Op right; } \ 00289 \ 00290 template <class Base> \ 00291 inline bool operator Op \ 00292 (const Base &left, const VecAD_reference<Base> &right) \ 00293 { return AD<Base>(left) Op right.ADBase(); } \ 00294 \ 00295 template <class Base> \ 00296 inline bool operator Op \ 00297 (const AD<Base> &left, const Base &right) \ 00298 { return left Op AD<Base>(right); } \ 00299 \ 00300 template <class Base> \ 00301 inline bool operator Op \ 00302 (const VecAD_reference<Base> &left, const Base &right) \ 00303 { return left.ADBase() Op AD<Base>(right); } \ 00304 \ 00305 /* ----------------------------------------------------------------*/ \ 00306 /* Operations double */ \ 00307 \ 00308 template <class Base> \ 00309 inline bool operator Op \ 00310 (const double &left, const AD<Base> &right) \ 00311 { return AD<Base>(left) Op right; } \ 00312 \ 00313 template <class Base> \ 00314 inline bool operator Op \ 00315 (const double &left, const VecAD_reference<Base> &right) \ 00316 { return AD<Base>(left) Op right.ADBase(); } \ 00317 \ 00318 template <class Base> \ 00319 inline bool operator Op \ 00320 (const AD<Base> &left, const double &right) \ 00321 { return left Op AD<Base>(right); } \ 00322 \ 00323 template <class Base> \ 00324 inline bool operator Op \ 00325 (const VecAD_reference<Base> &left, const double &right) \ 00326 { return left.ADBase() Op AD<Base>(right); } \ 00327 /* ----------------------------------------------------------------*/ \ 00328 /* Special case to avoid ambuigity when Base is double */ \ 00329 \ 00330 inline bool operator Op \ 00331 (const double &left, const AD<double> &right) \ 00332 { return AD<double>(left) Op right; } \ 00333 \ 00334 inline bool operator Op \ 00335 (const double &left, const VecAD_reference<double> &right) \ 00336 { return AD<double>(left) Op right.ADBase(); } \ 00337 \ 00338 inline bool operator Op \ 00339 (const AD<double> &left, const double &right) \ 00340 { return left Op AD<double>(right); } \ 00341 \ 00342 inline bool operator Op \ 00343 (const VecAD_reference<double> &left, const double &right) \ 00344 { return left.ADBase() Op AD<double>(right); } 00345 00346 # endif