\(\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}} }\)
atomic_four_define¶
View page sourceDefining Atomic Functions: Fourth Generation¶
Syntax¶
Define Class¶
class
atomic_user : public CppAD::atomic_four<
Base > {Constructor¶
atomic_user afun ( ctor_arg_list )
Call¶
Callbacks¶
for_type
( call_id ,forward
( call_id ,reverse
( call_id ,jac_sparsity
( call_id ,hes_sparsity
( call_id ,rev_depend
( call_id ,See Also¶
Purpose¶
Speed¶
In some cases, it is possible to compute derivatives of a function
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_four_call |
|
atomic_four_for_type |
|
atomic_four_forward |
|
atomic_four_reverse |
|
atomic_four_jac_sparsity |
|
atomic_four_hes_sparsity |
|
atomic_four_rev_depend |