File: print_for_string.cpp.xml

package info (click to toggle)
cppad 2014.00.00.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,424 kB
  • ctags: 10,192
  • sloc: xml: 181,438; cpp: 49,002; sh: 5,451; makefile: 1,164; ansic: 190; python: 131; sed: 2
file content (145 lines) | stat: -rw-r--r-- 4,263 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Print During Zero Order Forward Mode: Example and Test</title>
<meta name="description" id="description" content="Print During Zero Order Forward Mode: Example and Test"/>
<meta name="keywords" id="keywords" content=" print zero order forward "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_print_for_string.cpp_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="print_for_cout.cpp.xml" target="_top">Prev</a>
</td><td><a href="var2par.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>AD</option>
<option>Convert</option>
<option>PrintFor</option>
<option>print_for_string.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>AD-&gt;</option>
<option>ad_ctor</option>
<option>ad_assign</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>Convert-&gt;</option>
<option>Value</option>
<option>Integer</option>
<option>ad_input</option>
<option>ad_output</option>
<option>PrintFor</option>
<option>Var2Par</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>PrintFor-&gt;</option>
<option>print_for_cout.cpp</option>
<option>print_for_string.cpp</option>
</select>
</td>
<td>print_for_string.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Print During Zero Order Forward Mode: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &lt;cppad/cppad.hpp&gt;

namespace { 
	using std::endl;
	using CppAD::AD;

	// use of PrintFor to check for invalid function arguments
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; check_log(const <a href="ad.xml" target="_top">AD</a>&lt;double&gt;&amp; y, std::ostream&amp; s_out)
	{	// check <a href="ad.xml" target="_top">AD</a>&lt;double&gt; value during recording
		if( y &lt;= 0 )
			s_out &lt;&lt; &quot;check_log: y == &quot; &lt;&lt; y &lt;&lt; &quot; which is &lt;= 0\n&quot;;

		// check double value during zero order forward calculation
		PrintFor(y, &quot;check_log: y == &quot;, y , &quot; which is &lt;= 0\n&quot;);

		return log(y);
	} 
}

bool print_for(void)
{	bool ok = true;
	using CppAD::PrintFor;
	std::stringstream stream_out;

	// independent variable vector
	size_t n = 1;
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(AD&lt;double&gt;) ax(n);
	ax[0] = 1.;         // value of the independent variable during recording
	<a href="independent.xml" target="_top">Independent</a>(ax);

	// A log evaluations that is OK when x[0] = 1 but not when x[0] = 2.
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; var     = 2. - ax[0];
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; log_var = check_log(var, stream_out);
	ok &amp;= stream_out.str() == &quot;&quot;;

	// dependent variable vector 
	size_t m = 1;
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(AD&lt;double&gt;) ay(m);
	ay[0]    = log_var;

	// define f: x -&gt; y and stop tape recording
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;double&gt; f(ax, ay); 

	// zero order forward with x[0] = 2 
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(double) x(n);
	x[0] = 2.;
	f.<a href="forward.xml" target="_top">Forward</a>(0, x, stream_out);	

	std::string string_out = stream_out.str();
	ok &amp;= stream_out.str() == &quot;check_log: y == 0 which is &lt;= 0\n&quot;;

	return ok;
}
</pre>

</font></code>


<hr/>Input File: example/print_for.cpp

</body>
</html>