Code-Eli  0.3.6
dual_functions.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_mutil_ad_dual_functions_hpp
14 #define eli_mutil_ad_dual_functions_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 #include "eli/util/traits.hpp"
19 
22 
23 namespace eli
24 {
25  namespace mutil
26  {
27  namespace ad
28  {
29  namespace dual_number
30  {
31  template <typename data__, typename fun_ob__>
32  class unary_fun
33  {
34  public:
35  typedef typename data__::data_type data_type;
36 
37  private:
39 
40  public:
41  unary_fun(const data__ &v) : val(v) {}
42 
43  data_type real() const
44  {
45  return fun_ob__::f(val.real());
46  }
47 
48  data_type nonreal() const
49  {
50  return val.nonreal()*fun_ob__::fp(val.real());
51  }
52  };
53  }
54  }
55  }
56 }
57 
58 #define ELI_AD_DUAL_UNARY_OP_HELPER(x) \
59 template <typename data__, bool comp_real_only> \
60 eli::mutil::ad::dual_number::expression<eli::mutil::ad::dual_number::unary_fun<eli::mutil::ad::dual<data__, comp_real_only>, \
61  eli::mutil::ad::x ## _fun<data__> >, comp_real_only> \
62  x (const eli::mutil::ad::dual<data__, comp_real_only> &v) \
63 { \
64  typedef eli::mutil::ad::dual_number::unary_fun<eli::mutil::ad::dual<data__, comp_real_only>,eli::mutil::ad::x ## _fun<data__> > un_fun_t; \
65  \
66  return eli::mutil::ad::dual_number::expression<un_fun_t, comp_real_only>(un_fun_t(v)); \
67 } \
68 template <typename data__, bool comp_real_only> \
69 eli::mutil::ad::dual_number::expression<eli::mutil::ad::dual_number::unary_fun<eli::mutil::ad::dual_number::expression<data__, comp_real_only>, \
70  eli::mutil::ad::x ## _fun<typename eli::mutil::ad::dual_number::expression<data__, comp_real_only>::data_type > >, \
71  comp_real_only> \
72  x (const eli::mutil::ad::dual_number::expression<data__, comp_real_only> &v) \
73 { \
74  typedef eli::mutil::ad::dual_number::unary_fun<eli::mutil::ad::dual_number::expression<data__, comp_real_only>, \
75  eli::mutil::ad::x ## _fun<typename eli::mutil::ad::dual_number::expression<data__, comp_real_only>::data_type > > un_fun_t; \
76  \
77  return eli::mutil::ad::dual_number::expression<un_fun_t, comp_real_only>(un_fun_t(v)); \
78 }
79 
80 #endif
Definition: math.hpp:20
Definition: dual_functions.hpp:32
data_type nonreal() const
Definition: dual_functions.hpp:48
data_type real() const
Definition: dual_functions.hpp:43
const data__ & const_expr_ref
Definition: traits.hpp:45
eli::util::traits< data__ >::const_expr_ref val
Definition: dual_functions.hpp:38
data__::data_type data_type
Definition: dual_functions.hpp:35
unary_fun(const data__ &v)
Definition: dual_functions.hpp:41