Codebase list cppad / upstream/2015.00.00.7 doc / ad_output.cpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

ad_output.cpp.xml @upstream/2015.00.00.7raw · history · blame

<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>AD Output Operator: Example and Test</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="AD Output Operator: Example and Test"/>
<meta name="keywords" id="keywords" content=" ad output operator: example and test &lt;&lt; Ad "/>
<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='_ad_output.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="ad_output.xml" target="_top">Prev</a>
</td><td><a href="printfor.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>ad_output</option>
<option>ad_output.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>ad_output-&gt;</option>
<option>ad_output.cpp</option>
</select>
</td>
<td>ad_output.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>AD Output Operator: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

# include &lt;sstream&gt;  // std::ostringstream
# include &lt;string&gt;   // std::string
# include &lt;iomanip&gt;  // std::setprecision, setw, setfill, right

namespace {
	template &lt;class S&gt;
	void set_ostream(S &amp;os)
	{	os 
		&lt;&lt; std::setprecision(4) // 4 digits of precision
		&lt;&lt; std::setw(6)         // 6 characters per field
		&lt;&lt; std::setfill(' ')    // fill with spaces
		&lt;&lt; std::right;          // adjust value to the right
	}
}

bool ad_output(void)
{	bool ok = true;

	// This output stream is an ostringstream for testing purposes.
	// You can use &lt;&lt; with other types of streams; i.e., std::cout.
	std::ostringstream stream;

	// ouput an <a href="ad.xml" target="_top">AD</a>&lt;double&gt; object
	CppAD::<a href="ad.xml" target="_top">AD</a>&lt;double&gt;  pi = 4. * atan(1.); // 3.1415926536
	set_ostream(stream);
	stream &lt;&lt; pi;

	// ouput a VecAD&lt;double&gt;::reference object
	CppAD::VecAD&lt;double&gt; v(1);
	CppAD::<a href="ad.xml" target="_top">AD</a>&lt;double&gt; zero(0);
	v[zero]   = exp(1.);                  // 2.7182818285
	set_ostream(stream); 
	stream &lt;&lt; v[zero];

	// convert output from stream to string
	std::string str = stream.str();

	// check the output
	ok      &amp;= (str == &quot; 3.142 2.718&quot;);

	return ok;
}
</pre>

</font></code>


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

</body>
</html>