<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Controlling Taylor Coefficients Memory Allocation</title>
<meta name="description" id="description" content="Controlling Taylor Coefficients Memory Allocation"/>
<meta name="keywords" id="keywords" content=" Forward capacity capacity_taylor memory control "/>
<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='_capacity_taylor_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="comparechange.cpp.xml" target="_top">Prev</a>
</td><td><a href="forward.cpp.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>ADFun</option>
<option>FunEval</option>
<option>Forward</option>
<option>capacity_taylor</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>ADFun-&gt;</option>
<option>Independent</option>
<option>FunConstruct</option>
<option>Dependent</option>
<option>abort_recording</option>
<option>seq_property</option>
<option>FunEval</option>
<option>Drivers</option>
<option>FunCheck</option>
<option>optimize</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>FunEval-&gt;</option>
<option>Forward</option>
<option>Reverse</option>
<option>Sparse</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>Forward-&gt;</option>
<option>ForwardZero</option>
<option>ForwardOne</option>
<option>ForwardAny</option>
<option>size_taylor</option>
<option>CompareChange</option>
<option>capacity_taylor</option>
<option>Forward.cpp</option>
</select>
</td>
<td>capacity_taylor</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>---..See Also</option>
<option>Purpose</option>
<option>f</option>
<option>c</option>
<option>Discussion</option>
<option>---..Pre-Allocating Memory</option>
<option>---..Freeing Memory</option>
<option>---..Original State</option>
<option>Example</option>
</select>
</td>
</tr></table><br/>








<center><b><big><big>Controlling Taylor Coefficients Memory Allocation</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<br/>
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.capacity_taylor(</span></font></code><i><span style='white-space: nowrap'>c</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>

<br/>
<br/>
<b><a name="Syntax.See Also" id="Syntax.See Also">See Also</a></b>

<br/>
<a href="seq_property.xml" target="_top"><span style='white-space: nowrap'>seq_property</span></a>


<br/>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
The Taylor coefficients calculated by <a href="forward.xml" target="_top"><span style='white-space: nowrap'>Forward</span></a>
 mode calculations
are retained in an <a href="adfun.xml" target="_top"><span style='white-space: nowrap'>ADFun</span></a>
 object for subsequent use during 
<a href="reverse.xml" target="_top"><span style='white-space: nowrap'>Reverse</span></a>
 mode or higher order Forward mode calculations.
This operation allow you to control that amount of memory
that is retained by an AD function object 
(for subsequent calculations).

<br/>
<br/>
<b><big><a name="f" id="f">f</a></big></b>
<br/>
The object <i>f</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;ADFun&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="c" id="c">c</a></big></b>
<br/>
The argument <i>c</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;</span></font></code><i><span style='white-space: nowrap'>c</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>It specifies the number of Taylor coefficients that are allocated for
each variable in the AD operation sequence corresponding to <i>f</i>.

<br/>
<br/>
<b><big><a name="Discussion" id="Discussion">Discussion</a></big></b>
<br/>
A call to <a href="forwardany.xml" target="_top"><span style='white-space: nowrap'>Forward</span></a>
 with the syntax
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>y_p</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.Forward(</span></font></code><i><span style='white-space: nowrap'>p</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>x_p</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>uses the lower order Taylor coefficients and 
computes the <i>p</i>-th order Taylor coefficients for all
the variables in the operation sequence corresponding to <i>f</i>.
(You can determine the number of variables in the operation sequence
using the <a href="seq_property.xml#size_var" target="_top"><span style='white-space: nowrap'>size_var</span></a>
 function.)

<br/>
<br/>
<b><a name="Discussion.Pre-Allocating Memory" id="Discussion.Pre-Allocating Memory">Pre-Allocating Memory</a></b>
<br/>
If you plan to make calls to <code><font color="blue">Forward</font></code> with the maximum value of 
<i>p</i> equal to <i>q</i>,
it should be faster to pre-allocate memory for these calls using
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.capacity_taylor(</span></font></code><i><span style='white-space: nowrap'>c</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>with <i>c</i> equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>q</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow></math>

.
If you do no do this, <code><font color="blue">Forward</font></code> will automatically allocate memory
and will copy the results to a larger buffer, when necessary.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Note that each call to <a href="dependent.xml" target="_top"><span style='white-space: nowrap'>Dependent</span></a>
 frees the old memory
connected to the function object and sets the corresponding 
taylor capacity to zero.

<br/>
<br/>
<b><a name="Discussion.Freeing Memory" id="Discussion.Freeing Memory">Freeing Memory</a></b>
<br/>
If you no longer need the Taylor coefficients of order <i>q</i>
and higher (that are stored in <i>f</i>), 
you can reduce the memory allocated to <i>f</i> using
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.capacity_taylor(</span></font></code><i><span style='white-space: nowrap'>c</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>with <i>c</i> equal to <i>q</i>.

<br/>
<br/>
<b><a name="Discussion.Original State" id="Discussion.Original State">Original State</a></b>
<br/>
If <i>f</i> is <a href="funconstruct.xml" target="_top"><span style='white-space: nowrap'>constructed</span></a>
 with the syntax
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;ADFun&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>,
there is an implicit call to <code><font color="blue">Forward</font></code> with <i>p</i> equal to zero
and <i>x_p</i> equal to 
the value of the
<a href="glossary.xml#Tape.Independent Variable" target="_top"><span style='white-space: nowrap'>independent&#xA0;variables</span></a>
 
when the AD operation sequence was recorded.

<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>
<br/>
The file 
<a href="forward.cpp.xml" target="_top"><span style='white-space: nowrap'>Forward.cpp</span></a>

contains an example and test of these operations.
It returns true if it succeeds and false otherwise.


<hr/>Input File: cppad/local/cap_taylor.hpp

</body>
</html>

