/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/abs_op.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_ABS_OP_INCLUDED
00002 # define CPPAD_ABS_OP_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 
00015 /*
00016 $begin ForAbsOp$$ $comment CppAD Developer Documentation$$
00017 $spell
00018         Abs
00019         Taylor
00020         const
00021         inline
00022         Op
00023 $$
00024 
00025 $index abs, forward$$
00026 $index forward, abs$$
00027 $index ForAbsOp$$
00028 
00029 $section Forward Mode Absolute Value Function$$
00030 
00031 $head Syntax$$
00032 
00033 $syntax%inline void ForAbsOp(size_t %d%,
00034         %Base% *%z%, const %Base% *%x%)%$$
00035 
00036 $head Description$$
00037 Computes the $italic d$$ order Taylor coefficient for $latex Z$$ where
00038 $syntax%
00039         %Z% = Abs(%X%)
00040 %$$
00041 
00042 $head x$$
00043 The vector $italic x$$ has length $latex d+1$$ and contains the
00044 $th d$$ order Taylor coefficient row vector for $italic X$$.
00045 
00046 $head z$$
00047 The vector $italic z$$ has length $latex d+1$$.
00048 On input it contains the
00049 $th d-1$$ order Taylor coefficient row vector for $italic Z$$.
00050 On output it contains the
00051 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e.,
00052 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for
00053 the function $italic Z$$.
00054 
00055 $end
00056 ------------------------------------------------------------------------------
00057 $begin RevAbsOp$$ $comment CppAD Developer Documentation$$
00058 $spell
00059         Abs
00060         Taylor
00061         const
00062         inline
00063         Op
00064         px
00065         py
00066         pz
00067 $$
00068 
00069 $index abs, reverse$$
00070 $index reverse, abs$$
00071 $index RevAbsOp$$
00072 
00073 $section Reverse Mode Absolute Value Function$$
00074 
00075 $head Syntax$$
00076 
00077 $syntax%inline void RevAbsOp(size_t %d%,
00078         const %Base% *%z%, const %Base% *%x%,
00079          %Base% *%pz%, %Base% *%px%)%$$
00080 
00081 $head Description$$
00082 We are given the partial derivatives for a function
00083 $latex G(z, x)$$ and we wish to compute the partial derivatives for
00084 the function
00085 $latex \[
00086         H(x) = G [ Z(x) , x ]
00087 \]$$
00088 where $latex Z(x)$$ is defined as the 
00089 $th d$$ order Taylor coefficient row vector for $italic Z$$ as
00090 a function of the corresponding row vector for $italic X$$ 
00091 and
00092 $latex \[
00093         Z = Abs(X)
00094 \]$$
00095 Note that $italic Z$$ has been used both the original absolute value 
00096 function and for the corresponding mapping of Taylor coefficients.
00097 
00098 $head x$$
00099 The vector $italic x$$ has length $latex d+1$$ and contains the
00100 $th d$$ order Taylor coefficient row vector for $italic X$$.
00101 
00102 
00103 $head z$$
00104 The vector $italic z$$ has length $latex d+1$$ and contains
00105 $th d$$ order Taylor coefficient row vector for $italic Z$$.
00106 
00107 
00108 $head On Input$$
00109 
00110 $subhead px$$
00111 The vector $italic px$$ has length $latex d+1$$ and 
00112 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$
00113 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00114 
00115 $subhead pz$$
00116 The vector $italic pz$$ has length $latex d+1$$ and 
00117 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$
00118 with respect to the $th j$$ order Taylor coefficient for $italic Y$$.
00119 
00120 $head On Output$$
00121 
00122 $subhead px$$
00123 The vector $italic px$$ has length $latex d+1$$ and 
00124 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$
00125 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00126 
00127 $subhead pz$$
00128 The vector $italic pz$$ has length $latex d+1$$ and 
00129 its contents are no longer specified; i.e., it has
00130 been used for work space.
00131 
00132 $end
00133 ------------------------------------------------------------------------------
00134 */
00135 
00136 // BEGIN CppAD namespace
00137 namespace CppAD {
00138 
00139 template <class Base>
00140 inline void ForAbsOp(size_t j, 
00141         Base *z, const Base *x)
00142 {       size_t k;
00143 
00144         // order that decides positive, negative or zero
00145         k = 0;
00146         while( (k < j) & (x[k] == Base(0)) )
00147                 k++; 
00148 
00149         if( GreaterThanZero(x[k]) )
00150                 z[j]  = x[j];
00151         else if( LessThanZero(x[k]) )
00152                 z[j] = -x[j]; 
00153         else    z[j] = Base(0);
00154 }
00155 
00156 template <class Base>
00157 inline void RevAbsOp(size_t d, 
00158         const Base  *z, const Base *x,
00159               Base *pz,      Base *px)
00160 {       size_t j, k;
00161 
00162         // order that decides positive, negative or zero
00163         k = 0;
00164         while( (k < d) & (x[k] == Base(0)) )
00165                 k++; 
00166 
00167         if( GreaterThanZero(x[k]) )
00168         {       for(j = k; j <= d; j++)
00169                         px[j] += pz[j];
00170         }
00171         else if( LessThanZero(x[k]) )
00172         {       for(j = k; j <= d; j++)
00173                         px[j] -= pz[j];
00174         }
00175 
00176 }
00177 
00178 } // END CppAD namespace
00179 
00180 # endif

Generated on Sun Nov 14 14:06:32 2010 for Coin-All by  doxygen 1.4.7