Prev Next

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@ This is cppad-20221105 documentation. Here is a link to its current documentation .
Comparison Changes Between Taping and Zero Order Forward

Syntax
f.compare_change_count(count)
number = f.compare_change_number()
op_index = f.compare_change_op_index()

See Also FunCheck

Purpose
We use @(@ F : \B{R}^n \rightarrow \B{R}^m @)@ to denote the AD function corresponding to f ; i.e, given @(@ x \in \B{R}^n @)@, @(@ F(x) @)@ is defined by
    
F(x) = f.Forward(0, x)
see forward_zero . If @(@ x @)@ is such that all the algorithm comparison operations have the same result as when the algorithm was taped, The function @(@ F(x) @)@ and the algorithm will have the same values. (This is a sufficient, but not necessary condition).

f
In the compare_change_number and compare_change_op_index syntax, the object f has prototype
    const ADFun<
Basef
In the compare_change_count syntax, the object f has prototype
    ADFun<
Basef

count
The argument count has prototype
    size_t 
count
It specifies which comparison change should correspond to the information stored in f during subsequent calls to forward_zero ; i.e.,
    
f.Forward(0, x)
For example, if count == 1 , the operator index corresponding to the first comparison change will be stored. This is the default value used if count is not specified.

Speed
The special case where count == 0 , should be faster because the comparisons are not checked during
    
f.Forward(0, x)

number
The return value number has prototype
    size_t 
number
If count is non-zero, number is the number of AD<Base> comparison operations, corresponding to the previous call to
    
f.Forward(0, x)
that have a different result for this value of x than the value used when f was created by taping an algorithm. If count is zero, or if no calls to f.Forward(0, x) follow the previous setting of count , number is zero.

Discussion
If count and number are non-zero, you may want to re-tape the algorithm with the independent variables equal to the values in x , so the AD operation sequence properly represents the algorithm for this value of independent variables. On the other hand, re-taping the AD operation sequence usually takes significantly more time than evaluation using forward_zero . If the functions values have not changed (see FunCheck ) it may not be worth re-taping a new AD operation sequence.

op_index
The return value op_index has prototype
    size_t 
op_index
If count is non-zero, op_index is the operator index corresponding the count -th comparison change during the previous call to
    
f.Forward(0, x)
If count is greater than the corresponding number , there is no such comparison change and op_index will also be zero. If count is zero, if the function f has been optimized , or if no calls to f.Forward(0, x) follow the previous setting of count , op_index is zero.

Purpose
The operator index can be used to generate an error during the taping process so that the corresponding algorithm can be inspected. In some cases, it is possible to re-design this part of the algorithm to avoid the particular comparison operation. For example, using an conditional expression may be appropriate in some cases. See abort_op_index in the syntax
    Independent(
xabort_op_index)

Example
compare_change.cpp contains an example and test of this operation.
Input File: include/cppad/core/forward/compare_change.omh