CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
print_op.hpp
Go to the documentation of this file.
1 // $Id: print_op.hpp 3845 2016-11-19 01:50:47Z bradbell $
2 # ifndef CPPAD_LOCAL_PRINT_OP_HPP
3 # define CPPAD_LOCAL_PRINT_OP_HPP
4 
5 /* --------------------------------------------------------------------------
6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
7 
8 CppAD is distributed under multiple licenses. This distribution is under
9 the terms of the
10  Eclipse Public License Version 1.0.
11 
12 A copy of this license is included in the COPYING file of this distribution.
13 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14 -------------------------------------------------------------------------- */
15 
16 
17 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
18 /*!
19 Print operation for parameters; i.e., op = PriOp.
20 
21 The C++ source code corresponding to this operation is
22 \verbatim
23  f.Forward(0, x)
24  PrintFor(before, var)
25  PrintFor(pos, before, var, after)
26 \endverbatim
27 The PrintFor call puts the print operation on the tape
28 and the print occurs during the zero order forward mode computation.
29 
30 \tparam Base
31 base type for the operator; i.e., this operation was recorded
32 using AD< \a Base > and computations by this routine are done using type
33 \a Base .
34 
35 \param s_out
36 the results are printed on this output stream.
37 
38 \param arg
39 \a arg[0] & 1
40 \n
41 If this is zero, \a pos is a parameter. Otherwise it is a variable.
42 \n
43 \a arg[0] & 2
44 \n
45 If this is zero, \a var is a parameter. Otherwise it is a variable.
46 \n
47 \n
48 \a arg[1]
49 \n
50 If \a pos is a parameter, <code>parameter[arg[1]]</code> is its value.
51 Othwise <code>taylor[ arg[1] * cap_order + 0 ]</code> is the zero
52 order Taylor coefficient for \a pos.
53 \n
54 \n
55 \a arg[2]
56 \n
57 index of the text to be printed before \a var
58 if \a pos is not a positive value.
59 \n
60 \n
61 \a arg[3]
62 \n
63 If \a var is a parameter, <code>parameter[arg[3]]</code> is its value.
64 Othwise <code>taylor[ arg[3] * cap_order + 0 ]</code> is the zero
65 order Taylor coefficient for \a var.
66 \n
67 \n
68 \a arg[4]
69 \n
70 index of the text to be printed after \a var
71 if \a pos is not a positive value.
72 
73 \param num_text
74 is the total number of text characters on the tape
75 (only used for error checking).
76 
77 \param text
78 \b Input: <code>text[arg[1]]</code> is the first character of the text
79 that will be printed. All the characters from there to (but not including)
80 the first '\\0' are printed.
81 
82 \param num_par
83 is the total number of values in the \a parameter vector
84 
85 \param parameter
86 Contains the value of parameters.
87 
88 \param cap_order
89 number of colums in the matrix containing all the Taylor coefficients.
90 
91 \param taylor
92 Contains the value of variables.
93 
94 \par Checked Assertions:
95 \li NumArg(PriOp) == 5
96 \li NumRes(PriOp) == 0
97 \li text != CPPAD_NULL
98 \li arg[1] < num_text
99 \li if \a pos is a parameter, arg[1] < num_par
100 \li if \a var is a parameter, arg[3] < num_par
101 */
102 template <class Base>
103 inline void forward_pri_0(
104  std::ostream& s_out ,
105  const addr_t* arg ,
106  size_t num_text ,
107  const char* text ,
108  size_t num_par ,
109  const Base* parameter ,
110  size_t cap_order ,
111  const Base* taylor )
112 { Base pos, var;
113  const char* before;
114  const char* after;
116 
117  // pos
118  if( arg[0] & 1 )
119  { pos = taylor[ arg[1] * cap_order + 0 ];
120  }
121  else
122  { CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
123  pos = parameter[ arg[1] ];
124  }
125 
126  // before
127  CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
128  before = text + arg[2];
129 
130  // var
131  if( arg[0] & 2 )
132  { var = taylor[ arg[3] * cap_order + 0 ];
133  }
134  else
135  { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
136  var = parameter[ arg[3] ];
137  }
138 
139  // after
140  CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
141  after = text + arg[4];
142 
143  if( ! GreaterThanZero( pos ) )
144  s_out << before << var << after;
145 }
146 
147 } } // END_CPPAD_LOCAL_NAMESPACE
148 # endif
void forward_pri_0(std::ostream &s_out, const addr_t *arg, size_t num_text, const char *text, size_t num_par, const Base *parameter, size_t cap_order, const Base *taylor)
Print operation for parameters; i.e., op = PriOp.
Definition: print_op.hpp:103
CPPAD_TAPE_ADDR_TYPE addr_t
Definition: declare_ad.hpp:44
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
#define CPPAD_ASSERT_NARG_NRES(op, n_arg, n_res)
Check that operator op has the specified number of of arguments and results.
bool GreaterThanZero(const std::complex< double > &x)