Atomic Reverse Mode
Keywords: atomic reverse mode syntax purpose implementation q tx ty f g h py px ok examples define use

| Prev | Next |  |  |  |  |  | atomic_reverse |

Atomic Reverse Mode
Syntax
`ok = afun.reverse(q, tx, ty, px, py)`
Purpose
This function is used by reverse to compute derivatives.
Implementation
If you are using reverse mode, this virtual function must be defined by the atomic_user class. It can just return `ok == false` (and not compute anything) for values of `q` that are greater than those used by your reverse mode calculations.
q
The argument `q` has prototype `
size_t q
` It specifies the highest order Taylor coefficient that computing the derivative of.
tx
The argument `tx` has prototype `
const CppAD::vector<Base>& tx
` and `tx.size() == (q+1)*n` . For j = 0 , … , n -1 and k = 0 , … , q , we use the Taylor coefficient notation x j k = tx [ j * ( q + 1 ) + k ] X j ( t ) = x j 0 + x j 1 t 1 + ⋯ + x j q t q Note that superscripts represent an index for x j k and an exponent for t k . Also note that the Taylor coefficients for X ( t ) correspond to the derivatives of X ( t ) at t = 0 in the following way: x j k = 1 k ! X j ( k ) ( 0 )
ty
The argument `ty` has prototype `
const CppAD::vector<Base>& ty
` and `tx.size() == (q+1)*m` . For i = 0 , … , m -1 and k = 0 , … , q , we use the Taylor coefficient notation Y i ( t ) = f i [ X ( t ) ] Y i ( t ) = y i 0 + y i 1 t 1 + ⋯ + y i q t q + o ( t q ) y i k = ty [ i * ( q + 1 ) + k ] where o ( t q ) / t q → 0 as t → 0 . Note that superscripts represent an index for y j k and an exponent for t k . Also note that the Taylor coefficients for Y ( t ) correspond to the derivatives of Y ( t ) at t = 0 in the following way: y j k = 1 k ! Y j ( k ) ( 0 )
F, G, H
We use the notation { x j k } ∈ B n × ( q + 1 ) for { x j k : j = 0 , … , n -1 , k = 0 , … , q } We use the notation { y i k } ∈ B m × ( q + 1 ) for { y i k : i = 0 , … , m -1 , k = 0 , … , q } We define the function F : B n × ( q + 1 ) → B m × ( q + 1 ) by y i k = F i k [ { x j k } ] We use G : B m × ( q + 1 ) → B to denote an arbitrary scalar valued function of { y i k } . We use H : B n × ( q + 1 ) → B defined by H ( { x j k } ) = G [ F ( { x j k } ) ]
py
The argument `py` has prototype `
const CppAD::vector<Base>& py
` and `py.size() == m * (q+1)` . For i = 0 , … , m -1 , k = 0 , … , q , py [ i * ( q + 1 ) + k ] = ∂ G / ∂ y i k
px
The `px` has prototype `
CppAD::vector<Base>& px
` and `px.size() == n * (q+1)` . The input values of the elements of `px` are not specified (must not matter). Upon return, for j = 0 , … , n -1 and ℓ = 0 , … , q , px [ j * ( q + 1 ) + ℓ ] = ∂ H / ∂ x j ℓ = ( ∂ G / ∂ { y i k } ) ( ∂ { y i k } / ∂ x j ℓ ) = ∑ i = 0 m -1 ∑ k = 0 q ( ∂ G / ∂ y i k ) ( ∂ y i k / ∂ x j ℓ ) = ∑ i = 0 m -1 ∑ k = ℓ q py [ i * ( q + 1 ) + k ] ( ∂ F i k / ∂ x j ℓ ) Note that we have used the fact that for k < ℓ , ∂ F i k / ∂ x j ℓ = 0 .
ok
The return value `ok` has prototype `
bool ok
` If it is `true`, the corresponding evaluation succeeded, otherwise it failed.
Examples
Define reverse
The following files contain example atomic `reverse` functions: norm_sq.cpp , reciprocal.cpp , tangent.cpp , matrix_mul.hpp .
Use reverse
The following are links to user atomic function constructor uses: norm_sq.cpp , reciprocal.cpp , tangent.cpp , mat_mul.cpp .

Input File: cppad/local/atomic_base.hpp