CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
evaluator_adolc.hpp
1#ifndef CPPAD_CG_EVALUATOR_ADOLC_INCLUDED
2#define CPPAD_CG_EVALUATOR_ADOLC_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2014 Ciengis
6 *
7 * CppADCodeGen is distributed under multiple licenses:
8 *
9 * - Eclipse Public License Version 1.0 (EPL1), and
10 * - GNU General Public License Version 3 (GPL3).
11 *
12 * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13 * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14 * ----------------------------------------------------------------------------
15 * Author: Joao Leal
16 */
17
18#include <adolc/adolc.h>
19#include <adolc/drivers/drivers.h>
20
24inline adouble abs(const adouble& val) {
25 return fabs(val);
26}
27
28inline adouble sign(const adouble& val) {
29 throw CppAD::cg::CGException("Sign operation not implemented in ADOL-C");
30 //adouble temp;
31 //condassign(temp, val, adouble(1.0), adouble(-1.0)); // warning it should return zero if val == 0 but there is no way to do this in Adol-C
32 //return temp;
33}
34
35inline adouble condExpLt(const adouble& left, const adouble& right,
36 const adouble& exp_if_true, const adouble& exp_if_false) {
37 adouble temp;
38 condassign(temp, right - left, exp_if_true, exp_if_false); // temp = (right - left>0)? exp_if_true: exp_if_false
39 return temp;
40}
41
42inline adouble condExpLe(const adouble& left, const adouble& right, const adouble& exp_if_true, const adouble& exp_if_false) {
43 throw CppAD::cg::CGException("Conditional operation (<=) not implemented in ADOL-C");
44}
45
46inline adouble condExpEq(const adouble& left, const adouble& right,
47 const adouble& exp_if_true, const adouble& exp_if_false) {
48 throw CppAD::cg::CGException("Conditional operation (==) not implemented in ADOL-C");
49}
50
51inline adouble condExpGe(const adouble& left, const adouble& right,
52 const adouble& exp_if_true, const adouble& exp_if_false) {
53 throw CppAD::cg::CGException("Conditional operation (>=) not implemented in ADOL-C");
54}
55
56inline adouble condExpGt(const adouble& left, const adouble& right,
57 const adouble& exp_if_true, const adouble& exp_if_false) {
58 adouble temp;
59 condassign(temp, left - right, exp_if_true, exp_if_false);
60 return temp;
61}
62
63inline adouble condExpNe(const adouble& left, const adouble& right,
64 const adouble& exp_if_true, const adouble& exp_if_false) {
65 throw CppAD::cg::CGException("Conditional operation (!=) not implemented in ADOL-C");
66}
67
68inline adouble CondExpOp(enum CppAD::CompareOp cop,
69 const adouble& left,
70 const adouble& right,
71 const adouble& trueCase,
72 const adouble& falseCase) {
73 switch (cop) {
74 case CppAD::CompareLt: // less than
75 return condExpLt(left, right, trueCase, falseCase);
76 case CppAD::CompareLe: // less than or equal
77 return condExpLe(left, right, trueCase, falseCase);
78 case CppAD::CompareEq: // equal
79 return condExpEq(left, right, trueCase, falseCase);
80 case CppAD::CompareGe: // greater than or equal
81 return condExpGe(left, right, trueCase, falseCase);
82 case CppAD::CompareGt: // greater than
83 return condExpGt(left, right, trueCase, falseCase);
84 case CppAD::CompareNe:
85 return condExpNe(left, right, trueCase, falseCase);
86 default:
87 throw CppAD::cg::CGException("Unknown comparison type");
88 }
89}
90
91namespace CppAD {
92namespace cg {
93
97template<class ScalarIn>
98class Evaluator<ScalarIn, double, adouble> : public EvaluatorOperations<ScalarIn, double, adouble, Evaluator<ScalarIn, double, adouble> > {
99public:
100 using ActiveOut = adouble;
102public:
103
104 inline Evaluator(CodeHandler<ScalarIn>& handler) :
105 Super(handler) {
106 }
107
108 inline virtual ~Evaluator() = default;
109
110};
111
112} // END cg namespace
113} // END CppAD namespace
114
115#endif
cg::CG< Base > sign(const cg::CG< Base > &x)