CppAD: A C++ Algorithmic Differentiation Package 20110419
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_IDENTICAL_INCLUDED 00003 # define CPPAD_IDENTICAL_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 # include <cppad/local/define.hpp> 00017 00018 CPPAD_BEGIN_NAMESPACE 00019 /*! 00020 \file identical.hpp 00021 Check if certain properties is true for any possible AD tape play back. 00022 */ 00023 00024 // Parameter ============================================================== 00025 /*! 00026 return true, used by <tt>IdenticalPar(AD<float>)</tt>. 00027 00028 \param x 00029 not used. 00030 00031 \return 00032 returns true. 00033 */ 00034 inline bool IdenticalPar(const float &x) 00035 { return true; } 00036 // --------------------------------------------------------------------------- 00037 /*! 00038 return true, used by <tt>IdenticalPar(AD<double>)</tt>. 00039 00040 \param x 00041 not used. 00042 00043 \return 00044 returns true. 00045 */ 00046 inline bool IdenticalPar(const double &x) 00047 { return true; } 00048 // --------------------------------------------------------------------------- 00049 /*! 00050 Determine if an AD<Base> object is a parameter, and could never have 00051 a different value during any tape playback. 00052 00053 An AD<Base> object \c x is identically a parameter if and only if 00054 all of the objects in the following chain are parameters: 00055 \code 00056 x , x.value , x.value.value , ... 00057 \endcode 00058 In such a case, the value of the object will always be the same 00059 no matter what the independent variable values are at any level. 00060 00061 \param x 00062 values that we are checking for identically a pamameter. 00063 00064 \return 00065 returns true iff \c x is identically a parameter. 00066 */ 00067 template <class Base> 00068 CPPAD_INLINE bool IdenticalPar(const AD<Base> &x) 00069 { return Parameter(x) && IdenticalPar(x.value_); } 00070 // Zero ============================================================== 00071 /*! 00072 Check if a float is equal to zero, used by <tt>IdenticalZero(AD<float>)</tt>. 00073 00074 \param x 00075 value we are checking. 00076 00077 \return 00078 returns true iff the argument equals zero. 00079 */ 00080 inline bool IdenticalZero(const float &x) 00081 { return (x == 0.); } 00082 // -------------------------------------------------------------------------- 00083 /*! 00084 Check if a double is equal to zero, used by <tt>IdenticalZero(AD<double>)</tt>. 00085 00086 \param x 00087 value we are checking. 00088 00089 \return 00090 returns true iff the argument equals zero. 00091 */ 00092 inline bool IdenticalZero(const double &x) 00093 { return (x == 0.); } 00094 // -------------------------------------------------------------------------- 00095 /*! 00096 Determine if an AD<Base> is equal to zero, 00097 and must be equal zero during any tape playback. 00098 00099 \param x 00100 object that we are checking. 00101 00102 \return 00103 returns true if and only if 00104 \c x is equals zero and is identically a parameter \ref IdenticalPar. 00105 */ 00106 template <class Base> 00107 CPPAD_INLINE bool IdenticalZero(const AD<Base> &x) 00108 { return Parameter(x) && IdenticalZero(x.value_); } 00109 // One ============================================================== 00110 /*! 00111 Check if a float is equal to one, used by <tt>IdenticalOne(AD<float>)</tt>. 00112 00113 \param x 00114 value we are checking. 00115 00116 \return 00117 returns true iff the argument equals one. 00118 */ 00119 inline bool IdenticalOne(const float &x) 00120 { return (x == 1.); } 00121 // -------------------------------------------------------------------------- 00122 /*! 00123 Check if a double is equal to one, used by <tt>IdenticalOne(AD<double>)</tt>. 00124 00125 \param x 00126 value we are checking. 00127 00128 \return 00129 returns true iff the argument equals one. 00130 */ 00131 inline bool IdenticalOne(const double &x) 00132 { return (x == 1.); } 00133 // -------------------------------------------------------------------------- 00134 /*! 00135 Determine if an AD<Base> is equal to one, 00136 and must be equal one during any tape playback. 00137 00138 \param x 00139 object that we are checking. 00140 00141 \return 00142 returns true if and only if 00143 \c x is equals one and is identically a parameter \ref IdenticalPar. 00144 */ 00145 template <class Base> 00146 CPPAD_INLINE bool IdenticalOne(const AD<Base> &x) 00147 { return Parameter(x) && IdenticalOne(x.value_); } 00148 // Equal =================================================================== 00149 /*! 00150 Check if two floats are equal, 00151 used by <tt>IdenticalEqualPar(AD<float>, AD<float>)</tt>. 00152 00153 \param x 00154 first float we are checking. 00155 00156 \param y 00157 second float we are checking. 00158 00159 \return 00160 returns true iff the arugments are equal. 00161 */ 00162 inline bool IdenticalEqualPar(const float &x, const float &y) 00163 { return (x == y); } 00164 // -------------------------------------------------------------------------- 00165 /*! 00166 Check if two doubles are equal, 00167 used by <tt>IdenticalEqualPar(AD<double>, AD<double>)</tt>. 00168 00169 \param x 00170 first double we are checking. 00171 00172 \param y 00173 second double we are checking. 00174 00175 \return 00176 returns true iff the arugments are equal. 00177 */ 00178 inline bool IdenticalEqualPar(const double &x, const double &y) 00179 { return (x == y); } 00180 // -------------------------------------------------------------------------- 00181 /*! 00182 Determine if two AD<Base> objects are equal, 00183 and must be equal during any tape playback. 00184 00185 \param x 00186 first of two objects we are checking for equal. 00187 00188 \param y 00189 second of two objects we are checking for equal. 00190 00191 \return 00192 returns true if and only if 00193 the arguments are equal and both identically parameters \ref IdenticalPar. 00194 */ 00195 template <class Base> 00196 CPPAD_INLINE bool IdenticalEqualPar 00197 (const AD<Base> &x, const AD<Base> &y) 00198 { bool parameter; 00199 parameter = ( Parameter(x) & Parameter(y) ); 00200 return parameter && IdenticalEqualPar(x.value_, y.value_); 00201 } 00202 // ========================================================================== 00203 00204 CPPAD_END_NAMESPACE 00205 # endif