source: trunk/cppad/local/print_op.hpp @ 3301

Last change on this file since 3301 was 3301, checked in by bradbell, 6 years ago

merge in multiple forward direcitons from branches/forward_dir

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* $Id: print_op.hpp 3301 2014-05-24 05:20:21Z bradbell $ */
2# ifndef CPPAD_PRINT_OP_INCLUDED
3# define CPPAD_PRINT_OP_INCLUDED
4
5/* --------------------------------------------------------------------------
6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
7
8CppAD is distributed under multiple licenses. This distribution is under
9the terms of the
10                    Eclipse Public License Version 1.0.
11
12A copy of this license is included in the COPYING file of this distribution.
13Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14-------------------------------------------------------------------------- */
15
16
17namespace CppAD { // BEGIN_CPPAD_NAMESPACE
18/*!
19Print operation for parameters; i.e., op = PriOp.
20
21The 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
27The PrintFor call puts the print operation on the tape
28and the print occurs during the zero order forward mode computation.
29
30\tparam Base
31base type for the operator; i.e., this operation was recorded
32using AD< \a Base > and computations by this routine are done using type
33\a Base .
34
35\param s_out
36the results are printed on this output stream.
37
38\param i_z
39is the index of the next variable on the tape
40(only used for error checking).
41
42\param arg
43\a arg[0] & 1
44\n
45If this is zero, \a pos is a parameter. Otherwise it is a variable.
46\n
47\a arg[0] & 2
48\n
49If this is zero, \a var is a parameter. Otherwise it is a variable.
50\n
51\n
52\a arg[1]
53\n
54If \a pos is a parameter, <code>parameter[arg[1]]</code> is its value.
55Othwise <code>taylor[ arg[1] * cap_order + 0 ]</code> is the zero
56order Taylor coefficient for \a pos.
57\n
58\n
59\a arg[2]
60\n
61index of the text to be printed before \a var
62if \a pos is not a positive value.
63\n
64\n
65\a arg[3]
66\n
67If \a var is a parameter, <code>parameter[arg[3]]</code> is its value.
68Othwise <code>taylor[ arg[3] * cap_order + 0 ]</code> is the zero
69order Taylor coefficient for \a var.
70\n
71\n
72\a arg[4]
73\n
74index of the text to be printed after \a var
75if \a pos is not a positive value.
76
77\param num_text
78is the total number of text characters on the tape
79(only used for error checking).
80
81\param text
82\b Input: <code>text[arg[1]]</code> is the first character of the text
83that will be printed. All the characters from there to (but not including)
84the first '\\0' are printed.
85
86\param num_par
87is the total number of values in the \a parameter vector
88
89\param parameter
90Contains the value of parameters.
91
92\param cap_order
93number of colums in the matrix containing all the Taylor coefficients.
94
95\param taylor
96Contains the value of variables.
97
98\par Checked Assertions:
99\li NumArg(PriOp)  == 5
100\li NumRes(PriOp)  == 0
101\li text          !=  CPPAD_NULL
102\li arg[1]         <  num_text
103\li if \a pos is a variable, arg[1] < i_z, otherwise arg[1] < num_par
104\li if \a var is a variable, arg[3] < i_z, otherwise arg[3] < num_par
105*/
106template <class Base>
107inline void forward_pri_0(
108        std::ostream& s_out       ,
109        size_t        i_z         ,
110        const addr_t* arg         ,
111        size_t        num_text    ,
112        const char*   text        ,
113        size_t        num_par     ,
114        const Base*   parameter   ,
115        size_t        cap_order   ,
116        const Base*   taylor      )
117{       Base pos, var;
118        const char* before;
119        const char* after;
120        CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0);
121
122        // pos
123        if( arg[0] & 1 )
124        {       CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= i_z );
125                pos = taylor[ arg[1] * cap_order + 0 ];
126        }
127        else
128        {       CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
129                pos = parameter[ arg[1] ];
130        }
131
132        // before
133        CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
134        before = text + arg[2];
135
136        // var
137        if( arg[0] & 2 )
138        {       CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z );
139                var = taylor[ arg[3] * cap_order + 0 ];
140        }
141        else
142        {       CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
143                var = parameter[ arg[3] ];
144        }
145
146        // after
147        CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
148        after = text + arg[4];
149
150        if( ! GreaterThanZero( pos ) )
151                s_out << before << var << after;
152}
153
154} // END_CPPAD_NAMESPACE
155# endif
Note: See TracBrowser for help on using the repository browser.