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
|
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
# SPDX-FileContributor: 2003-24 Bradley M. Bell
# ----------------------------------------------------------------------------
{xrst_begin Faq app}
{xrst_spell
github
}
Frequently Asked Questions and Answers
######################################
Assignment and Independent
**************************
Why does the code sequence
| |tab| ``Independent`` ( *u* );
| |tab| *v* = *u* [0];
behave differently from the code sequence
| |tab| *v* = *u* [0];
| |tab| ``Independent`` ( *u* );
Before the call to :ref:`Independent-name` ,
*u* [0] is a :ref:`glossary@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 ?
#. The first step is to check currently open
`issues <https://github.com/coin-or/CppAD/issues>`_ on github.
If it is an open issue, and you want to hurry it along, you can add
a comment to the effect that it is holding you up.
#. The next step is to search the
:ref:`whats_new-name` sections for mention of a related bug fix
between the date of the version you are using and the current date.
It the bug has been fixed, obtain a more recent release that has the fix
and see if that works for you.
#. The next step is to
create a simple 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.
#. The next step is open a new issue on github and provide your simple
example so that the problem can be reproduced.
CompareChange
*************
If you attempt to use the
:ref:`CompareChange-name`
function when ``NDEBUG`` is true,
you will get an error message stating that
``CompareChange`` is not a member of the
:ref:`ADFun-name` template class.
Complex Types
*************
Which of the following complex types is better:
| |tab| ``AD< std::complex<`` *Base* > >
| |tab| ``std::complex< AD<`` *Base* > >
The :ref:`complex abs function<abs@Complex Types>` 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 :ref:`ErrorHandler-name` 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 :ref:`forward_zero-name` ).
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 ?
LuSolve
=======
The example routine :ref:`LuSolve-name` can be used to do this
because the inverse is a special case of the solution of linear equations.
The examples
:ref:`jac_lu_det.cpp-name` and :ref:`hes_lu_det.cpp-name`
use LuSolve to compute derivatives of the
determinant with respect to the components of the matrix.
Atomic Operation
================
One can also do this by making the inversion of the matrix an atomic operation;
e.g., see :ref:`atomic_two_eigen_mat_inv.cpp-name` .
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 :ref:`Forward-name` computes the derivative of all
the range directions with respect to one domain direction.
Each call to :ref:`Reverse-name` 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 :ref:`fun_property@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 :ref:`testvector-name` class ?
The preprocessor symbol ``CPPAD_TESTVECTOR`` ( see :ref:`testvector-name` )
determines which
:ref:`SimpleVector-name` template class is used for extensive testing.
The default definition for ``CPPAD_TESTVECTOR`` is the
:ref:`CppAD::vector<CppAD_vector-name>` 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`` ).
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 :ref:`speed_cppad-name` tests do this.)
Note that defining ``NDEBUG``
will turn off all of the error checking and reporting that
is done using :ref:`ErrorHandler-name` .
Optimize
========
It is also possible that preforming a tape
:ref:`optimization<optimize-name>` 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
:ref:`ta_hold_memory@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.
{xrst_end Faq}
|