Frequently Asked Questions and Answers
Keywords: frequently asked questions answers Faq operator reporting Errorhandler avoid record taping mode Cppad_testvector standard math function storage assignment independent bugs comparechange complex types exceptions variables matrix inverse mode: forward reverse namespace test vector preprocessor symbol using speed ndebug optimize memory allocation tape storage: disk

| Prev | Next |  |  |  |  | Faq |

Frequently Asked Questions and Answers
Assignment and Independent
Why does the code sequence `
Independent(u);
v = u[0];
` behave differently from the code sequence `
v = u[0];
Independent(u);
` Before the call to Independent , `u[0]` is a parameter and after the call it is a variable. Thus in the first case, `v` is a variable and in the second case it is a parameter.
Bugs
What should I do if I suspect that there is a bug in CppAD ? `
`

1. 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.
2. The second step is to check the whats_new messages from the date of the release that you are using to the current date. If the bug has been mentioned and fixed, then install the current version of CppAD. If this does not solve your problem, continue to the next step.
3. Create a simple as possible demonstration of the bug; see the file `bug/template.sh` for a template that you can edit for that purpose. The smaller the program, the better the bug report.
4. Send an e-mail message to the mailing list cppad@list.coin-or.org with a description of the bug. Attaching your program that demonstrates the bug.

CompareChange
If you attempt to use the CompareChange function when `NDEBUG` is true, you will get an error message stating that `CompareChange` is not a member of the ADFun template class.
Complex Types
Which of the following complex types is better: `
AD< std::complex<Base> >
std::complex< AD<Base> >
` The complex abs function is differentiable with respect to its real and imaginary parts, but it is not complex differentiable. Thus one would prefer to use `
std::complex< AD<Base> >
` On the other hand, the C++ standard only specifies `std::complex<Type>` where `Type` is `float`, `double`, or `lone double`. The effect of instantiating the template complex for any other type is unspecified.
Exceptions
Why, in all the examples, do you pass back a boolean variable instead of throwing an exception ? `
` 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 ErrorHandler utility to signal exceptions. Specifications for redefining this action are provided.
Independent Variables
Is it possible to evaluate the same tape recording with different values for the independent variables ? `
` Yes (see forward_zero ).
Matrix Inverse
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 ? `
` The example routine LuSolve can be used to do this because the inverse is a special case of the solution of linear equations. The examples jac_lu_det.cpp and hes_lu_det.cpp use LuSolve to compute derivatives of the determinant with respect to the components of the matrix.
Mode: Forward or Reverse
When evaluating derivatives, one always has a choice between forward and reverse mode. How does one decide which mode to use ? `
` In general, the best mode depends on the number of domain and range components in the function that your are differentiating. Each call to Forward computes the derivative of all the range directions with respect to one domain direction. Each call to Reverse computes the derivative of one range direction with respect to all the domain directions. The times required for (speed of) calls `Forward` and `Reverse` are about equal. The Parameter function can be used to quickly determine that some range directions have derivative zero.
Namespace
Test Vector Preprocessor Symbol
Why do you use `CPPAD_TESTVECTOR` instead of a namespace for the CppAD testvector class ? `
` The preprocessor symbol CPPAD_TESTVECTOR determines which SimpleVector template class is used for extensive testing. The default definition for `CPPAD_TESTVECTOR` is the CppAD::vector template class, but it can be changed. Note that all the preprocessor symbols that are defined or used by CppAD begin with either `CPPAD` (some old deprecated symbols begin with `CppAD`).
Using
Why do I have trouble when the following command `

         using namespace CppAD

` is at the global level (not within a function or some other limited scope). `
` Some versions of `# include <cmath>` for gcc and Visual C++ define the standard math functions, (for example `double sqrt(double x)` ) at the global level. It is necessary to put your `using` commands within the scope of a function, or some other limited scope, in order to shadow these improper global definitions.
Speed
How do I get the best speed performance out of CppAD ?
NDEBUG
You should compile your code with optimization, without debugging, and with the preprocessor symbol `NDEBUG` defined. (The speed_cppad tests do this.) Note that defining `NDEBUG` will turn off all of the error checking and reporting that is done using ErrorHandler .
Optimize
It is also possible that preforming a tape optimization will improve the speed of evaluation more than the time required for the optimization.
Memory Allocation
You may also increase execution speed by calling `hold_memory` with value equal to true.
Tape Storage: Disk or Memory
Does CppAD store the tape on disk or in memory ? `
` CppAD uses memory to store a different tape for recording operations for each `AD<Base>` 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.

Input File: omh/faq.omh