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

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

faq.xml @upstream/2015.00.00.7raw · history · blame

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Frequently Asked Questions and Answers</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Frequently Asked Questions and Answers"/>
<meta name="keywords" id="keywords" content=" Faq frequently asked questions and answers assignment independent operator bugs reporting comparechange Comparechange Ndebug complex types faq exceptions test exception Errorhandler variables variable tape avoid record speed taping math functions function matrix inverse mode: forward or reverse mode namespace vector preprocessor symbol Cppad_testvector symbols using standard ndebug optimize memory allocation storage: disk storage "/>
<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='_faq_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="appendix.xml" target="_top">Prev</a>
</td><td><a href="theory.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>Appendix</option>
<option>Faq</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>Appendix-&gt;</option>
<option>Faq</option>
<option>Theory</option>
<option>glossary</option>
<option>Bib</option>
<option>Bugs</option>
<option>WishList</option>
<option>whats_new</option>
<option>deprecated</option>
<option>compare_c</option>
<option>License</option>
</select>
</td>
<td>Faq</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Assignment and Independent</option>
<option>Bugs</option>
<option>CompareChange</option>
<option>Complex Types</option>
<option>Exceptions</option>
<option>Independent Variables</option>
<option>Math Functions</option>
<option>Matrix Inverse</option>
<option>Mode: Forward or Reverse</option>
<option>Namespace</option>
<option>---..Test Vector Preprocessor Symbol</option>
<option>---..Using</option>
<option>Speed</option>
<option>---..NDEBUG</option>
<option>---..Optimize</option>
<option>---..Memory Allocation</option>
<option>Tape Storage: Disk or Memory</option>
</select>
</td>
</tr></table><br/>
<center><b><big><big>Frequently Asked Questions and Answers</big></big></b></center>
<br/>
<b><big><a name="Assignment and Independent" id="Assignment and Independent">Assignment and Independent</a></big></b>



