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