Independent

View page source

Declare Independent Variables and Start Recording

Syntax

Independent ( x )
Independent ( x , dynamic )
Independent ( x , abort_op_index )
Independent ( x , abort_op_index , record_compare )
Independent ( x , abort_op_index , record_compare , dynamic )

Start Recording

The syntax above starts recording AD of Base operations with x as the independent variable vector. Once the operation sequence is completed, it must be transferred to a function object or aborted; see below.

Stop Recording

The recording is stopped, and the operation sequence is transferred to the AD function object f , using either the function constructor

ADFun < Base > f ( x , y )

or the dependent variable specifier

f . Dependent ( x , y )

The only other way to stop a recording is using abort_recording . Between when the recording is started and when it stopped, we refer to the elements of x , and the values that depend on the elements of x , as AD < Base > variables.

x

The vector x has prototype

ADVector & x

(see ADVector below). The size of the vector x , must be greater than zero, and is the number of independent variables for this AD operation sequence.

abort_op_index

If this argument has prototype

size_t abort_op_index

If it is present, it specifies the operator index at which the execution will aborted by calling the CppAD error handler . When this error handler leads to an assert, the user can inspect the call stack to see the source code corresponding to this operator index; see Purpose for op_index and NDEBUG . No abort will occur if abort_op_index is zero. If this argument is not present, the default value zero is used for abort_index .

record_compare

This argument has prototype

bool record_compare

If it is present, it specifies if AD Compare operations are recorded. It takes extra time and memory to record these operations. On the other hand, they can be useful for detecting when and why a functions recording would change; see abort_op_index above and compare_change . If this argument is not present, the default value true is used for record_compare . If this argument is false, abort_op_index must be zero.

dynamic

If this argument is present, it has prototype

const ADVector & dynamic

(see Vector below). It specifies the independent Dynamic parameters. The value of these parameters, in the ADFun object f , that can be changed using new_dynamic .

Efficiency

Any operations that use dynamic parameters will be recorded. We use other dynamic parameters to denote parameters that depend on the independent dynamic parameters dynamic , and do not depend on x . It is more efficient to compute other dynamic parameters before calling Independent and include them in the independent dynamic parameter vector dynamic .

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.

Parallel Mode

Each thread can have one, and only one, active recording. A call to Independent starts the recording for the current thread. The recording must be stopped by a corresponding call to

ADFun < Base > f ( x , y )

or

f . Dependent ( x , y )

or abort_recording preformed by the same thread; i.e., thread_alloc::thread_num must be the same.

Example

The file independent.cpp contains an example and test of this operation.