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 .
Defining Atomic Functions: Fourth Generation

Syntax

Define Class
class atomic_user : public CppAD::atomic_four<Base> {
    
...
};


Constructor
atomic_user afun(ctor_arg_list)

Call
afun(axay)
afun(call_idaxay)

Callbacks
ok = afun.for_type( call_id,
    
type_xtype_y
)
ok = afun.forward( call_id,
    
select_yorder_loworder_uptaylor_xtaylor_y
)
ok = afun.reverse( call_id,
    
select_xorder_uptaylor_xtaylor_ypartial_xpartial_y
)
ok = afun.jac_sparsity( call_id,
    
dependencyident_zero_xselect_x select_ypattern_out
)
ok = afun.hes_sparsity( call_id,
    
ident_zero_xselect_x select_ypattern_out
)
ok = afun.rev_depend( call_id,
    
ident_zero_xdepend_xdepend_y
)


See Also
chkpoint_two , atomic_three

Purpose

Speed
In some cases, it is possible to compute derivatives of a function @[@ y = g(x) \; {\rm where} \; g : \B{R}^n \rightarrow \B{R}^m @]@ more efficiently than by coding it using AD<Base> atomic operations and letting CppAD do the rest. The class atomic_four<Base> is used to create a new atomic operation corresponding to a function @(@ g(x) @)@ where the user specifies how to compute the derivatives and sparsity patterns for @(@ g(x) @)@.

Reduce Memory
If the function @(@ g(x) @)@ is used many times during the recording of an ADFun object, an atomic version of @(@ g(x) @)@ removes the need for repeated copies of the corresponding AD<Base> operations and variables in the recording.

Virtual Functions
The callback functions are implemented by defining the virtual functions in the atomic_user class. These functions compute derivatives, sparsity patterns, and dependency relations. Each virtual function has a default implementation that returns ok == false . The for_type and forward function (for the case order_up == 0 ) are used by an atomic function call . Hence, they are required for one to use an atomic function. Other functions and orders are only required if they are used for your calculations. For example, forward for the case order_up == 2 can just return ok == false unless you require forward mode calculation of second derivatives.

Contents
atomic_four_ctorAtomic Function Constructor
atomic_four_callCalling an Atomic Function
atomic_four_for_typeAtomic Function Forward Type Calculation
atomic_four_forwardAtomic Function Forward Mode
atomic_four_reverseAtomic Function Reverse Mode
atomic_four_jac_sparsityAtomic Function Jacobian Sparsity Patterns
atomic_four_hes_sparsityAtomic Function Hessian Sparsity Patterns
atomic_four_rev_dependAtomic Function Reverse Dependency

Input File: include/cppad/core/atomic/four/atomic.hpp