Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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"
39
40// Note: Sacado::Fad::Ops are forward-declared here, instead of in macros
41// below.
43
44#define UNARYFUNC_MACRO(OP,FADOP) \
45namespace Sacado { \
46 \
47 namespace Fad { \
48 template <typename T> \
49 SACADO_INLINE_FUNCTION \
50 Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
51 \
52 template <typename T> class SimpleFad; \
53 template <typename T> \
54 SimpleFad<T> OP (const SimpleFad<T>&); \
55 } \
56 \
57 namespace ELRFad { \
58 template <typename T> class FADOP; \
59 template <typename T> class Expr; \
60 template <typename T> \
61 SACADO_INLINE_FUNCTION \
62 Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
63 } \
64 \
65 namespace CacheFad { \
66 template <typename T> class FADOP; \
67 template <typename T> class Expr; \
68 template <typename T> \
69 SACADO_INLINE_FUNCTION \
70 Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
71 } \
72 \
73 namespace ELRCacheFad { \
74 template <typename T> class FADOP; \
75 template <typename T> class Expr; \
76 template <typename T> \
77 SACADO_INLINE_FUNCTION \
78 Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
79 } \
80 \
81 namespace LFad { \
82 template <typename T> class FADOP; \
83 template <typename T> class Expr; \
84 template <typename T> \
85 Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
86 } \
87 \
88 namespace Tay { \
89 template <typename T> class Taylor; \
90 template <typename T> Taylor<T> OP (const Base< Taylor<T> >&); \
91 } \
92 \
93 namespace FlopCounterPack { \
94 template <typename T> class ScalarFlopCounter; \
95 template <typename T> \
96 ScalarFlopCounter<T> OP (const Base< ScalarFlopCounter<T> >&); \
97 } \
98 \
99 namespace Rad { \
100 template <typename T> class ADvari; \
101 template <typename T> class IndepADvar; \
102 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&); \
103 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&); \
104 } \
105} \
106 \
107namespace std { \
108 using Sacado::Fad::OP; \
109 using Sacado::ELRFad::OP; \
110 using Sacado::CacheFad::OP; \
111 using Sacado::ELRCacheFad::OP; \
112 using Sacado::LFad::OP; \
113 using Sacado::Tay::OP; \
114 using Sacado::FlopCounterPack::OP; \
115 using Sacado::Rad::OP; \
116}
117
136#ifdef HAVE_SACADO_CXX11
138#endif
139
140#undef UNARYFUNC_MACRO
141
142namespace Sacado {
143 namespace Fad {
144 template <typename T>
147 }
148
149 namespace ELRFad {
150 template <typename T> class SafeSqrtOp;
151 template <typename T>
154 }
155
156 namespace CacheFad {
157 template <typename T> class SafeSqrtOp;
158 template <typename T>
161 }
162
163 namespace ELRCacheFad {
164 template <typename T> class SafeSqrtOp;
165 template <typename T>
168 }
169}
170
171#define BINARYFUNC_MACRO(OP,FADOP) \
172namespace Sacado { \
173 \
174 namespace Fad { \
175 template <typename T> class ConstExpr; \
176 template <typename T> struct IsFadExpr; \
177 template <typename T> struct ExprLevel; \
178 template <typename T1, typename T2> \
179 SACADO_INLINE_FUNCTION \
180 typename mpl::enable_if_c< \
181 ExprLevel< Expr<T1> >::value == ExprLevel< Expr<T2> >::value, \
182 Expr< FADOP< Expr<T1>, Expr<T2> > > \
183 >::type \
184 /*SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP)*/ \
185 OP (const Expr<T1>&, const Expr<T2>&); \
186 \
187 template <typename T> \
188 SACADO_INLINE_FUNCTION \
189 Expr< FADOP< Expr<T>, Expr<T> > > \
190 OP (const Expr<T>&, const Expr<T>&); \
191 \
192 template <typename T> \
193 SACADO_INLINE_FUNCTION \
194 Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
195 OP (const typename Expr<T>::value_type&, const Expr<T>&); \
196 \
197 template <typename T> \
198 SACADO_INLINE_FUNCTION \
199 Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
200 OP (const Expr<T>&, const typename Expr<T>::value_type&); \
201 \
202 template <typename T> \
203 SACADO_INLINE_FUNCTION \
204 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
205 OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
206 \
207 template <typename T> \
208 SACADO_INLINE_FUNCTION \
209 SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
210 OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
211 \
212 template <typename T> class SimpleFad; \
213 template <typename T> \
214 SimpleFad<T> \
215 OP (const SimpleFad<T>&, const SimpleFad<T>&); \
216 \
217 template <typename T> \
218 SimpleFad<T> \
219 OP (const SimpleFad<T>&, \
220 const typename SimpleFad<T>::value_type&); \
221 \
222 template <typename T> \
223 SimpleFad<T> \
224 OP (const typename SimpleFad<T>::value_type&, \
225 const SimpleFad<T>&); \
226 } \
227 \
228 namespace ELRFad { \
229 template <typename T1, typename T2> class FADOP; \
230 template <typename T> class Expr; \
231 template <typename T> class ConstExpr; \
232 template <typename T> struct IsFadExpr; \
233 template <typename T> struct ExprLevel; \
234 template <typename T1, typename T2> \
235 SACADO_INLINE_FUNCTION \
236 SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
237 OP (const T1&, const T2&); \
238 \
239 template <typename T> \
240 SACADO_INLINE_FUNCTION \
241 Expr< FADOP< Expr<T>, Expr<T> > > \
242 OP (const Expr<T>&, const Expr<T>&); \
243 \
244 template <typename T> \
245 SACADO_INLINE_FUNCTION \
246 Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
247 OP (const typename Expr<T>::value_type&, const Expr<T>&); \
248 \
249 template <typename T> \
250 SACADO_INLINE_FUNCTION \
251 Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
252 OP (const Expr<T>&, const typename Expr<T>::value_type&); \
253 \
254 template <typename T> \
255 SACADO_INLINE_FUNCTION \
256 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
257 OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
258 \
259 template <typename T> \
260 SACADO_INLINE_FUNCTION \
261 SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
262 OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
263 } \
264 \
265 namespace CacheFad { \
266 template <typename T1, typename T2> class FADOP; \
267 template <typename T> class Expr; \
268 template <typename T> class ConstExpr; \
269 template <typename T> struct IsFadExpr; \
270 template <typename T> struct ExprLevel; \
271 template <typename T1, typename T2> \
272 SACADO_INLINE_FUNCTION \
273 SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
274 OP (const T1&, const T2&); \
275 \
276 template <typename T> \
277 SACADO_INLINE_FUNCTION \
278 Expr< FADOP< Expr<T>, Expr<T> > > \
279 OP (const Expr<T>&, const Expr<T>&); \
280 \
281 template <typename T> \
282 SACADO_INLINE_FUNCTION \
283 Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
284 OP (const typename Expr<T>::value_type&, const Expr<T>&); \
285 \
286 template <typename T> \
287 SACADO_INLINE_FUNCTION \
288 Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
289 OP (const Expr<T>&, const typename Expr<T>::value_type&); \
290 \
291 template <typename T> \
292 SACADO_INLINE_FUNCTION \
293 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
294 OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
295 \
296 template <typename T> \
297 SACADO_INLINE_FUNCTION \
298 SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
299 OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
300 } \
301 \
302 namespace ELRCacheFad { \
303 template <typename T1, typename T2> class FADOP; \
304 template <typename T> class Expr; \
305 template <typename T> class ConstExpr; \
306 template <typename T> struct IsFadExpr; \
307 template <typename T> struct ExprLevel; \
308 template <typename T1, typename T2> \
309 SACADO_INLINE_FUNCTION \
310 SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
311 OP (const T1&, const T2&); \
312 \
313 template <typename T> \
314 SACADO_INLINE_FUNCTION \
315 Expr< FADOP< Expr<T>, Expr<T> > > \
316 OP (const Expr<T>&, const Expr<T>&); \
317 \
318 template <typename T> \
319 SACADO_INLINE_FUNCTION \
320 Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
321 OP (const typename Expr<T>::value_type&, const Expr<T>&); \
322 \
323 template <typename T> \
324 SACADO_INLINE_FUNCTION \
325 Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
326 OP (const Expr<T>&, const typename Expr<T>::value_type&); \
327 \
328 template <typename T> \
329 SACADO_INLINE_FUNCTION \
330 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
331 OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
332 \
333 template <typename T> \
334 SACADO_INLINE_FUNCTION \
335 SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
336 OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
337 } \
338 \
339 namespace LFad { \
340 template <typename T1, typename T2> class FADOP; \
341 template <typename T> class Expr; \
342 \
343 template <typename T1, typename T2> \
344 Expr< FADOP< Expr<T1>, Expr<T2> > > \
345 OP (const Expr<T1>&, const Expr<T2>&); \
346 \
347 template <typename T> \
348 Expr< FADOP< Expr<T>, Expr<T> > > \
349 OP (const Expr<T>&, const Expr<T>&); \
350 \
351 template <typename T> \
352 Expr< FADOP< typename Expr<T>::value_type, Expr<T> > > \
353 OP (const typename Expr<T>::value_type&, const Expr<T>&); \
354 \
355 template <typename T> \
356 Expr< FADOP< Expr<T>, typename Expr<T>::value_type > > \
357 OP (const Expr<T>&, const typename Expr<T>::value_type&); \
358 } \
359 \
360 namespace Tay { \
361 template <typename T> class Taylor; \
362 template <typename T> Taylor<T> OP ( \
363 const Base< Taylor<T> >&, \
364 const Base< Taylor<T> >&); \
365 template <typename T> Taylor<T> OP ( \
366 const typename Taylor<T>::value_type&, \
367 const Base< Taylor<T> >&); \
368 template <typename T> Taylor<T> OP ( \
369 const Base< Taylor<T> >&, \
370 const typename Taylor<T>::value_type&); \
371 } \
372 \
373 namespace FlopCounterPack { \
374 template <typename T> class ScalarFlopCounter; \
375 template <typename T> \
376 ScalarFlopCounter<T> OP ( \
377 const Base< ScalarFlopCounter<T> >&, \
378 const Base< ScalarFlopCounter<T> >&); \
379 template <typename T> \
380 ScalarFlopCounter<T> OP ( \
381 const typename ScalarFlopCounter<T>::value_type&, \
382 const Base< ScalarFlopCounter<T> >&); \
383 template <typename T> \
384 ScalarFlopCounter<T> OP ( \
385 const Base< ScalarFlopCounter<T> >&, \
386 const typename ScalarFlopCounter<T>::value_type&); \
387 template <typename T> \
388 ScalarFlopCounter<T> OP ( \
389 const int&, \
390 const Base< ScalarFlopCounter<T> >&); \
391 template <typename T> \
392 ScalarFlopCounter<T> OP ( \
393 const Base< ScalarFlopCounter<T> >&, \
394 const int&); \
395 } \
396 \
397 namespace Rad { \
398 template <typename T> class ADvari; \
399 template <typename T> class IndepADvar; \
400 template <typename T> class DoubleAvoid; \
401 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
402 const Base< ADvari<T> >&); \
403 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
404 const Base< ADvari<T> >&); \
405 template <typename T> ADvari<T>& OP (T, \
406 const Base< ADvari<T> >&); \
407 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
408 const Base< ADvari<T> >&); \
409 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
410 const Base< ADvari<T> >&); \
411 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
412 const Base< ADvari<T> >&); \
413 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
414 const Base< IndepADvar<T> >&); \
415 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
416 T); \
417 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
418 typename DoubleAvoid<T>::dtype);\
419 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
420 typename DoubleAvoid<T>::itype);\
421 template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
422 typename DoubleAvoid<T>::ltype);\
423 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
424 const Base< IndepADvar<T> >&); \
425 template <typename T> ADvari<T>& OP (T, \
426 const Base< IndepADvar<T> >&); \
427 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
428 const Base< IndepADvar<T> >&); \
429 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
430 const Base< IndepADvar<T> >&); \
431 template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
432 const Base< IndepADvar<T> >&); \
433 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
434 T); \
435 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
436 typename DoubleAvoid<T>::dtype);\
437 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
438 typename DoubleAvoid<T>::itype);\
439 template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
440 typename DoubleAvoid<T>::ltype);\
441 } \
442 \
443} \
444 \
445namespace std { \
446 using Sacado::Fad::OP; \
447 using Sacado::ELRFad::OP; \
448 using Sacado::CacheFad::OP; \
449 using Sacado::ELRCacheFad::OP; \
450 using Sacado::LFad::OP; \
451 using Sacado::Tay::OP; \
452 using Sacado::FlopCounterPack::OP; \
453 using Sacado::Rad::OP; \
454}
455
460
461#undef BINARYFUNC_MACRO
462
463#if defined(HAVE_SACADO_KOKKOSCORE)
464
465namespace Sacado {
466#ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
467 namespace Fad {
468 template <typename ValT, unsigned sl, unsigned ss, typename U>
469 class ViewFadPtr;
470 template <typename T> class DFad;
471 template <typename T, int N> class SFad;
472 template <typename T, int N> class SLFad;
473 template <typename T>
475 void atomic_add(DFad<T>* dst, const DFad<T>& x);
476 template <typename T, int N>
478 void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
479 template <typename T, int N>
481 void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
482 template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
484 void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
485 }
486#endif
487 namespace ELRFad {
488 template <typename ValT, unsigned sl, unsigned ss, typename U>
489 class ViewFadPtr;
490 template <typename T> class DFad;
491 template <typename T, int N> class SFad;
492 template <typename T, int N> class SLFad;
493 template <typename T>
495 void atomic_add(DFad<T>* dst, const DFad<T>& x);
496 template <typename T, int N>
498 void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
499 template <typename T, int N>
501 void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
502 template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
504 void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
505 }
506 namespace CacheFad {
507 template <typename ValT, unsigned sl, unsigned ss, typename U>
508 class ViewFadPtr;
509 template <typename T> class DFad;
510 template <typename T, int N> class SFad;
511 template <typename T, int N> class SLFad;
512 template <typename T>
514 void atomic_add(DFad<T>* dst, const DFad<T>& x);
515 template <typename T, int N>
517 void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
518 template <typename T, int N>
520 void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
521 template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
523 void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
524 }
525 namespace ELRCacheFad {
526 template <typename ValT, unsigned sl, unsigned ss, typename U>
527 class ViewFadPtr;
528 template <typename T> class DFad;
529 template <typename T, int N> class SFad;
530 template <typename T, int N> class SLFad;
531 template <typename T>
533 void atomic_add(DFad<T>* dst, const DFad<T>& x);
534 template <typename T, int N>
536 void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
537 template <typename T, int N>
539 void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
540 template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
542 void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
543 }
544}
545
546namespace Kokkos {
547#ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
549#endif
550 using Sacado::ELRFad::atomic_add;
551 using Sacado::CacheFad::atomic_add;
552 using Sacado::ELRCacheFad::atomic_add;
553}
554
555#endif
556
557#ifdef SACADO_ENABLE_NEW_DESIGN
559#endif
560
561#endif // SACADO_MATHFUNCTIONS_HPP
#define SACADO_INLINE_FUNCTION
expr expr SinOp
expr expr SinhOp
expr expr SqrtOp
expr expr ACosOp
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MaxOp
expr expr ATanOp
expr expr ACoshOp
expr expr ASinOp
expr expr TanhOp
expr expr TanOp
expr expr CoshOp
expr expr ASinhOp
expr expr Log10Op
expr expr expr ExpOp
expr expr AbsOp
expr expr ATanhOp
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 expr1 expr1 c *expr2 expr1 c *expr2 expr1 c *expr2 expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 Atan2Op
expr expr CosOp
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
#define UNARYFUNC_MACRO(OP, FADOP)
#define BINARYFUNC_MACRO(OP, FADOP)
Wrapper for a generic expression template.
Wrapper for a generic expression template.
Wrapper for a generic expression template.
Fad specializations for Teuchos::BLAS wrappers.
SACADO_INLINE_FUNCTION Expr< SafeSqrtOp< Expr< T > > > safe_sqrt(const Expr< T > &)
SACADO_INLINE_FUNCTION Expr< SafeSqrtOp< Expr< T > > > safe_sqrt(const Expr< T > &)
SACADO_INLINE_FUNCTION Expr< SafeSqrtOp< Expr< T > > > safe_sqrt(const Expr< T > &)
SACADO_INLINE_FUNCTION Expr< SafeSqrtOp< Expr< T > > > safe_sqrt(const Expr< T > &)