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 .
Discrete AD Functions

Syntax
CPPAD_DISCRETE_FUNCTION(Basename)
y  = name(x)
ay = name(ax)

Purpose
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.

Base
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.

name
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> .

x
The argument x has prototype
    const 
Basex
It is the value at which the user provided version of name is to be evaluated.

y
The result y has prototype
    
Base y
It is the return value for the user provided version of name .

ax
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.

ay
The result ay has prototype
    AD<
Baseay
It is the return value for the CppAD provided version of name .

Create AD Version
The preprocessor macro invocation
    CPPAD_DISCRETE_FUNCTION(
Basename)
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.

Operation Sequence
This is an AD of Base atomic operation and hence is part of the current AD of Base operation sequence .

Derivatives
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.

Parallel Mode
The first call to
    
name(ax)
must not be in parallel execution mode.

Example
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.)

CppADCreateDiscrete Deprecated 2007-07-28
The preprocessor symbol CppADCreateDiscrete is defined to be the same as CPPAD_DISCRETE_FUNCTION but its use is deprecated.
Input File: include/cppad/core/discrete/user.omh