CppADCodeGen  2.3.0
A C++ Algorithmic Differentiation Package with Source Code Generation
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 
24 namespace Eigen {
25 
31 template<typename Base>
32 struct NumTraits<CppAD::cg::CG<Base> > {
33  // the real part of an CG<Base> value
34  using Real = CppAD::cg::CG<Base> ;
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 
101 template <typename Base>
102 struct NumTraits<CppAD::AD<CppAD::cg::CG<Base> > > {
103  using CGBase = 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
109  using Nested = CppAD::AD<CGBase>;
110  // type for numeric literals such as "2" or "0.5"
111  using Literal = CppAD::AD<CGBase>;
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 
171 template<typename Base, typename BinOp>
172 struct ScalarBinaryOpTraits<CppAD::AD<CppAD::cg::CG<Base> >, Base, BinOp> {
174 };
175 
176 template<typename Base, typename BinOp>
177 struct ScalarBinaryOpTraits<Base, CppAD::AD<CppAD::cg::CG<Base> >, BinOp> {
179 };
180 
181 template<typename Base, typename BinOp>
182 struct ScalarBinaryOpTraits<CppAD::AD<CppAD::cg::CG<Base> >, CppAD::cg::CG<Base>, BinOp> {
184 };
185 
186 template<typename Base, typename BinOp>
187 struct ScalarBinaryOpTraits<CppAD::cg::CG<Base>, CppAD::AD<CppAD::cg::CG<Base> >, BinOp> {
189 };
190 
191 
196 template<typename Base, typename BinOp>
197 struct ScalarBinaryOpTraits<CppAD::cg::CG<Base>, Base, BinOp> {
199 };
200 
201 template<typename Base, typename BinOp>
202 struct ScalarBinaryOpTraits<Base, CppAD::cg::CG<Base>, BinOp> {
204 };
205 
206 }
207 
208 namespace CppAD {
209 namespace cg {
210 
215 // functions that return references
216 template <class Base>
218  return x;
219 }
220 
221 template <class Base>
223  return x;
224 }
225 
226 // functions that return values (note abs is defined by cppadcg.hpp)
227 template <class Base>
229  return CppAD::AD<CppAD::cg::CG<Base> >(0.);
230 }
231 
232 template <class Base>
234  return x * x;
235 }
236 
241 // functions that return references
242 template <class Base>
243 const CppAD::cg::CG<Base>& conj(const CppAD::cg::CG<Base>& x) {
244  return x;
245 }
246 
247 template <class Base>
248 const CppAD::cg::CG<Base>& real(const CppAD::cg::CG<Base>& x) {
249  return x;
250 }
251 
252 // functions that return values (note abs is defined by cppadcg.hpp)
253 template <class Base>
255  return CppAD::cg::CG<Base>(0.);
256 }
257 
258 template <class Base>
260  return x * x;
261 }
262 
263 }
264 }
265 
266 # endif
static CppAD::cg::CG< Base > highest()
static CppAD::cg::CG< Base > dummy_precision()
static CppAD::cg::CG< Base > lowest()
static CppAD::cg::CG< Base > epsilon()