Codebase list cppad / upstream/2015.00.00.7 doc / capacity_order.xml
upstream/2015.00.00.7

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

capacity_order.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>Controlling Taylor Coefficients Memory Allocation</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Controlling Taylor Coefficients Memory Allocation"/>
<meta name="keywords" id="keywords" content=" Forward capacity capacity_order control memory controlling taylor coefficients allocation syntax see also purpose f c pre-allocating freeing original state example "/>
<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_order_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="compare_change.cpp.xml" target="_top">Prev</a>
</td><td><a href="capacity_order.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_order</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>
<option>check_for_nan</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>forward_zero</option>
<option>forward_one</option>
<option>forward_two</option>
<option>forward_order</option>
<option>forward_dir</option>
<option>size_order</option>
<option>CompareChange</option>
<option>capacity_order</option>
<option>number_skip</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>capacity_order-&gt;</option>
<option>capacity_order.cpp</option>
</select>
</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>---..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><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity_order(</span></font><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><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 and higher order Forward mode calculations.
For example, a call to <a href="forward_order.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><i><font color="black"><span style='white-space: nowrap'>yq</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><font color="blue"><span style='white-space: nowrap'>.Forward(</span></font><i><font color="black"><span style='white-space: nowrap'>q</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>xq</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
where 
<code><i><font color="black"><span style='white-space: nowrap'>q</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&gt;&#xA0;0</span></font></code>
 and  <code><font color="blue">%xq%.size() == %f%.Domain()%</font></code>,
uses the lower order Taylor coefficients and 
computes the <code><i>q</i></code>-th order Taylor coefficients for all
the variables in the operation sequence corresponding to 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
.
The <code><font color="blue">capacity_order</font></code> operation allows you to control that 
amount of memory that is retained by an AD function object 
(to hold <code><font color="blue">Forward</font></code> results for subsequent calculations).

<br/>
<br/>
<b><big><a name="f" id="f">f</a></big></b>
<br/>
The object 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;ADFun&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><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 
<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It specifies the number of Taylor coefficient orders that are allocated 
in the AD operation sequence corresponding to 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
.

<br/>
<br/>
<b><a name="c.Pre-Allocating Memory" id="c.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 

<code><i><font color="black"><span style='white-space: nowrap'>q</span></font></i></code>
 equal to 
<code><i><font color="black"><span style='white-space: nowrap'>Q</span></font></i></code>
,
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><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity_order(</span></font><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
with 
<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
 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="c.Freeing Memory" id="c.Freeing Memory">Freeing Memory</a></b>
<br/>
If you no longer need the Taylor coefficients of order 
<code><i><font color="black"><span style='white-space: nowrap'>q</span></font></i></code>

and higher (that are stored in 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
), 
you can reduce the memory allocated to 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
 using

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity_order(</span></font><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
with 
<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
 equal to 
<code><i><font color="black"><span style='white-space: nowrap'>q</span></font></i></code>
.
Note that, if <a href="ta_hold_memory.xml" target="_top"><span style='white-space: nowrap'>ta_hold_memory</span></a>
 is true, this memory is not actually 
returned to the system, but rather held for future use by the same thread. 

<br/>
<br/>
<b><big><a name="Original State" id="Original State">Original State</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>f</span></font></i></code>
 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><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>f</span></font></i><font color="blue"><span style='white-space: nowrap'>(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
,
there is an implicit call to <a href="forward_zero.xml" target="_top"><span style='white-space: nowrap'>forward_zero</span></a>
 with 
<code><i><font color="black"><span style='white-space: nowrap'>xq</span></font></i></code>
 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.
This corresponds to 
<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;==&#xA0;1</span></font></code>
.


<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>
<br/>
The file 
<a href="capacity_order.cpp.xml" target="_top"><span style='white-space: nowrap'>capacity_order.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/capacity_order.hpp

</body>
</html>