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 .
Construct an ADFun Object and Stop Recording

Syntax
ADFun<Basef(xy);
ADFun<Basef
f.swap(g)
f = g

Purpose
The ADFun<Base> object f stores an AD of Base operation sequence . It can then be used to calculate derivatives of the corresponding AD function @[@ F : \B{R}^n \rightarrow \B{R}^m @]@ where @(@ B @)@ is the space corresponding to objects of type Base .

x
If the argument x is present, it has prototype
    const 
ADVector &x
It must be the vector argument in the previous call to Independent . Neither its size, or any of its values, are allowed to change between calling
    Independent(
x)
and
    ADFun<
Basef(xy)

y
If the argument y is present, it has prototype
    const 
ADVector &y
The sequence of operations that map x to y are stored in the ADFun object f .

ADVector
The type ADVector must be a SimpleVector class with elements of type AD<Base> . The routine CheckSimpleVector will generate an error message if this is not the case.

Default Constructor
The default constructor
    ADFun<
Baseg
creates an AD<Base> object with no corresponding operation sequence; i.e.,
    
g.size_var()
returns the value zero (see size_var ).

Sequence Constructor
The sequence constructor
    ADFun<
Basef(xy)
creates the AD<Base> object f , stops the recording of AD of Base operations corresponding to the call
    Independent(
x)
and stores the corresponding operation sequence in the object f . It then stores the zero order Taylor coefficients (corresponding to the value of x ) in f . This is equivalent to the following steps using the default constructor:
  1. Create f with the default constructor
        ADFun<
    Basef;
  2. Stop the tape and storing the operation sequence using
        
    f.Dependent(xy);
    (see Dependent ).
  3. Calculate the zero order Taylor coefficients for all the variables in the operation sequence using
        
    f.Forward(px_p)
    with p equal to zero and the elements of x_p equal to the corresponding elements of x (see Forward ).


Copy Constructor
It is an error to attempt to use the ADFun<Base> copy constructor; i.e., the following syntax is not allowed:
    ADFun<
Baseg(f)
where f is an ADFun<Base> object. Use its default constructor instead and its assignment operator.

swap
The swap operation %f%.swap(%g%)% exchanges the contents of the two ADFun<Base> functions; i.e., f ( g ) before the swap is identical to g ( f ) after the swap.

Assignment Operator
The ADFun<Base> assignment operation
    
g = f
makes a copy of the operation sequence currently stored in f in the object g . The object f is not affected by this operation and can be const. All of information (state) stored in f is copied to g and any information originally in g is lost.

Move Semantics
In the special case where f is a temporary object (and enough C++11 features are supported by the compiler) this assignment will use move semantics. This avoids the overhead of the copying all the information from f to g .

Taylor Coefficients
The Taylor coefficient information currently stored in f (computed by f.Forward ) is copied to g . Hence, directly after this operation
    
g.size_order() == f.size_order()

Sparsity Patterns
The forward Jacobian sparsity pattern currently stored in f (computed by f.ForSparseJac ) is copied to g . Hence, directly after this operation
    
g.size_forward_bool() == f.size_forward_bool()
    
g.size_forward_set()  == f.size_forward_set()

Parallel Mode
The call to Independent, and the corresponding call to
    ADFun<
Basefxy)
or
    
f.Dependent( xy)
or abort_recording , must be preformed by the same thread; i.e., thread_alloc::thread_num must be the same.

Example

Sequence Constructor
The file independent.cpp contains an example and test of the sequence constructor.

Default Constructor
The files fun_check.cpp and hes_lagrangian.cpp contain an examples and tests using the default constructor. They return true if they succeed and false otherwise.

Assignment Operator
The file fun_assign.cpp contains an example and test of the ADFun<Base> assignment operator.
Input File: include/cppad/core/fun_construct.hpp