CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
cppadcg_eigen.hpp
1#ifndef CPPAD_CG_CPPADCG_EIGEN_INCLUDED
2#define CPPAD_CG_CPPADCG_EIGEN_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2017 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 <cppad/cg.hpp>
19# include <Eigen/Dense>
20
24namespace Eigen {
25
31template<typename Base>
32struct NumTraits<CppAD::cg::CG<Base> > {
33 // the real part of an CG<Base> value
35 // type for CG<Base> operations producing non-integer values
37 // type for nested value inside an CG<Base> expression tree
39 // type for numeric literals such as "2" or "0.5"
41
42 enum {
43 // does not support complex Base types
44 IsComplex = 0 ,
45 // does not support integer Base types
46 IsInteger = 0 ,
47 // only support signed Base types
48 IsSigned = 1 ,
49 // must initialize an CG<Base> object
50 RequireInitialization = 1 ,
51 // computational cost of the corresponding operations
52 ReadCost = 1 ,
53 AddCost = 2 ,
54 MulCost = 2
55 };
56
62 return CppAD::numeric_limits<CppAD::cg::CG<Base> >::epsilon();
63 }
64
70 return 100. * CppAD::numeric_limits<CppAD::cg::CG<Base> >::epsilon();
71 }
72
77 return CppAD::numeric_limits<CppAD::cg::CG<Base> >::min();
78 }
79
84 return CppAD::numeric_limits<CppAD::cg::CG<Base> >::max();
85 }
86
90 static int digits10() {
91 return CppAD::numeric_limits<CppAD::cg::CG<Base> >::digits10;
92 }
93
94};
95
101template <typename Base>
102struct NumTraits<CppAD::AD<CppAD::cg::CG<Base> > > {
104 // the real part of an AD<CGBase> value
105 using Real = CppAD::AD<CGBase>;
106 // type for AD<CGBase> operations producing non-integer values
108 // type for nested value inside an AD<CGBase> expression tree
110 // type for numeric literals such as "2" or "0.5"
112
113 enum {
114 // does not support complex Base types
115 IsComplex = 0 ,
116 // does not support integer Base types
117 IsInteger = 0 ,
118 // only support signed Base types
119 IsSigned = 1 ,
120 // must initialize an AD<CGBase> object
121 RequireInitialization = 1 ,
122 // computational cost of the corresponding operations
123 ReadCost = 1 ,
124 AddCost = 2 ,
125 MulCost = 2
126 };
127
133 return CppAD::numeric_limits<CppAD::AD<CGBase> >::epsilon();
134 }
135
141 return 100. * CppAD::numeric_limits<CppAD::AD<CGBase> >::epsilon();
142 }
143
148 return CppAD::numeric_limits<CppAD::AD<CGBase> >::min();
149 }
150
155 return CppAD::numeric_limits<CppAD::AD<CGBase> >::max();
156 }
157
161 static int digits10() {
162 return CppAD::numeric_limits<CGBase>::digits10;
163 }
164
165};
166
167#if EIGEN_VERSION_AT_LEAST(3,2,93)
168
173template<typename Base, typename BinOp>
174struct ScalarBinaryOpTraits<CppAD::AD<CppAD::cg::CG<Base> >, Base, BinOp> {
175 using ReturnType = CppAD::AD<CppAD::cg::CG<Base> >;
176};
177
178template<typename Base, typename BinOp>
179struct ScalarBinaryOpTraits<Base, CppAD::AD<CppAD::cg::CG<Base> >, BinOp> {
180 using ReturnType = CppAD::AD<CppAD::cg::CG<Base> >;
181};
182
183template<typename Base, typename BinOp>
184struct ScalarBinaryOpTraits<CppAD::AD<CppAD::cg::CG<Base> >, CppAD::cg::CG<Base>, BinOp> {
185 using ReturnType = CppAD::AD<CppAD::cg::CG<Base> >;
186};
187
188template<typename Base, typename BinOp>
189struct ScalarBinaryOpTraits<CppAD::cg::CG<Base>, CppAD::AD<CppAD::cg::CG<Base> >, BinOp> {
190 using ReturnType = CppAD::AD<CppAD::cg::CG<Base> >;
191};
192
193
198template<typename Base, typename BinOp>
199struct ScalarBinaryOpTraits<CppAD::cg::CG<Base>, Base, BinOp> {
200 using ReturnType = CppAD::cg::CG<Base>;
201};
202
203template<typename Base, typename BinOp>
204struct ScalarBinaryOpTraits<Base, CppAD::cg::CG<Base>, BinOp> {
205 using ReturnType = CppAD::cg::CG<Base>;
206};
207
208#endif // #ifdef EIGEN_VERSION_AT_LEAST(3,2,93)
209
210} // namespace Eigen
211
212namespace CppAD {
213namespace cg {
214
219// functions that return references
220template <class Base>
222 return x;
223}
224
225template <class Base>
227 return x;
228}
229
230// functions that return values (note abs is defined by cppadcg.hpp)
231template <class Base>
234}
235
236template <class Base>
238 return x * x;
239}
240
245// functions that return references
246template <class Base>
247const CppAD::cg::CG<Base>& conj(const CppAD::cg::CG<Base>& x) {
248 return x;
249}
250
251template <class Base>
252const CppAD::cg::CG<Base>& real(const CppAD::cg::CG<Base>& x) {
253 return x;
254}
255
256// functions that return values (note abs is defined by cppadcg.hpp)
257template <class Base>
259 return CppAD::cg::CG<Base>(0.);
260}
261
262template <class Base>
264 return x * x;
265}
266
267}
268}
269
270# endif
static CppAD::cg::CG< Base > highest()
static CppAD::cg::CG< Base > lowest()
static CppAD::cg::CG< Base > epsilon()
static CppAD::cg::CG< Base > dummy_precision()