Prev Next base_cond_exp

@(@\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 .
Base Type Requirements for Conditional Expressions

Purpose
These definitions are required by the user's code to support the AD<Base> type for CondExp operations:

CompareOp
The following enum type is used in the specifications below:
 
namespace CppAD {
    // The conditional expression operator enum type
    enum CompareOp
    {   CompareLt, // less than
        CompareLe, // less than or equal
        CompareEq, // equal
        CompareGe, // greater than or equal
        CompareGt, // greater than
        CompareNe  // not equal
    };
}

CondExpTemplate
The type Base must support the syntax
    
result = CppAD::CondExpOp(
        
copleftrightexp_if_trueexp_if_false
    )
which computes implements the corresponding CondExp function when the result has prototype
    
Base result
The argument cop has prototype
    enum CppAD::CompareOp 
cop
The other arguments have the prototype
    const 
Base&  left
    const 
Base&  right
    const 
Base&  exp_if_true
    const 
Base&  exp_if_false

Ordered Type
If Base is a relatively simple type that supports <, <=, ==, >=, and > operators its CondExpOp function can be defined by
namespace CppAD {
    inline 
Base CondExpOp(
    enum CppAD::CompareOp  
cop            ,
    const 
Base           &left          ,
    const 
Base           &right         ,
    const 
Base           &exp_if_true   ,
    const 
Base           &exp_if_false  )
    {   return CondExpTemplate(
            cop, left, right, trueCase, falseCase);
    }
}
For example, see double CondExpOp . For an example of and implementation of CondExpOp with a more involved Base type see adolc CondExpOp .

Not Ordered
If the type Base does not support ordering, the CondExpOp function does not make sense. In this case one might (but need not) define CondExpOp as follows:
namespace CppAD {
    inline 
Base CondExpOp(
    enum CompareOp 
cop           ,
    const 
Base   &left         ,
    const 
Base   &right        ,
    const 
Base   &exp_if_true  ,
    const 
Base   &exp_if_false )
    {   // attempt to use CondExp with a 
Base argument
        assert(0);
        return 
Base(0);
    }
}
For example, see complex CondExpOp .

CondExpRel
The macro invocation
    CPPAD_COND_EXP_REL(
Base)
uses CondExpOp above to define the following functions
    CondExpLt(
leftrightexp_if_trueexp_if_false)
    CondExpLe(
leftrightexp_if_trueexp_if_false)
    CondExpEq(
leftrightexp_if_trueexp_if_false)
    CondExpGe(
leftrightexp_if_trueexp_if_false)
    CondExpGt(
leftrightexp_if_trueexp_if_false)
where the arguments have type Base . This should be done inside of the CppAD namespace. For example, see base_alloc .
Input File: include/cppad/core/base_cond_exp.hpp