CppAD: A C++ Algorithmic Differentiation Package  20130102
print_op.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_PRINT_OP_INCLUDED
00003 # define CPPAD_PRINT_OP_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                     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 Print operation for parameters; i.e., op = PriOp.
00020 
00021 The C++ source code corresponding to this operation is
00022 \verbatim
00023      f.Forward(0, x)
00024      PrintFor(before, var)
00025      PrintFor(pos, before, var, after)
00026 \endverbatim
00027 The PrintFor call puts the print operation on the tape
00028 and the print occurs during the zero order forward mode computation.
00029 
00030 \tparam Base
00031 base type for the operator; i.e., this operation was recorded
00032 using AD< \a Base > and computations by this routine are done using type 
00033 \a Base .
00034 
00035 \param s_out
00036 the results are printed on this output stream.
00037 
00038 \param i_z
00039 is the index of the next variable on the tape
00040 (only used for error checking).
00041 
00042 \param arg
00043 \a arg[0] & 1
00044 \n
00045 If this is zero, \a pos is a parameter. Otherwise it is a variable.
00046 \n
00047 \a arg[0] & 2
00048 \n
00049 If this is zero, \a var is a parameter. Otherwise it is a variable.
00050 \n
00051 \n
00052 \a arg[1]
00053 \n
00054 If \a pos is a parameter, <code>parameter[arg[1]]</code> is its value.
00055 Othwise <code>taylor[ arg[1] * nc_taylor + 0 ]</code> is the zero
00056 order Taylor coefficient for \a pos.
00057 \n
00058 \n
00059 \a arg[2]
00060 \n
00061 index of the text to be printed before \a var
00062 if \a pos is not a positive value.
00063 \n
00064 \n
00065 \a arg[3]
00066 \n
00067 If \a var is a parameter, <code>parameter[arg[3]]</code> is its value.
00068 Othwise <code>taylor[ arg[3] * nc_taylor + 0 ]</code> is the zero
00069 order Taylor coefficient for \a var.
00070 \n
00071 \n
00072 \a arg[4]
00073 \n
00074 index of the text to be printed after \a var
00075 if \a pos is not a positive value.
00076 
00077 \param num_text
00078 is the total number of text characters on the tape
00079 (only used for error checking).
00080 
00081 \param text
00082 \b Input: <code>text[arg[1]]</code> is the first character of the text
00083 that will be printed. All the characters from there to (but not including)
00084 the first '\\0' are printed.
00085 
00086 \param num_par
00087 is the total number of values in the \a parameter vector
00088 
00089 \param parameter
00090 Contains the value of parameters.
00091 
00092 \param nc_taylor
00093 number of colums in the matrix containing all the Taylor coefficients.
00094 
00095 \param taylor
00096 Contains the value of variables.
00097 
00098 \par Checked Assertions:
00099 \li NumArg(PriOp)  == 5
00100 \li NumRes(PriOp)  == 0
00101 \li text          !=  CPPAD_NULL
00102 \li arg[1]         <  num_text
00103 \li if \a pos is a variable, arg[1] < i_z, otherwise arg[1] < num_par
00104 \li if \a var is a variable, arg[3] < i_z, otherwise arg[3] < num_par
00105 */
00106 template <class Base>
00107 inline void forward_pri_0(
00108      std::ostream& s_out       ,
00109      size_t        i_z         ,
00110      const addr_t* arg         ,
00111      size_t        num_text    ,
00112      const char*   text        ,
00113      size_t        num_par     ,
00114      const Base*   parameter   ,
00115      size_t        nc_taylor   ,
00116      const Base*   taylor      )
00117 {    Base pos, var;
00118      const char* before;
00119      const char* after;
00120      CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0);
00121 
00122      // pos
00123      if( arg[0] & 1 )
00124      {    CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= i_z );
00125           pos = taylor[ arg[1] * nc_taylor + 0 ];
00126      }
00127      else
00128      {    CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
00129           pos = parameter[ arg[1] ];
00130      }
00131 
00132      // before
00133      CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
00134      before = text + arg[2];
00135 
00136      // var
00137      if( arg[0] & 2 )
00138      {    CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z );
00139           var = taylor[ arg[3] * nc_taylor + 0 ];
00140      }
00141      else
00142      {    CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
00143           var = parameter[ arg[3] ];
00144      }
00145 
00146      // after
00147      CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
00148      after = text + arg[4];
00149 
00150      if( ! GreaterThanZero( pos ) )
00151           s_out << before << var << after;
00152 }
00153 
00154 CPPAD_END_NAMESPACE
00155 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines