atomic_four_for_type

View page source

Atomic Function Forward Type Calculation

Syntax

ok = afun . for_type ( call_id , type_x , type_y )

Prototype

template <class Base>
bool atomic_four<Base>::for_type(
   size_t                       call_id     ,
   const vector<ad_type_enum>&  type_x      ,
   vector<ad_type_enum>&        type_y      )

Dependency Analysis

This calculation is sometimes referred to as a forward dependency analysis.

Usage

This syntax and prototype are used a call to an atomic function.

Implementation

This virtual function must be defined by the atomic_user derived class.

vector

is the CppAD_vector template class.

Base

See Base .

call_id

See call_id .

ad_type

The type CppAD::ad_type_enum is used to specify if an AD object is a constant parameter dynamic parameter or Variable . It has the following possible values:

ad_type_enum

Meaning

identical_zero_enum

identically zero

constant_enum

constant parameter

dynamic_enum

dynamic parameter

variable_enum

variable

In addition,

identical_zero_enum < constant_enum < dynamic_enum < variable_enum

A value that is identically zero is also a constant parameter. In CppAD, multiplication of a variable by a value that is identically zero is sometimes treated like Absolute Zero Multiplication. This avoids having to record the operation.

type_x

This vector has size equal to the number of arguments in the atomic function call; i.e., the size of ax which we denote by n . For j =0,…, n -1 , type_x [ j ] is the type of ax [ j ] .

type_y

This vector has size equal to the number of results in the atomic function call; i.e., the size of ay which we denote by m . The input values of the elements of type_y are not specified (must not matter). Upon return, for \(i = 0 , \ldots , m-1\), type_y [ i ] is set to one of the following values:

  1. It is identical_zero_enum if ay [ i ] is identically zero .

  2. It is constant_enum if ay [ i ] only depends on the arguments that are constants.

  3. It is dynamic_enum if ay [ i ] depends on a dynamic parameter and does not depend on any variables.

  4. It is variable_enum if ay [ i ] depends on a variable.

ok

If this calculation succeeded, ok is true. Otherwise, it is false.

Example

The following is an example for_type definition taken from atomic_four_norm_sq.cpp :

      bool for_type(
         size_t                                     call_id     ,
         const CppAD::vector<CppAD::ad_type_enum>&  type_x      ,
         CppAD::vector<CppAD::ad_type_enum>&        type_y      ) override
      {  assert( call_id == 0 );       // default value
         assert(type_y.size() == 1 );  // m
         //
         // type_y
         size_t n     = type_x.size();
         type_y[0] = CppAD::constant_enum;
         for(size_t j = 0; j < n; ++j)
            type_y[0] = std::max(type_y[0], type_x[j]);
         return true;
      }