CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
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
18namespace 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
35CPPAD_CG_CREATE_OPERATION(abs, Abs)
36CPPAD_CG_CREATE_OPERATION(fabs, Abs)
37CPPAD_CG_CREATE_OPERATION(acos, Acos)
38CPPAD_CG_CREATE_OPERATION(asin, Asin)
39CPPAD_CG_CREATE_OPERATION(atan, Atan)
40CPPAD_CG_CREATE_OPERATION(cos, Cos)
41CPPAD_CG_CREATE_OPERATION(cosh, Cosh)
42CPPAD_CG_CREATE_OPERATION(exp, Exp)
43CPPAD_CG_CREATE_OPERATION(log, Log)
44CPPAD_CG_CREATE_OPERATION(sin, Sin)
45CPPAD_CG_CREATE_OPERATION(sinh, Sinh)
46CPPAD_CG_CREATE_OPERATION(sqrt, Sqrt)
47CPPAD_CG_CREATE_OPERATION(tan, Tan)
48CPPAD_CG_CREATE_OPERATION(tanh, Tanh)
49
50#if CPPAD_USE_CPLUSPLUS_2011
51// c++11 functions
52CPPAD_CG_CREATE_OPERATION(erf, Erf)
53CPPAD_CG_CREATE_OPERATION(erfc, Erfc)
54CPPAD_CG_CREATE_OPERATION(asinh, Asinh)
55CPPAD_CG_CREATE_OPERATION(acosh, Acosh)
56CPPAD_CG_CREATE_OPERATION(atanh, Atanh)
57CPPAD_CG_CREATE_OPERATION(expm1, Expm1)
58CPPAD_CG_CREATE_OPERATION(log1p, Log1p)
59#endif
60
61template <class Base>
62inline cg::CG<Base> log10(const cg::CG<Base> &x) {
63 return CppAD::log(x) / CppAD::log(Base(10));
64}
65
66namespace 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