atomic_four_define

View page source

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 ( ax , ay )
afun ( call_id , ax , ay )

Callbacks

ok = afun . for_type ( call_id ,
      type_x , type_y
)
ok = afun . forward ( call_id ,
      select_y , order_low , order_up , taylor_x , taylor_y
)
ok = afun . reverse ( call_id ,
      select_x , order_up , taylor_x , taylor_y , partial_x , partial_y
)
ok = afun . jac_sparsity ( call_id ,
      dependency , ident_zero_x , select_x select_y , pattern_out
)
ok = afun . hes_sparsity ( call_id ,
      ident_zero_x , select_x , select_y , pattern_out
)
ok = afun . rev_depend ( call_id ,
      ident_zero_x , depend_x , depend_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

Name

Title

atomic_four_ctor

Atomic Function Constructor

atomic_four_call

Calling an Atomic Function

atomic_four_for_type

Atomic Function Forward Type Calculation

atomic_four_forward

Atomic Function Forward Mode

atomic_four_reverse

Atomic Function Reverse Mode

atomic_four_jac_sparsity

Atomic Function Jacobian Sparsity Patterns

atomic_four_hes_sparsity

Atomic Function Hessian Sparsity Patterns

atomic_four_rev_depend

Atomic Function Reverse Dependency