<br/>
Why does the code sequence

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;Independent(</span></font><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><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'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>[0];<br/>
</span></font></code>
behave differently from the code sequence

<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'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>[0];<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;Independent(</span></font><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>);<br/>
</span></font></code>
Before the call to <a href="independent.xml" target="_top"><span style='white-space: nowrap'>Independent</span></a>
,

<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>[0]</span></font></code>
 is a <a href="glossary.xml#Parameter" target="_top"><span style='white-space: nowrap'>parameter</span></a>

and after the call it is a variable.
Thus in the first case, 
<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>
 is a variable
and in the second case it is a parameter.

<br/>
<br/>
<b><big><a name="Bugs" id="Bugs">Bugs</a></big></b>

<br/>
What should I do if I suspect that there is a bug in CppAD ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code><ol type="1"><li>The first step is to search this page for mention of
some feature that perhaps you interpreting as a bug
(and is not).
If this does not solve your problem, continue
to the next step.
</li><li>

The second step is to check the 
<a href="whats_new.xml" target="_top"><span style='white-space: nowrap'>whats_new</span></a>
 messages from the date 
of the release that you are using to the current date.
If the bug has been mentioned and fixed,
then <a href="install.xml" target="_top"><span style='white-space: nowrap'>install</span></a>
 the current version of CppAD.
If this does not solve your problem, continue
to the next step.
</li><li>

Send an e-mail message to the mailing list 
<a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_top"><span style='white-space: nowrap'>cppad@list.coin-or.org</span></a>

with a description of the bug.
Attaching a small source code sample program that 
demonstrates the bug is always helpful.
The smaller the program, the better the bug report.
</li></ol>


<br/>
<br/>
<b><big><a name="CompareChange" id="CompareChange">CompareChange</a></big></b>


<br/>
If you attempt to use the 
<a href="comparechange.xml" target="_top"><span style='white-space: nowrap'>CompareChange</span></a>

function when <code><font color="blue">NDEBUG</font></code> is true,
you will get an error message stating that
<code><font color="blue">CompareChange</font></code> is not a member of the
<a href="adfun.xml" target="_top"><span style='white-space: nowrap'>ADFun</span></a>
 template class.

<br/>
<br/>
<b><big><a name="Complex Types" id="Complex Types">Complex Types</a></big></b>

<br/>
Which of the following complex types is better:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;AD&lt;&#xA0;std::complex&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;&gt;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::complex&lt;&#xA0;AD&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;&gt;<br/>
</span></font></code>
The <a href="abs.xml#Complex Types" target="_top"><span style='white-space: nowrap'>complex&#xA0;abs&#xA0;function</span></a>
 is differentiable
with respect to its real and imaginary parts,
but it is not complex differentiable.
Thus one would prefer to use

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::complex&lt;&#xA0;AD&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;&gt;<br/>
</span></font></code>
On the other hand, the C++ standard only specifies 

<code><font color="blue"><span style='white-space: nowrap'>std::complex&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 where 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
 is 
<code><font color="blue">float</font></code>, <code><font color="blue">double</font></code>, or <code><font color="blue">lone double</font></code>.
The effect of instantiating the template complex for any other type 
is unspecified. 

<br/>
<br/>
<b><big><a name="Exceptions" id="Exceptions">Exceptions</a></big></b>



<br/>
Why, in all the examples, do you pass back a boolean variable instead
of throwing an exception ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The examples are also used to test the correctness of CppAD
and to check your installation.
For these two uses, it is helpful to run all the tests
and to know which ones failed.
The actual code in CppAD uses the <a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>
 utility
to signal exceptions.
Specifications for redefining this action are provided.

<br/>
<br/>
<b><big><a name="Independent Variables" id="Independent Variables">Independent Variables</a></big></b>




<br/>
Is it possible to evaluate the same tape recording with different values 
for the independent variables ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Yes (see <a href="forward_zero.xml" target="_top"><span style='white-space: nowrap'>forward_zero</span></a>
). 

<br/>
<br/>
<b><big><a name="Math Functions" id="Math Functions">Math Functions</a></big></b>


<br/>
Are there plans to add more math functions to CppAD ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Yes. The <a href="std_math_ad.xml" target="_top"><span style='white-space: nowrap'>std_math_ad</span></a>
 and <a href="mathother.xml" target="_top"><span style='white-space: nowrap'>MathOther</span></a>
 section contains
a list of the math functions included so far.
Contact the mailing list 
<a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_top"><span style='white-space: nowrap'>cppad@list.coin-or.org</span></a>

if you need a math function that is has not yet been included.



<br/>
<br/>
<b><big><a name="Matrix Inverse" id="Matrix Inverse">Matrix Inverse</a></big></b>


<br/>
Is it possible to differentiate (with respect to the matrix elements)
the computation of the inverse of a matrix 
where the computation of the inverse uses pivoting ? 
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The example routine <a href="lusolve.xml" target="_top"><span style='white-space: nowrap'>LuSolve</span></a>
 can be used to do this
because the inverse is a special case of the solution of linear equations.
The examples 
<a href="jac_lu_det.cpp.xml" target="_top"><span style='white-space: nowrap'>jac_lu_det.cpp</span></a>
 and <a href="hes_lu_det.cpp.xml" target="_top"><span style='white-space: nowrap'>hes_lu_det.cpp</span></a>

use LuSolve to compute derivatives of the 
determinant with respect to the components of the matrix.

<br/>
<br/>
<b><big><a name="Mode: Forward or Reverse" id="Mode: Forward or Reverse">Mode: Forward or Reverse</a></big></b>



<br/>
When evaluating derivatives, 
one always has a choice between 
forward and reverse mode.
How does one decide which mode to use ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>In general, the best mode depends on the number of domain and range
components in the function that your are differentiating.
Each call to <a href="forward.xml" target="_top"><span style='white-space: nowrap'>Forward</span></a>
 computes the derivative of all 
the range directions with respect to one domain direction.
Each call to <a href="reverse.xml" target="_top"><span style='white-space: nowrap'>Reverse</span></a>
 computes the derivative of one 
range direction with respect to all the domain directions.
The times required for (speed of) 
calls <code><font color="blue">Forward</font></code> and <code><font color="blue">Reverse</font></code> are about equal.  
The <a href="seq_property.xml#Parameter" target="_top"><span style='white-space: nowrap'>Parameter</span></a>
 
function can be used to quickly determine that 
some range directions have derivative zero.



<br/>
<br/>
<b><big><a name="Namespace" id="Namespace">Namespace</a></big></b>




<br/>
<br/>
<b><a name="Namespace.Test Vector Preprocessor Symbol" id="Namespace.Test Vector Preprocessor Symbol">Test Vector Preprocessor Symbol</a></b>



<br/>
Why do you use <code><font color="blue">CPPAD_TESTVECTOR</font></code> instead of a namespace for
the CppAD <a href="testvector.xml" target="_top"><span style='white-space: nowrap'>testvector</span></a>
 class ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The preprocessor symbol 
<small><a href="testvector.xml" target="_top"><span style='white-space: nowrap'>CPPAD_TESTVECTOR</span></a>
 </small>
determines which
<a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>SimpleVector</span></a>
 template class is used for extensive testing.
The default definition for <code><font color="blue">CPPAD_TESTVECTOR</font></code> is the
<a href="cppad_vector.xml" target="_top"><span style='white-space: nowrap'>CppAD::vector</span></a>
 template class, but it can be changed.
Note that all the preprocessor symbols that are defined or used
by CppAD begin with either <code><font color="blue">CPPAD</font></code>
(some old deprecated symbols begin with <code><font color="blue">CppAD</font></code>).

<br/>
<br/>
<b><a name="Namespace.Using" id="Namespace.Using">Using</a></b>



<br/>
Why do I have trouble when the following command
<code><font color='blue'><pre style='display:inline'> 
	using namespace CppAD
</pre></font></code>

is at the global level 
(not within a function or some other limited scope).
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Some versions of <code><font color="blue"># include &lt;cmath&gt;</font></code> for
gcc and Visual C++ define the standard math functions,
(for example 
<code><font color="blue"><span style='white-space: nowrap'>double&#xA0;sqrt(double&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
)
at the global level.
It is necessary to put your <code><font color="blue">using</font></code> commands within the scope
of a function,
or some other limited scope,
in order to shadow these improper global definitions.

<br/>
<br/>
<b><big><a name="Speed" id="Speed">Speed</a></big></b>


<br/>
How do I get the best speed performance out of CppAD ?

<br/>
<br/>
<b><a name="Speed.NDEBUG" id="Speed.NDEBUG">NDEBUG</a></b>
<br/>
You should compile your code with optimization, without debugging,
and with the preprocessor symbol <code><font color="blue">NDEBUG</font></code> defined.
(The <a href="speed_cppad.xml" target="_top"><span style='white-space: nowrap'>speed_cppad</span></a>
 tests do this.)
Note that defining <code><font color="blue">NDEBUG</font></code>
will turn off all of the error checking and reporting that
is done using <a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>
. 

<br/>
<br/>
<b><a name="Speed.Optimize" id="Speed.Optimize">Optimize</a></b>
<br/>
It is also possible that preforming a tape 
<a href="optimize.xml" target="_top"><span style='white-space: nowrap'>optimization</span></a>
 will improve the speed of evaluation
more than the time required for the optimization.

<br/>
<br/>
<b><a name="Speed.Memory Allocation" id="Speed.Memory Allocation">Memory Allocation</a></b>
<br/>
You may also increase execution speed
by calling <code><font color="blue">hold_memory</font></code> with
<a href="ta_hold_memory.xml#value" target="_top"><span style='white-space: nowrap'>value</span></a>
 equal to true.

<br/>
<br/>
<b><big><a name="Tape Storage: Disk or Memory" id="Tape Storage: Disk or Memory">Tape Storage: Disk or Memory</a></big></b>




<br/>
Does CppAD store the tape on disk or in memory ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>CppAD uses memory to store a different tape for recording operations
for each 
<code><font color="blue"><span style='white-space: nowrap'>AD&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;</span></font></code>
 type that is used.
If you have a very large number calculations that are recorded
on a tape, the tape will keep growing to hold the necessary information.
Eventually, virtual memory may be used to store the tape 
and the calculations may slow down because of necessary disk access.



<hr/>Input File: omh/faq.omh

</body>
</html>