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}} }@)@

`CPPAD_DISCRETE_FUNCTION(`*Base*, *name*)

*y* = *name*(*x*)

*ay* = *name*(*ax*)

Record the evaluation of a discrete function as part of an

`AD<`*Base*>

operation sequence
.
The value of a discrete function can depend on the
independent variables
,
but its derivative is identically zero.
For example, suppose that the integer part of
a variable
*x*

is the
index into an array of values.
This is the base type corresponding to the operations sequence; i.e., use of the

*name*

with arguments of type
`AD<`*Base*>

can be recorded in an operation sequence.
This is the name of the function (as it is used in the source code). The user must provide a version of

*name*

where the argument has type
*Base*

.
CppAD uses this to create a version of
*name*

where the argument has type
`AD<`*Base*>

.
The argument

*x*

has prototype

const *Base*& *x*

It is the value at which the user provided version of
*name*

is to be evaluated.
The result

*y*

has prototype

*Base* *y*

It is the return value for the user provided version of
*name*

.
The argument

*ax*

has prototype

const AD<*Base*>& *ax*

It is the value at which the CppAD provided version of
*name*

is to be evaluated.
The result

*ay*

has prototype

AD<*Base*> *ay*

It is the return value for the CppAD provided version of
*name*

.
The preprocessor macro invocation

CPPAD_DISCRETE_FUNCTION(*Base*, *name*)

defines the
`AD<`*Base*>

version of
*name*

.
This can be with in a namespace (not the `CppAD`

namespace)
but must be outside of any routine.
This is an AD of

*Base*

atomic operation
and hence is part of the current
AD of
*Base*

operation sequence
.
During a zero order Forward operation, an ADFun object will compute the value of

*name*

using the user provided
*Base*

version of this routine.
All the derivatives of
*name*

will be evaluated as zero.
The first call to

*ay* = *name*(*ax*)

must not be in parallel
execution mode.
The file tape_index.cpp contains an example and test that uses a discrete function to vary an array index during Forward mode calculations. The file interp_onetape.cpp contains an example and test that uses discrete functions to avoid retaping a calculation that requires interpolation. (The file interp_retape.cpp shows how interpolation can be done with retaping.)

The preprocessor symbol

`CppADCreateDiscrete`

is defined to be the same as `CPPAD_DISCRETE_FUNCTION`

but its use is deprecated.
Input File: cppad/core/discrete.hpp