CppAD: A C++ Algorithmic Differentiation Package  20130918
discrete_op.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_DISCRETE_OP_INCLUDED
00003 # define CPPAD_DISCRETE_OP_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 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 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
00018 /*!
00019 \file discrete_op.hpp
00020 Zero order forward mode for z = f(x) where f is piecewise constant.
00021 */
00022 
00023 
00024 /*!
00025 Compute zero order forward mode Taylor coefficient for result of op = DisOp.
00026 
00027 The C++ source code corresponding to this operation is
00028 \verbatim
00029      z = f(x)
00030 \endverbatim
00031 where f is a piecewise constant function (and it's derivative is always
00032 calculated as zero).
00033 
00034 \tparam Base
00035 base type for the operator; i.e., this operation was recorded
00036 using AD< \a Base > and computations by this routine are done using type 
00037 \a Base .
00038 
00039 \param i_z
00040 variable index corresponding to the result for this operation; 
00041 i.e. the row index in \a taylor corresponding to z. 
00042 
00043 \param arg
00044 \a arg[0]
00045 \n
00046 is the index, in the order of the discrete functions defined by the user, 
00047 for this discrete function.
00048 \n
00049 \n
00050 \a arg[1]
00051 variable index corresponding to the argument for this operator;
00052 i.e. the row index in \a taylor corresponding to x.
00053 
00054 \param nc_taylor
00055 number of colums in the matrix containing all the Taylor coefficients.
00056 
00057 \param taylor
00058 \b Input: \a taylor [ \a arg[1] * \a nc_taylor + 0 ] 
00059 is the zero order Taylor coefficient corresponding to x. 
00060 \n
00061 \b Output: \a taylor [ \a i_z * \a nc_taylor + 0 ] 
00062 is the zero order Taylor coefficient corresponding to z. 
00063 
00064 \par Checked Assertions where op is the unary operator with one result:
00065 \li NumArg(op) == 2
00066 \li NumRes(op) == 1
00067 \li \a arg[1] < \a i_z 
00068 \li \a 0 < \a nc_taylor
00069 */
00070 template <class Base>
00071 inline void forward_dis_op_0(
00072      size_t        i_z         ,
00073      const addr_t* arg         ,
00074      size_t        nc_taylor   , 
00075      Base*         taylor      )
00076 {    
00077      // check assumptions
00078      CPPAD_ASSERT_UNKNOWN( NumArg(DisOp) == 2 );
00079      CPPAD_ASSERT_UNKNOWN( NumRes(DisOp) == 1 );
00080      CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z );
00081      CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor );
00082 
00083      // Taylor coefficients corresponding to argument and result
00084      Base* x = taylor + arg[1] * nc_taylor;
00085      Base* z = taylor + i_z * nc_taylor;
00086 
00087      z[0]  = discrete<Base>::eval(arg[0], x[0]);
00088 }
00089 
00090 
00091 } // END_CPPAD_NAMESPACE
00092 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines