CppADCodeGen  2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
math.hpp
1 #ifndef CPPAD_CG_MATH_INCLUDED
2 #define CPPAD_CG_MATH_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2012 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 namespace CppAD {
19 
20 #define CPPAD_CG_CREATE_OPERATION(OpName, OpCode) \
21  template<class Base> \
22  inline cg::CG<Base> OpName(const cg::CG<Base>& var) { \
23  using namespace CppAD::cg; \
24  if (var.isParameter()) { \
25  return CG<Base> (OpName(var.getValue())); \
26  } else { \
27  CodeHandler<Base>& h = *var.getOperationNode()->getCodeHandler(); \
28  CG<Base> result(*h.makeNode(CGOpCode::OpCode, var.argument())); \
29  if(var.isValueDefined()) \
30  result.setValue(OpName(var.getValue())); \
31  return result; \
32  } \
33  }
34 
35 CPPAD_CG_CREATE_OPERATION(abs, Abs)
36 CPPAD_CG_CREATE_OPERATION(fabs, Abs)
37 CPPAD_CG_CREATE_OPERATION(acos, Acos)
38 CPPAD_CG_CREATE_OPERATION(asin, Asin)
39 CPPAD_CG_CREATE_OPERATION(atan, Atan)
40 CPPAD_CG_CREATE_OPERATION(cos, Cos)
41 CPPAD_CG_CREATE_OPERATION(cosh, Cosh)
42 CPPAD_CG_CREATE_OPERATION(exp, Exp)
43 CPPAD_CG_CREATE_OPERATION(log, Log)
44 CPPAD_CG_CREATE_OPERATION(sin, Sin)
45 CPPAD_CG_CREATE_OPERATION(sinh, Sinh)
46 CPPAD_CG_CREATE_OPERATION(sqrt, Sqrt)
47 CPPAD_CG_CREATE_OPERATION(tan, Tan)
48 CPPAD_CG_CREATE_OPERATION(tanh, Tanh)
49 
50 #if CPPAD_USE_CPLUSPLUS_2011
51 // c++11 functions
52 CPPAD_CG_CREATE_OPERATION(erf, Erf)
53 CPPAD_CG_CREATE_OPERATION(erfc, Erfc)
54 CPPAD_CG_CREATE_OPERATION(asinh, Asinh)
55 CPPAD_CG_CREATE_OPERATION(acosh, Acosh)
56 CPPAD_CG_CREATE_OPERATION(atanh, Atanh)
57 CPPAD_CG_CREATE_OPERATION(expm1, Expm1)
58 CPPAD_CG_CREATE_OPERATION(log1p, Log1p)
59 #endif
60 
61 template <class Base>
62 inline cg::CG<Base> log10(const cg::CG<Base> &x) {
63  return CppAD::log(x) / CppAD::log(Base(10));
64 }
65 
66 namespace cg {
67 
68  using CppAD::abs;
69  using CppAD::fabs;
70  using CppAD::acos;
71  using CppAD::asin;
72  using CppAD::atan;
73  using CppAD::cos;
74  using CppAD::cosh;
75  using CppAD::exp;
76  using CppAD::log;
77  using CppAD::sin;
78  using CppAD::sinh;
79  using CppAD::asin;
80  using CppAD::sqrt;
81  using CppAD::tan;
82  using CppAD::tanh;
83 
84 #if CPPAD_USE_CPLUSPLUS_2011
85  using CppAD::erf;
86  using CppAD::erfc;
87  using CppAD::asinh;
88  using CppAD::acosh;
89  using CppAD::atanh;
90  using CppAD::expm1;
91  using CppAD::log1p;
92 #endif
93 
94  using CppAD::log10;
95 
96 } // END cg namespace
97 } // END CppAD namespace
98 
99 #endif
CppAD
Definition: abstract_atomic_fun.hpp:19