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