Prev Next Index-> contents reference index search external Up-> CppAD ADFun FunConstruct CppAD-> Install Introduction AD ADFun preprocessor multi_thread library ipopt_solve Example speed Appendix ADFun-> Independent FunConstruct Dependent abort_recording seq_property FunEval Drivers FunCheck optimize check_for_nan FunConstruct-> fun_assign.cpp Headings-> Syntax Purpose x y VectorAD Default Constructor Sequence Constructor Copy Constructor Assignment Operator ---..Taylor Coefficients ---..Sparsity Patterns Parallel Mode Example ---..Sequence Constructor ---..Default Constructor ---..Assignment Operator

Construct an ADFun Object and Stop Recording

Syntax
ADFun<Base> f, g  ADFun<Base> f(x, y)  g = f 
Purpose
The AD<Base> object f can store an AD of Base operation sequence . It can then be used to calculate derivatives of the corresponding AD function   $F : B^n \rightarrow B^m$  where   B is the space corresponding to objects of type Base .

x
If the argument x is present, it has prototype       const VectorAD &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<Base> f(x, y)  .

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

The type VectorAD 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<Base> f  creates an AD<Base> object with no corresponding operation sequence; i.e.,       f.size_var()  returns the value zero (see size_var ).

Sequence Constructor
The default constructor The sequence constructor       ADFun<Base> f(x, y)  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 first 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<Base> f; 
2. Stop the tape and storing the operation sequence using       f.Dependent(x, y);  (see Dependent ).
3. Calculating the first order taylor_ coefficients for all the variables in the operation sequence using       f.Forward(p, x_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<Base> g(f)  where f is an ADFun<Base> object. Use its default constructor instead and its assignment operator.

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. Any operation sequence or other information in g is lost.

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_taylor() == f.size_taylor() 
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<Base> f( x, y)  or       f.Dependent( x, y)  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. It returns true if it succeeds and false otherwise.

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. It returns true if it succeeds and false otherwise.