10 #include "Sacado_cmath.hpp"
14 #include <cuda_runtime_api.h>
17 #if CUDART_VERSION < 10000
18 #include <math_functions.h>
86 #define MP_UNARYOP_MACRO(OPNAME,OP,OPER,USING_OP) \
91 template <typename T> \
93 public Expr< OP< T > > { \
96 typedef typename remove_volatile<T>::type Tnv; \
97 typedef typename Tnv::value_type value_type; \
98 typedef typename Tnv::storage_type storage_type; \
99 typedef typename Tnv::base_expr_type base_expr_type; \
101 KOKKOS_INLINE_FUNCTION \
102 explicit OP(const T& expr_) : expr(expr_) {} \
104 KOKKOS_INLINE_FUNCTION \
105 std::string name() const { \
106 return std::string(#OPER) + expr.name(); \
109 KOKKOS_INLINE_FUNCTION \
111 return expr.size(); \
114 KOKKOS_INLINE_FUNCTION \
115 bool hasFastAccess(int sz) const { \
116 return expr.hasFastAccess(sz); \
119 KOKKOS_INLINE_FUNCTION \
120 value_type val() const { \
122 return OPER(expr.val()); \
125 KOKKOS_INLINE_FUNCTION \
126 value_type coeff(int i) const { \
128 return OPER(expr.coeff(i)); \
131 KOKKOS_INLINE_FUNCTION \
132 value_type fastAccessCoeff(int i) const { \
134 return OPER(expr.fastAccessCoeff(i)); \
138 KOKKOS_INLINE_FUNCTION \
139 value_type getCoeff() const { \
141 return OPER(expr.template getCoeff<i>()); \
146 typename const_expr_ref<T>::type expr; \
150 template <typename T> \
151 KOKKOS_INLINE_FUNCTION \
153 OPNAME (const Expr<T>& expr) \
155 typedef OP< typename Expr<T>::derived_type > expr_t; \
157 return expr_t(expr.derived()); \
160 template <typename T> \
161 KOKKOS_INLINE_FUNCTION \
163 OPNAME (const volatile Expr<T>& expr) \
165 typedef typename Expr<T>::derived_type derived; \
166 typedef OP< typename add_volatile<derived>::type > expr_t; \
168 return expr_t(expr.derived()); \
171 template <typename T> \
172 KOKKOS_INLINE_FUNCTION \
174 OPNAME (const Vector<T>& vector) \
176 return OP< Vector<T> >(vector); \
180 template <typename T> \
181 struct IsExpr< MP::OP<T> > { \
182 static const bool value = true; \
185 template <typename T> \
186 struct BaseExprType< MP::OP<T> > { \
187 typedef typename MP::OP<T>::base_expr_type type; \
214 #undef MP_UNARYOP_MACRO
216 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \
220 template <typename T1, typename T2> \
222 public Expr< OP< T1, T2> > { \
226 typedef typename remove_volatile<T1>::type Tnv1; \
227 typedef typename remove_volatile<T2>::type Tnv2; \
228 typedef typename Tnv1::value_type value_type_1; \
229 typedef typename Tnv2::value_type value_type_2; \
230 typedef typename Sacado::Promote<value_type_1, \
231 value_type_2>::type value_type; \
233 typedef typename Tnv1::storage_type storage_type; \
234 typedef typename Tnv1::base_expr_type base_expr_type; \
236 KOKKOS_INLINE_FUNCTION \
237 OP(const T1& expr1_, const T2& expr2_) : \
238 expr1(expr1_), expr2(expr2_) {} \
240 KOKKOS_INLINE_FUNCTION \
241 std::string name() const { \
242 return expr1.name() + std::string(#OPER) + expr2.name(); \
245 KOKKOS_INLINE_FUNCTION \
247 int sz1 = expr1.size(), sz2 = expr2.size(); \
248 return sz1 > sz2 ? sz1 : sz2; \
251 KOKKOS_INLINE_FUNCTION \
252 bool hasFastAccess(int sz) const { \
253 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
256 KOKKOS_INLINE_FUNCTION \
257 value_type val() const { \
258 return (expr1.val() OPER expr2.val()); \
261 KOKKOS_INLINE_FUNCTION \
262 value_type coeff(int i) const { \
263 return (expr1.coeff(i) OPER expr2.coeff(i)); \
266 KOKKOS_INLINE_FUNCTION \
267 value_type fastAccessCoeff(int i) const { \
268 return (expr1.fastAccessCoeff(i) OPER expr2.fastAccessCoeff(i)); \
272 KOKKOS_INLINE_FUNCTION \
273 value_type getCoeff() const { \
274 return expr1.template getCoeff<i>() OPER expr2.template getCoeff<i>(); \
279 typename const_expr_ref<T1>::type expr1; \
280 typename const_expr_ref<T2>::type expr2; \
284 template <typename T1> \
285 class OP< T1, typename T1::value_type > : \
286 public Expr< OP< T1, typename T1::value_type > > { \
290 typedef typename remove_volatile<T1>::type Tnv1; \
291 typedef typename Tnv1::value_type value_type; \
292 typedef typename Tnv1::value_type ConstT; \
294 typedef typename Tnv1::storage_type storage_type; \
295 typedef typename Tnv1::base_expr_type base_expr_type; \
297 KOKKOS_INLINE_FUNCTION \
298 OP(const T1& expr1_, const ConstT& c_) : \
299 expr1(expr1_), c(c_) {} \
301 KOKKOS_INLINE_FUNCTION \
302 std::string name() const { \
303 return expr1.name() + std::string(#OPER) + std::string("c"); \
306 KOKKOS_INLINE_FUNCTION \
308 return expr1.size(); \
311 KOKKOS_INLINE_FUNCTION \
312 bool hasFastAccess(int sz) const { \
313 return expr1.hasFastAccess(sz); \
316 KOKKOS_INLINE_FUNCTION \
317 value_type val() const { \
318 return (expr1.val() OPER c); \
321 KOKKOS_INLINE_FUNCTION \
322 value_type coeff(int i) const { \
323 return (expr1.coeff(i) OPER c); \
326 KOKKOS_INLINE_FUNCTION \
327 value_type fastAccessCoeff(int i) const { \
328 return (expr1.fastAccessCoeff(i) OPER c); \
332 KOKKOS_INLINE_FUNCTION \
333 value_type getCoeff() const { \
334 return expr1.template getCoeff<i>() OPER c; \
339 typename const_expr_ref<T1>::type expr1; \
343 template <typename T2> \
344 class OP< typename T2::value_type, T2 > : \
345 public Expr< OP< typename T2::value_type, T2 > > { \
349 typedef typename remove_volatile<T2>::type Tnv2; \
350 typedef typename Tnv2::value_type value_type; \
351 typedef typename Tnv2::value_type ConstT; \
353 typedef typename Tnv2::storage_type storage_type; \
354 typedef typename Tnv2::base_expr_type base_expr_type; \
356 KOKKOS_INLINE_FUNCTION \
357 OP(const ConstT& c_, const T2& expr2_) : \
358 c(c_), expr2(expr2_) {} \
360 KOKKOS_INLINE_FUNCTION \
361 std::string name() const { \
362 return std::string("c") + std::string(#OPER) + expr2.name(); \
365 KOKKOS_INLINE_FUNCTION \
366 int size() const { return expr2.size(); } \
368 KOKKOS_INLINE_FUNCTION \
369 bool hasFastAccess(int sz) const { \
370 return expr2.hasFastAccess(sz); \
373 KOKKOS_INLINE_FUNCTION \
374 value_type val() const { \
375 return (c OPER expr2.val()); \
378 KOKKOS_INLINE_FUNCTION \
379 value_type coeff(int i) const { \
380 return (c OPER expr2.coeff(i)); \
383 KOKKOS_INLINE_FUNCTION \
384 value_type fastAccessCoeff(int i) const { \
385 return (c OPER expr2.fastAccessCoeff(i)); \
389 KOKKOS_INLINE_FUNCTION \
390 value_type getCoeff() const { \
391 return c OPER expr2.template getCoeff<i>(); \
397 typename const_expr_ref<T2>::type expr2; \
400 template <typename T1, typename T2> \
401 KOKKOS_INLINE_FUNCTION \
403 OPNAME (const Expr<T1>& expr1, \
404 const Expr<T2>& expr2) \
406 typedef OP< typename Expr<T1>::derived_type, \
407 typename Expr<T2>::derived_type > expr_t; \
409 return expr_t(expr1.derived(), expr2.derived()); \
412 template <typename T1, typename T2> \
413 KOKKOS_INLINE_FUNCTION \
414 OP< volatile T1, volatile T2 > \
415 OPNAME (const volatile Expr<T1>& expr1, \
416 const volatile Expr<T2>& expr2) \
418 typedef typename Expr<T1>::derived_type derived1; \
419 typedef typename Expr<T2>::derived_type derived2; \
420 typedef OP< typename add_volatile<derived1>::type, \
421 typename add_volatile<derived2>::type > expr_t; \
423 return expr_t(expr1.derived(), expr2.derived()); \
426 template <typename T1, typename T2> \
427 KOKKOS_INLINE_FUNCTION \
428 OP< T1, volatile T2 > \
429 OPNAME (const Expr<T1>& expr1, \
430 const volatile Expr<T2>& expr2) \
432 typedef typename Expr<T1>::derived_type derived1; \
433 typedef typename Expr<T2>::derived_type derived2; \
434 typedef OP< derived1, \
435 typename add_volatile<derived2>::type > expr_t; \
437 return expr_t(expr1.derived(), expr2.derived()); \
440 template <typename T1, typename T2> \
441 KOKKOS_INLINE_FUNCTION \
442 OP< volatile T1, T2 > \
443 OPNAME (const volatile Expr<T1>& expr1, \
444 const Expr<T2>& expr2) \
446 typedef typename Expr<T1>::derived_type derived1; \
447 typedef typename Expr<T2>::derived_type derived2; \
448 typedef OP< typename add_volatile<derived1>::type, \
451 return expr_t(expr1.derived(), expr2.derived()); \
454 template <typename T> \
455 KOKKOS_INLINE_FUNCTION \
456 OP< typename T::value_type, T > \
457 OPNAME (const typename T::value_type& c, \
458 const Expr<T>& expr) \
460 typedef typename T::value_type ConstT; \
461 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
463 return expr_t(c, expr.derived()); \
466 template <typename T> \
467 KOKKOS_INLINE_FUNCTION \
468 OP< typename T::value_type, volatile T > \
469 OPNAME (const typename T::value_type& c, \
470 const volatile Expr<T>& expr) \
472 typedef typename T::value_type ConstT; \
473 typedef typename Expr<T>::derived_type derived; \
474 typedef OP< ConstT, \
475 typename add_volatile<derived>::type > expr_t; \
477 return expr_t(c, expr.derived()); \
480 template <typename T> \
481 KOKKOS_INLINE_FUNCTION \
482 OP< T, typename T::value_type > \
483 OPNAME (const Expr<T>& expr, \
484 const typename T::value_type& c) \
486 typedef typename T::value_type ConstT; \
487 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
489 return expr_t(expr.derived(), c); \
492 template <typename T> \
493 KOKKOS_INLINE_FUNCTION \
494 OP< volatile T, typename T::value_type > \
495 OPNAME (const volatile Expr<T>& expr, \
496 const typename T::value_type& c) \
498 typedef typename T::value_type ConstT; \
499 typedef typename Expr<T>::derived_type derived; \
500 typedef OP< typename add_volatile<derived>::type, \
503 return expr_t(expr.derived(), c); \
506 template <typename T> \
507 KOKKOS_INLINE_FUNCTION \
508 OP< Vector<T>, Vector<T> > \
509 OPNAME (const Vector<T>& vector1, \
510 const Vector<T>& vector2) \
512 return {vector1, vector2}; \
516 template <typename T1, typename T2> \
517 struct IsExpr< MP::OP<T1,T2> > { \
518 static const bool value = true; \
521 template <typename T1, typename T2> \
522 struct BaseExprType< MP::OP<T1,T2> > { \
523 typedef typename MP::OP<T1,T2>::base_expr_type type; \
532 #undef MP_BINARYOP_MACRO
534 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER,USING_OP) \
538 template <typename T1, typename T2> \
540 public Expr< OP< T1, T2 > > { \
544 typedef typename T1::value_type value_type_1; \
545 typedef typename T2::value_type value_type_2; \
546 typedef typename Sacado::Promote<value_type_1, \
547 value_type_2>::type value_type; \
549 typedef typename T1::storage_type storage_type; \
550 typedef typename T1::base_expr_type base_expr_type; \
553 KOKKOS_INLINE_FUNCTION \
554 OP(const T1& expr1_, const T2& expr2_) : \
555 expr1(expr1_), expr2(expr2_) {} \
557 KOKKOS_INLINE_FUNCTION \
558 std::string name() const { \
559 return expr1.name() + std::string(#OPER) + expr2.name(); \
562 KOKKOS_INLINE_FUNCTION \
564 int sz1 = expr1.size(), sz2 = expr2.size(); \
565 return sz1 > sz2 ? sz1 : sz2; \
568 KOKKOS_INLINE_FUNCTION \
569 bool hasFastAccess(int sz) const { \
570 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
573 KOKKOS_INLINE_FUNCTION \
574 value_type val() const { \
576 return OPER(expr1.val(), expr2.val()); \
579 KOKKOS_INLINE_FUNCTION \
580 value_type coeff(int i) const { \
582 return OPER(expr1.coeff(i), expr2.coeff(i)); \
585 KOKKOS_INLINE_FUNCTION \
586 value_type fastAccessCoeff(int i) const { \
588 return OPER(expr1.fastAccessCoeff(i), expr2.fastAccessCoeff(i)); \
592 KOKKOS_INLINE_FUNCTION \
593 value_type getCoeff() const { \
595 return OPER(expr1.template getCoeff<i>(), \
596 expr2.template getCoeff<i>()); \
601 typename const_expr_ref<T1>::type expr1; \
602 typename const_expr_ref<T2>::type expr2; \
606 template <typename T1> \
607 class OP< T1, typename T1::value_type > : \
608 public Expr< OP< T1, typename T1::value_type > > { \
612 typedef typename T1::value_type value_type; \
613 typedef typename T1::value_type ConstT; \
615 typedef typename T1::storage_type storage_type; \
616 typedef typename T1::base_expr_type base_expr_type; \
618 KOKKOS_INLINE_FUNCTION \
619 OP(const T1& expr1_, const ConstT& c_) : \
620 expr1(expr1_), c(c_) {} \
622 KOKKOS_INLINE_FUNCTION \
623 std::string name() const { \
624 return expr1.name() + std::string(#OPER) + std::string("c"); \
627 KOKKOS_INLINE_FUNCTION \
628 int size() const { return expr1.size(); } \
630 KOKKOS_INLINE_FUNCTION \
631 bool hasFastAccess(int sz) const { \
632 return expr1.hasFastAccess(sz); \
635 KOKKOS_INLINE_FUNCTION \
636 value_type val() const { \
638 return OPER(expr1.val(), c); \
641 KOKKOS_INLINE_FUNCTION \
642 value_type coeff(int i) const { \
644 return OPER(expr1.coeff(i), c); \
647 KOKKOS_INLINE_FUNCTION \
648 value_type fastAccessCoeff(int i) const { \
650 return OPER(expr1.fastAccessCoeff(i), c); \
654 KOKKOS_INLINE_FUNCTION \
655 value_type getCoeff() const { \
657 return OPER(expr1.template getCoeff<i>(), c); \
662 typename const_expr_ref<T1>::type expr1; \
666 template <typename T2> \
667 class OP< typename T2::value_type, T2 > : \
668 public Expr< OP< typename T2::value_type, T2 > > { \
672 typedef typename T2::value_type value_type; \
673 typedef typename T2::value_type ConstT; \
675 typedef typename T2::storage_type storage_type; \
676 typedef typename T2::base_expr_type base_expr_type; \
678 KOKKOS_INLINE_FUNCTION \
679 OP(const ConstT& c_, const T2& expr2_) : \
680 c(c_), expr2(expr2_) {} \
682 KOKKOS_INLINE_FUNCTION \
683 std::string name() const { \
684 return std::string("c") + std::string(#OPER) + expr2.name(); \
687 KOKKOS_INLINE_FUNCTION \
688 int size() const { return expr2.size(); } \
690 KOKKOS_INLINE_FUNCTION \
691 bool hasFastAccess(int sz) const { \
692 return expr2.hasFastAccess(sz); \
695 KOKKOS_INLINE_FUNCTION \
696 value_type val() const { \
698 return OPER(c, expr2.val()); \
701 KOKKOS_INLINE_FUNCTION \
702 value_type coeff(int i) const { \
704 return OPER(c, expr2.coeff(i)); \
707 KOKKOS_INLINE_FUNCTION \
708 value_type fastAccessCoeff(int i) const { \
710 return OPER(c, expr2.fastAccessCoeff(i)); \
714 KOKKOS_INLINE_FUNCTION \
715 value_type getCoeff() const { \
717 return OPER(c, expr2.template getCoeff<i>()); \
723 typename const_expr_ref<T2>::type expr2; \
726 template <typename T1, typename T2> \
727 KOKKOS_INLINE_FUNCTION \
729 OPNAME (const Expr<T1>& expr1, \
730 const Expr<T2>& expr2) \
732 typedef OP< typename Expr<T1>::derived_type, \
733 typename Expr<T2>::derived_type > expr_t; \
735 return expr_t(expr1.derived(), expr2.derived()); \
738 template <typename T> \
739 KOKKOS_INLINE_FUNCTION \
740 OP< typename T::value_type, T > \
741 OPNAME (const typename T::value_type& c, \
742 const Expr<T>& expr) \
744 typedef typename T::value_type ConstT; \
745 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
747 return expr_t(c, expr.derived()); \
750 template <typename T> \
751 KOKKOS_INLINE_FUNCTION \
752 OP< T, typename T::value_type > \
753 OPNAME (const Expr<T>& expr, \
754 const typename T::value_type& c) \
756 typedef typename T::value_type ConstT; \
757 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
759 return expr_t(expr.derived(), c); \
762 template <typename T> \
763 KOKKOS_INLINE_FUNCTION \
764 OP< Vector<T>, Vector<T> > \
765 OPNAME (const Vector<T>& vector1, \
766 const Vector<T>& vector2) \
768 return {vector1, vector2}; \
772 template <typename T1, typename T2> \
773 struct IsExpr< MP::OP<T1,T2> > { \
774 static const bool value = true; \
777 template <typename T1, typename T2> \
778 struct BaseExprType< MP::OP<T1,T2> > { \
779 typedef typename MP::OP<T1,T2>::base_expr_type type; \
801 template <
typename T>
802 KOKKOS_INLINE_FUNCTION
805 return ! expr.derived().val();
818 template <
typename T>
819 KOKKOS_INLINE_FUNCTION
824 for (
int i=0; i<x.size(); i++)
825 is_zero = is_zero && (x.coeff(i) == 0.0);
833 #define PCE_BOOL_MACRO(OP) \
837 template <typename T1, typename T2> \
838 KOKKOS_INLINE_FUNCTION \
840 operator OP (const Expr<T1>& expr1, \
841 const Expr<T2>& expr2) \
843 return toBool(expr1) OP toBool(expr2); \
846 template <typename T2> \
847 KOKKOS_INLINE_FUNCTION \
849 operator OP (const typename T2::value_type& a, \
850 const Expr<T2>& expr2) \
852 return a OP toBool(expr2); \
855 template <typename T1> \
856 KOKKOS_INLINE_FUNCTION \
858 operator OP (const Expr<T1>& expr1, \
859 const typename T1::value_type& b) \
861 return toBool(expr1) OP b; \
869 #undef PCE_BOOL_MACRO
878 template <
typename T>
893 template <
typename T>
897 for (
int i=0; i<x.size(); i++)
898 if (!isfinite(x.coeff(i)))
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > fabs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 MultiplicationOp
#define MP_BINARYOP_MACRO(OPNAME, OP, OPER)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 j expr1 expr1 expr1 expr1 j expr1 c *expr2 expr1 c expr1 c expr1 c expr1 DivisionOp
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
atan2(expr1.val(), expr2.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< T > &expr)
expr2 j expr1 expr1 expr2 expr2 j expr1 c c c c MaxOp
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 j expr1 expr1 expr1 expr1 j expr1 c *expr2 expr1 c expr1 c expr1 c expr1 expr1 expr1 expr1 j *expr1 expr2 expr1 expr1 j *expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 Atan2Op
KOKKOS_INLINE_FUNCTION PCE< Storage > ceil(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
expr2 j expr1 expr1 expr2 expr2 j expr1 c c c c MinOp
std::ostream & operator<<(std::ostream &os, const Expr< T > &x)
expr expr expr expr ExpOp
#define MP_UNARYOP_MACRO(OPNAME, OP, OPER, USING_OP)
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)
#define PCE_BOOL_MACRO(OP)