Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_MathFunctions.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_MATHFUNCTIONS_HPP
31 #define SACADO_MATHFUNCTIONS_HPP
32 
33 #include <cmath>
34 
35 #include "Sacado_ConfigDefs.h"
36 #include "Sacado_Base.hpp"
38 #include "Sacado_SFINAE_Macros.hpp"
39 
40 #define UNARYFUNC_MACRO(OP,FADOP) \
41 namespace Sacado { \
42  \
43  namespace Fad { \
44  template <typename T> class FADOP; \
45  template <typename T> \
46  KOKKOS_INLINE_FUNCTION \
47  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
48  template <typename T> class SimpleFad; \
49  template <typename T> \
50  SimpleFad<T> OP (const SimpleFad<T>&); \
51  } \
52  \
53  namespace ELRFad { \
54  template <typename T> class FADOP; \
55  template <typename T> class Expr; \
56  template <typename T> \
57  KOKKOS_INLINE_FUNCTION \
58  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
59  } \
60  \
61  namespace CacheFad { \
62  template <typename T> class FADOP; \
63  template <typename T> class Expr; \
64  template <typename T> \
65  KOKKOS_INLINE_FUNCTION \
66  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
67  } \
68  \
69  namespace ELRCacheFad { \
70  template <typename T> class FADOP; \
71  template <typename T> class Expr; \
72  template <typename T> \
73  KOKKOS_INLINE_FUNCTION \
74  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
75  } \
76  \
77  namespace LFad { \
78  template <typename T> class FADOP; \
79  template <typename T> class Expr; \
80  template <typename T> \
81  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
82  } \
83  \
84  namespace Tay { \
85  template <typename T> class Taylor; \
86  template <typename T> Taylor<T> OP (const Base< Taylor<T> >&); \
87  } \
88  \
89  namespace FlopCounterPack { \
90  template <typename T> class ScalarFlopCounter; \
91  template <typename T> \
92  ScalarFlopCounter<T> OP (const Base< ScalarFlopCounter<T> >&); \
93  } \
94  \
95  namespace Rad { \
96  template <typename T> class ADvari; \
97  template <typename T> class IndepADvar; \
98  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&); \
99  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&); \
100  } \
101 } \
102  \
103 namespace std { \
104  using Sacado::Fad::OP; \
105  using Sacado::ELRFad::OP; \
106  using Sacado::CacheFad::OP; \
107  using Sacado::ELRCacheFad::OP; \
108  using Sacado::LFad::OP; \
109  using Sacado::Tay::OP; \
110  using Sacado::FlopCounterPack::OP; \
111  using Sacado::Rad::OP; \
112 }
113 
132 #ifdef HAVE_SACADO_CXX11
133 UNARYFUNC_MACRO(cbrt, CbrtOp)
134 #endif
135 
136 #undef UNARYFUNC_MACRO
137 
138 #define BINARYFUNC_MACRO(OP,FADOP) \
139 namespace Sacado { \
140  \
141  namespace Fad { \
142  template <typename T1, typename T2> class FADOP; \
143  template <typename T> class ConstExpr; \
144  template <typename T> struct IsFadExpr; \
145  template <typename T> struct ExprLevel; \
146  template <typename T1, typename T2> \
147  KOKKOS_INLINE_FUNCTION \
148  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
149  OP (const T1&, const T2&); \
150  \
151  template <typename T> \
152  KOKKOS_INLINE_FUNCTION \
153  Expr< FADOP< Expr<T>, Expr<T> > > \
154  OP (const Expr<T>&, const Expr<T>&); \
155  \
156  template <typename T> \
157  KOKKOS_INLINE_FUNCTION \
158  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
159  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
160  \
161  template <typename T> \
162  KOKKOS_INLINE_FUNCTION \
163  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
164  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
165  \
166  template <typename T> \
167  KOKKOS_INLINE_FUNCTION \
168  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
169  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
170  \
171  template <typename T> \
172  KOKKOS_INLINE_FUNCTION \
173  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
174  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
175  \
176  template <typename T> class SimpleFad; \
177  template <typename T> \
178  SimpleFad<T> \
179  OP (const SimpleFad<T>&, const SimpleFad<T>&); \
180  \
181  template <typename T> \
182  SimpleFad<T> \
183  OP (const SimpleFad<T>&, \
184  const typename SimpleFad<T>::value_type&); \
185  \
186  template <typename T> \
187  SimpleFad<T> \
188  OP (const typename SimpleFad<T>::value_type&, \
189  const SimpleFad<T>&); \
190  } \
191  \
192  namespace ELRFad { \
193  template <typename T1, typename T2> class FADOP; \
194  template <typename T> class Expr; \
195  template <typename T> class ConstExpr; \
196  template <typename T> struct IsFadExpr; \
197  template <typename T> struct ExprLevel; \
198  template <typename T1, typename T2> \
199  KOKKOS_INLINE_FUNCTION \
200  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
201  OP (const T1&, const T2&); \
202  \
203  template <typename T> \
204  KOKKOS_INLINE_FUNCTION \
205  Expr< FADOP< Expr<T>, Expr<T> > > \
206  OP (const Expr<T>&, const Expr<T>&); \
207  \
208  template <typename T> \
209  KOKKOS_INLINE_FUNCTION \
210  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
211  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
212  \
213  template <typename T> \
214  KOKKOS_INLINE_FUNCTION \
215  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
216  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
217  \
218  template <typename T> \
219  KOKKOS_INLINE_FUNCTION \
220  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
221  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
222  \
223  template <typename T> \
224  KOKKOS_INLINE_FUNCTION \
225  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
226  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
227  } \
228  \
229  namespace CacheFad { \
230  template <typename T1, typename T2> class FADOP; \
231  template <typename T> class Expr; \
232  template <typename T> class ConstExpr; \
233  template <typename T> struct IsFadExpr; \
234  template <typename T> struct ExprLevel; \
235  template <typename T1, typename T2> \
236  KOKKOS_INLINE_FUNCTION \
237  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
238  OP (const T1&, const T2&); \
239  \
240  template <typename T> \
241  KOKKOS_INLINE_FUNCTION \
242  Expr< FADOP< Expr<T>, Expr<T> > > \
243  OP (const Expr<T>&, const Expr<T>&); \
244  \
245  template <typename T> \
246  KOKKOS_INLINE_FUNCTION \
247  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
248  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
249  \
250  template <typename T> \
251  KOKKOS_INLINE_FUNCTION \
252  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
253  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
254  \
255  template <typename T> \
256  KOKKOS_INLINE_FUNCTION \
257  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
258  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
259  \
260  template <typename T> \
261  KOKKOS_INLINE_FUNCTION \
262  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
263  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
264  } \
265  \
266  namespace ELRCacheFad { \
267  template <typename T1, typename T2> class FADOP; \
268  template <typename T> class Expr; \
269  template <typename T> class ConstExpr; \
270  template <typename T> struct IsFadExpr; \
271  template <typename T> struct ExprLevel; \
272  template <typename T1, typename T2> \
273  KOKKOS_INLINE_FUNCTION \
274  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
275  OP (const T1&, const T2&); \
276  \
277  template <typename T> \
278  KOKKOS_INLINE_FUNCTION \
279  Expr< FADOP< Expr<T>, Expr<T> > > \
280  OP (const Expr<T>&, const Expr<T>&); \
281  \
282  template <typename T> \
283  KOKKOS_INLINE_FUNCTION \
284  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
285  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
286  \
287  template <typename T> \
288  KOKKOS_INLINE_FUNCTION \
289  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
290  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
291  \
292  template <typename T> \
293  KOKKOS_INLINE_FUNCTION \
294  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
295  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
296  \
297  template <typename T> \
298  KOKKOS_INLINE_FUNCTION \
299  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
300  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
301  } \
302  \
303  namespace LFad { \
304  template <typename T1, typename T2> class FADOP; \
305  template <typename T> class Expr; \
306  \
307  template <typename T1, typename T2> \
308  Expr< FADOP< Expr<T1>, Expr<T2> > > \
309  OP (const Expr<T1>&, const Expr<T2>&); \
310  \
311  template <typename T> \
312  Expr< FADOP< Expr<T>, Expr<T> > > \
313  OP (const Expr<T>&, const Expr<T>&); \
314  \
315  template <typename T> \
316  Expr< FADOP< typename Expr<T>::value_type, Expr<T> > > \
317  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
318  \
319  template <typename T> \
320  Expr< FADOP< Expr<T>, typename Expr<T>::value_type > > \
321  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
322  } \
323  \
324  namespace Tay { \
325  template <typename T> class Taylor; \
326  template <typename T> Taylor<T> OP ( \
327  const Base< Taylor<T> >&, \
328  const Base< Taylor<T> >&); \
329  template <typename T> Taylor<T> OP ( \
330  const typename Taylor<T>::value_type&, \
331  const Base< Taylor<T> >&); \
332  template <typename T> Taylor<T> OP ( \
333  const Base< Taylor<T> >&, \
334  const typename Taylor<T>::value_type&); \
335  } \
336  \
337  namespace FlopCounterPack { \
338  template <typename T> class ScalarFlopCounter; \
339  template <typename T> \
340  ScalarFlopCounter<T> OP ( \
341  const Base< ScalarFlopCounter<T> >&, \
342  const Base< ScalarFlopCounter<T> >&); \
343  template <typename T> \
344  ScalarFlopCounter<T> OP ( \
345  const typename ScalarFlopCounter<T>::value_type&, \
346  const Base< ScalarFlopCounter<T> >&); \
347  template <typename T> \
348  ScalarFlopCounter<T> OP ( \
349  const Base< ScalarFlopCounter<T> >&, \
350  const typename ScalarFlopCounter<T>::value_type&); \
351  template <typename T> \
352  ScalarFlopCounter<T> OP ( \
353  const int&, \
354  const Base< ScalarFlopCounter<T> >&); \
355  template <typename T> \
356  ScalarFlopCounter<T> OP ( \
357  const Base< ScalarFlopCounter<T> >&, \
358  const int&); \
359  } \
360  \
361  namespace Rad { \
362  template <typename T> class ADvari; \
363  template <typename T> class IndepADvar; \
364  template <typename T> class DoubleAvoid; \
365  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
366  const Base< ADvari<T> >&); \
367  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
368  const Base< ADvari<T> >&); \
369  template <typename T> ADvari<T>& OP (T, \
370  const Base< ADvari<T> >&); \
371  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
372  const Base< ADvari<T> >&); \
373  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
374  const Base< ADvari<T> >&); \
375  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
376  const Base< ADvari<T> >&); \
377  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
378  const Base< IndepADvar<T> >&); \
379  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
380  T); \
381  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
382  typename DoubleAvoid<T>::dtype);\
383  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
384  typename DoubleAvoid<T>::itype);\
385  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
386  typename DoubleAvoid<T>::ltype);\
387  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
388  const Base< IndepADvar<T> >&); \
389  template <typename T> ADvari<T>& OP (T, \
390  const Base< IndepADvar<T> >&); \
391  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
392  const Base< IndepADvar<T> >&); \
393  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
394  const Base< IndepADvar<T> >&); \
395  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
396  const Base< IndepADvar<T> >&); \
397  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
398  T); \
399  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
400  typename DoubleAvoid<T>::dtype);\
401  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
402  typename DoubleAvoid<T>::itype);\
403  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
404  typename DoubleAvoid<T>::ltype);\
405  } \
406  \
407 } \
408  \
409 namespace std { \
410  using Sacado::Fad::OP; \
411  using Sacado::ELRFad::OP; \
412  using Sacado::CacheFad::OP; \
413  using Sacado::ELRCacheFad::OP; \
414  using Sacado::LFad::OP; \
415  using Sacado::Tay::OP; \
416  using Sacado::FlopCounterPack::OP; \
417  using Sacado::Rad::OP; \
418 }
419 
423 BINARYFUNC_MACRO(min, MinOp)
424 
425 #undef BINARYFUNC_MACRO
426 
427 #endif // SACADO_MATHFUNCTIONS_HPP
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 Atan2Op
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 MaxOp
SimpleFad< ValueT > atan2(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > sqrt(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > asin(const SimpleFad< ValueT > &a)
expr expr expr ExpOp
SimpleFad< ValueT > log(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > exp(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > atan(const SimpleFad< ValueT > &a)
#define BINARYFUNC_MACRO(OP, FADOP)
SimpleFad< ValueT > log10(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > sin(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > sinh(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > pow(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > tan(const SimpleFad< ValueT > &a)
expr acosh(expr.val())) FAD_UNARYOP_MACRO(asinh
expr asinh(expr.val())) FAD_UNARYOP_MACRO(atanh
SimpleFad< ValueT > cos(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > cosh(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
KOKKOS_INLINE_FUNCTION Expr< AbsOp< Expr< T > > > abs(const Expr< T > &expr)
KOKKOS_INLINE_FUNCTION Expr< FAbsOp< Expr< T > > > fabs(const Expr< T > &expr)
expr atanh(expr.val())) FAD_UNARYOP_MACRO(abs
SimpleFad< ValueT > acos(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > tanh(const SimpleFad< ValueT > &a)
#define UNARYFUNC_MACRO(OP, FADOP)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 PowerOp