![]() |
Prev | Next |
example
directory.
It can be copied into the current working directory and
included with the command:
# include "base_adolc.hpp"
adouble
type for a CppAD Base type.
It returns true if it succeeds and false otherwise.
The file ode_taylor_adolc.cpp
contains a more realistic
(and complex) example.
<cppad/cppad.hpp>
so it is necessary to define the error handler
in addition to including
declare.hpp
# include <cppad/declare.hpp>
# include <cppad/error_handler.hpp>
abs
function is called fabs
in the Adolc package.
namespace CppAD {
inline adouble abs(const adouble &x) \
{ return ::fabs(x); }
}
Standard Math Functions Defined by Adolc Package
acos
,
asin
,
atan
,
cos
,
cosh
,
erf
,
exp
,
log
,
pow
,
sin
,
sinh
,
sqrt
,
tan
.
# define CPPAD_USER_MACRO(function) \
inline adouble function(const adouble &x) \
{ return ::function(x); }
namespace CppAD {
CPPAD_USER_MACRO(acos)
CPPAD_USER_MACRO(asin)
CPPAD_USER_MACRO(atan)
CPPAD_USER_MACRO(cos)
CPPAD_USER_MACRO(cosh)
CPPAD_USER_MACRO(erf)
CPPAD_USER_MACRO(exp)
CPPAD_USER_MACRO(log)
inline adouble pow(const adouble &x, const adouble y)
{ return ::pow(x, y); }
CPPAD_USER_MACRO(sin)
CPPAD_USER_MACRO(sinh)
CPPAD_USER_MACRO(sqrt)
CPPAD_USER_MACRO(tan)
}
# undef CPPAD_USER_MACRO
CondExpOp
adouble
supports a conditional assignment function
with the syntax
condassign(
a,
b,
c,
d)
which evaluates to
a = (
b > 0) ?
c :
d;
This enables one to include conditionals in the recording of
adouble
operations and later evaluation for different
values of the independent variables
(in the same spirit as the CppAD CondExp
function).
namespace CppAD {
inline adouble CondExpOp(
enum CppAD::CompareOp cop ,
const adouble &left ,
const adouble &right ,
const adouble &trueCase ,
const adouble &falseCase )
{ adouble result;
switch( cop )
{
case CompareLt: // left < right
condassign(result, right - left, trueCase, falseCase);
break;
case CompareLe: // left <= right
condassign(result, left - right, falseCase, trueCase);
break;
case CompareEq: // left == right
condassign(result, left - right, falseCase, trueCase);
condassign(result, right - left, falseCase, result);
break;
case CompareGe: // left >= right
condassign(result, right - left, falseCase, trueCase);
break;
case CompareGt: // left > right
condassign(result, left - right, trueCase, falseCase);
break;
default:
CppAD::ErrorHandler::Call(
true , __LINE__ , __FILE__ ,
"CppAD::CondExp",
"Error: for unknown reason."
);
result = trueCase;
}
return result;
}
}
adouble
variables correspond to the same operations sequence.
Make EqualOpSeq
an error if it gets used:
namespace CppAD {
inline bool EqualOpSeq(const adouble &x, const adouble &y)
{ CppAD::ErrorHandler::Call(
true , __LINE__ , __FILE__ ,
"CppAD::EqualOpSeq(x, y)",
"Error: adouble does not support EqualOpSeq."
);
return false;
}
}
adouble
depends on the independent variables.
To be safe (but slow) return false
in all the cases below.
namespace CppAD {
inline bool IdenticalPar(const adouble &x)
{ return false; }
inline bool IdenticalZero(const adouble &x)
{ return false; }
inline bool IdenticalOne(const adouble &x)
{ return false; }
inline bool IdenticalEqualPar(const adouble &x, const adouble &y)
{ return false; }
}
inline bool GreaterThanZero(const adouble &x)
{ return (x > 0); }
inline bool GreaterThanOrZero(const adouble &x)
{ return (x >= 0); }
inline bool LessThanZero(const adouble &x)
{ return (x < 0); }
inline bool LessThanOrZero(const adouble &x)
{ return (x <= 0); }
inline int Integer(const adouble &x)
{ return static_cast<int>( x.value() ); }