|
Prev
| Next
|
|
|
|
|
|
atomic_four_vector_for_type.hpp |
|
@(@\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
.
Atomic Vector Forward Type Calculation: Example Implementation
Purpose
The for_type
routine overrides the virtual functions
used by the atomic_four base; see
for_type
.
Source
# include <cppad/example/atomic_four/vector/vector.hpp>
namespace CppAD { // BEGIN_CPPAD_NAMESPACE
//
// for_type override
template <class Base>
bool atomic_vector<Base>::for_type(
size_t call_id ,
const CppAD::vector<CppAD::ad_type_enum>& type_x ,
CppAD::vector<CppAD::ad_type_enum>& type_y )
{
// n, m, op
size_t n = type_x.size();
size_t m = type_y.size();
op_enum_t op = op_enum_t( call_id );
//
// type_y
if( n == m )
{ // unary operator
for(size_t i = 0; i < m; ++i)
type_y[i] = type_x[i];
}
else
{ // binary operator
for(size_t i = 0; i < m; ++i)
type_y[i] = std::max( type_x[i] , type_x[m + i] );
}
switch(op)
{
// addition, subtraction
// not sure result is identically 0 unless both are identically 0
case add_enum:
case sub_enum:
for(size_t i = 0; i < m; ++i)
type_y[i] = std::max( type_x[i] , type_x[m + i] );
break;
// multiplication
// treat multiplication by zero like absolute zero
case mul_enum:
for(size_t i = 0; i < m; ++i)
{ if( type_x[i] == identical_zero_enum )
type_y[i] = identical_zero_enum;
else if( type_x[m + i] == identical_zero_enum )
type_y[i] = identical_zero_enum;
else
type_y[i] = std::max( type_x[i] , type_x[m + i] );
}
break;
// division
// treat divition of zero like absolute zero
case div_enum:
for(size_t i = 0; i < m; ++i)
{ if( type_x[i] == identical_zero_enum )
type_y[i] = identical_zero_enum;
else
type_y[i] = std::max( type_x[i] , type_x[m + i] );
}
break;
// unary minus
case neg_enum:
for(size_t i = 0; i < m; ++i)
type_y[i] = type_x[i];
break;
// error
case number_op_enum:
assert(false);
break;
}
return true;
}
} // END_CPPAD_NAMESPACE
Input File: include/cppad/example/atomic_four/vector/for_type.hpp