Prev Next capacity_taylor

Controlling taylor_ Coefficients Memory Allocation

Syntax
f.capacity_taylor(c)

Purpose
The taylor_ coefficients calculated by Forward mode calculations are retained in an ADFun object for subsequent use during Reverse mode or higher order Forward mode calculations. This operation allow you to control that amount of memory that is retained by an AD function object (for subsequent calculations).

f
The object f has prototype
     ADFun<
Basef

c
The argument c has prototype
     size_t 
c
It specifies the number of taylor_ coefficients that are allocated for each variable in the AD operation sequence corresponding to f.

Discussion
A call to Forward with the syntax
        
y_p = f.Forward(px_p)
uses the lower order taylor_ coefficients and computes the p-th order taylor_ coefficients for all the variables in the operation sequence corresponding to f. (You can determine the number of variables in the operation sequence using the size_var function.)

Pre-Allocating Memory
If you plan to make calls to Forward with the maximum value of p equal to q, it should be faster to pre-allocate memory for these calls using
     
f.capacity_taylor(c)
with c equal to  q + 1 . If you do no do this, Forward will automatically allocate memory and will copy the results to a larger buffer, when necessary.

Note that each call to Dependent frees the old memory connected to the function object and sets the corresponding taylor capacity to zero.

Freeing Memory
If you no longer need the taylor_ coefficients of order q and higher (that are stored in f), you can reduce the memory allocated to f using
     
f.capacity_taylor(c)
with c equal to q.

Original State
If f is constructed with the syntax
     ADFun<
Basef(xy)
, there is an implicit call to Forward with p equal to zero and x_p equal to the value of the independent variables when the AD operation sequence was recorded.

Example
The file Forward.cpp contains an example and test of these operations. It returns true if it succeeds and false otherwise.
Input File: cppad/local/cap_taylor.hpp