42#include "Sacado_cmath.hpp"
46 #include <cuda_runtime_api.h>
49 #if CUDART_VERSION < 10000
50 #include <math_functions.h>
118#define MP_UNARYOP_MACRO(OPNAME,OP,OPER,USING_OP) \
123 template <typename T> \
125 public Expr< OP< T > > { \
128 typedef typename remove_volatile<T>::type Tnv; \
129 typedef typename Tnv::value_type value_type; \
130 typedef typename Tnv::storage_type storage_type; \
131 typedef typename Tnv::base_expr_type base_expr_type; \
133 KOKKOS_INLINE_FUNCTION \
134 explicit OP(const T& expr_) : expr(expr_) {} \
136 KOKKOS_INLINE_FUNCTION \
137 std::string name() const { \
138 return std::string(#OPER) + expr.name(); \
141 KOKKOS_INLINE_FUNCTION \
143 return expr.size(); \
146 KOKKOS_INLINE_FUNCTION \
147 bool hasFastAccess(int sz) const { \
148 return expr.hasFastAccess(sz); \
151 KOKKOS_INLINE_FUNCTION \
152 value_type val() const { \
154 return OPER(expr.val()); \
157 KOKKOS_INLINE_FUNCTION \
158 value_type coeff(int i) const { \
160 return OPER(expr.coeff(i)); \
163 KOKKOS_INLINE_FUNCTION \
164 value_type fastAccessCoeff(int i) const { \
166 return OPER(expr.fastAccessCoeff(i)); \
170 KOKKOS_INLINE_FUNCTION \
171 value_type getCoeff() const { \
173 return OPER(expr.template getCoeff<i>()); \
178 typename const_expr_ref<T>::type expr; \
182 template <typename T> \
183 KOKKOS_INLINE_FUNCTION \
185 OPNAME (const Expr<T>& expr) \
187 typedef OP< typename Expr<T>::derived_type > expr_t; \
189 return expr_t(expr.derived()); \
192 template <typename T> \
193 KOKKOS_INLINE_FUNCTION \
195 OPNAME (const volatile Expr<T>& expr) \
197 typedef typename Expr<T>::derived_type derived; \
198 typedef OP< typename add_volatile<derived>::type > expr_t; \
200 return expr_t(expr.derived()); \
203 template <typename T> \
204 KOKKOS_INLINE_FUNCTION \
206 OPNAME (const Vector<T>& vector) \
208 return OP< Vector<T> >(vector); \
212 template <typename T> \
213 struct IsExpr< MP::OP<T> > { \
214 static const bool value = true; \
217 template <typename T> \
218 struct BaseExprType< MP::OP<T> > { \
219 typedef typename MP::OP<T>::base_expr_type type; \
246#undef MP_UNARYOP_MACRO
248#define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \
252 template <typename T1, typename T2> \
254 public Expr< OP< T1, T2> > { \
258 typedef typename remove_volatile<T1>::type Tnv1; \
259 typedef typename remove_volatile<T2>::type Tnv2; \
260 typedef typename Tnv1::value_type value_type_1; \
261 typedef typename Tnv2::value_type value_type_2; \
262 typedef typename Sacado::Promote<value_type_1, \
263 value_type_2>::type value_type; \
265 typedef typename Tnv1::storage_type storage_type; \
266 typedef typename Tnv1::base_expr_type base_expr_type; \
268 KOKKOS_INLINE_FUNCTION \
269 OP(const T1& expr1_, const T2& expr2_) : \
270 expr1(expr1_), expr2(expr2_) {} \
272 KOKKOS_INLINE_FUNCTION \
273 std::string name() const { \
274 return expr1.name() + std::string(#OPER) + expr2.name(); \
277 KOKKOS_INLINE_FUNCTION \
279 int sz1 = expr1.size(), sz2 = expr2.size(); \
280 return sz1 > sz2 ? sz1 : sz2; \
283 KOKKOS_INLINE_FUNCTION \
284 bool hasFastAccess(int sz) const { \
285 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
288 KOKKOS_INLINE_FUNCTION \
289 value_type val() const { \
290 return (expr1.val() OPER expr2.val()); \
293 KOKKOS_INLINE_FUNCTION \
294 value_type coeff(int i) const { \
295 return (expr1.coeff(i) OPER expr2.coeff(i)); \
298 KOKKOS_INLINE_FUNCTION \
299 value_type fastAccessCoeff(int i) const { \
300 return (expr1.fastAccessCoeff(i) OPER expr2.fastAccessCoeff(i)); \
304 KOKKOS_INLINE_FUNCTION \
305 value_type getCoeff() const { \
306 return expr1.template getCoeff<i>() OPER expr2.template getCoeff<i>(); \
311 typename const_expr_ref<T1>::type expr1; \
312 typename const_expr_ref<T2>::type expr2; \
316 template <typename T1> \
317 class OP< T1, typename T1::value_type > : \
318 public Expr< OP< T1, typename T1::value_type > > { \
322 typedef typename remove_volatile<T1>::type Tnv1; \
323 typedef typename Tnv1::value_type value_type; \
324 typedef typename Tnv1::value_type ConstT; \
326 typedef typename Tnv1::storage_type storage_type; \
327 typedef typename Tnv1::base_expr_type base_expr_type; \
329 KOKKOS_INLINE_FUNCTION \
330 OP(const T1& expr1_, const ConstT& c_) : \
331 expr1(expr1_), c(c_) {} \
333 KOKKOS_INLINE_FUNCTION \
334 std::string name() const { \
335 return expr1.name() + std::string(#OPER) + std::string("c"); \
338 KOKKOS_INLINE_FUNCTION \
340 return expr1.size(); \
343 KOKKOS_INLINE_FUNCTION \
344 bool hasFastAccess(int sz) const { \
345 return expr1.hasFastAccess(sz); \
348 KOKKOS_INLINE_FUNCTION \
349 value_type val() const { \
350 return (expr1.val() OPER c); \
353 KOKKOS_INLINE_FUNCTION \
354 value_type coeff(int i) const { \
355 return (expr1.coeff(i) OPER c); \
358 KOKKOS_INLINE_FUNCTION \
359 value_type fastAccessCoeff(int i) const { \
360 return (expr1.fastAccessCoeff(i) OPER c); \
364 KOKKOS_INLINE_FUNCTION \
365 value_type getCoeff() const { \
366 return expr1.template getCoeff<i>() OPER c; \
371 typename const_expr_ref<T1>::type expr1; \
375 template <typename T2> \
376 class OP< typename T2::value_type, T2 > : \
377 public Expr< OP< typename T2::value_type, T2 > > { \
381 typedef typename remove_volatile<T2>::type Tnv2; \
382 typedef typename Tnv2::value_type value_type; \
383 typedef typename Tnv2::value_type ConstT; \
385 typedef typename Tnv2::storage_type storage_type; \
386 typedef typename Tnv2::base_expr_type base_expr_type; \
388 KOKKOS_INLINE_FUNCTION \
389 OP(const ConstT& c_, const T2& expr2_) : \
390 c(c_), expr2(expr2_) {} \
392 KOKKOS_INLINE_FUNCTION \
393 std::string name() const { \
394 return std::string("c") + std::string(#OPER) + expr2.name(); \
397 KOKKOS_INLINE_FUNCTION \
398 int size() const { return expr2.size(); } \
400 KOKKOS_INLINE_FUNCTION \
401 bool hasFastAccess(int sz) const { \
402 return expr2.hasFastAccess(sz); \
405 KOKKOS_INLINE_FUNCTION \
406 value_type val() const { \
407 return (c OPER expr2.val()); \
410 KOKKOS_INLINE_FUNCTION \
411 value_type coeff(int i) const { \
412 return (c OPER expr2.coeff(i)); \
415 KOKKOS_INLINE_FUNCTION \
416 value_type fastAccessCoeff(int i) const { \
417 return (c OPER expr2.fastAccessCoeff(i)); \
421 KOKKOS_INLINE_FUNCTION \
422 value_type getCoeff() const { \
423 return c OPER expr2.template getCoeff<i>(); \
429 typename const_expr_ref<T2>::type expr2; \
432 template <typename T1, typename T2> \
433 KOKKOS_INLINE_FUNCTION \
435 OPNAME (const Expr<T1>& expr1, \
436 const Expr<T2>& expr2) \
438 typedef OP< typename Expr<T1>::derived_type, \
439 typename Expr<T2>::derived_type > expr_t; \
441 return expr_t(expr1.derived(), expr2.derived()); \
444 template <typename T1, typename T2> \
445 KOKKOS_INLINE_FUNCTION \
446 OP< volatile T1, volatile T2 > \
447 OPNAME (const volatile Expr<T1>& expr1, \
448 const volatile Expr<T2>& expr2) \
450 typedef typename Expr<T1>::derived_type derived1; \
451 typedef typename Expr<T2>::derived_type derived2; \
452 typedef OP< typename add_volatile<derived1>::type, \
453 typename add_volatile<derived2>::type > expr_t; \
455 return expr_t(expr1.derived(), expr2.derived()); \
458 template <typename T1, typename T2> \
459 KOKKOS_INLINE_FUNCTION \
460 OP< T1, volatile T2 > \
461 OPNAME (const Expr<T1>& expr1, \
462 const volatile Expr<T2>& expr2) \
464 typedef typename Expr<T1>::derived_type derived1; \
465 typedef typename Expr<T2>::derived_type derived2; \
466 typedef OP< derived1, \
467 typename add_volatile<derived2>::type > expr_t; \
469 return expr_t(expr1.derived(), expr2.derived()); \
472 template <typename T1, typename T2> \
473 KOKKOS_INLINE_FUNCTION \
474 OP< volatile T1, T2 > \
475 OPNAME (const volatile Expr<T1>& expr1, \
476 const Expr<T2>& expr2) \
478 typedef typename Expr<T1>::derived_type derived1; \
479 typedef typename Expr<T2>::derived_type derived2; \
480 typedef OP< typename add_volatile<derived1>::type, \
483 return expr_t(expr1.derived(), expr2.derived()); \
486 template <typename T> \
487 KOKKOS_INLINE_FUNCTION \
488 OP< typename T::value_type, T > \
489 OPNAME (const typename T::value_type& c, \
490 const Expr<T>& expr) \
492 typedef typename T::value_type ConstT; \
493 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
495 return expr_t(c, expr.derived()); \
498 template <typename T> \
499 KOKKOS_INLINE_FUNCTION \
500 OP< typename T::value_type, volatile T > \
501 OPNAME (const typename T::value_type& c, \
502 const volatile Expr<T>& expr) \
504 typedef typename T::value_type ConstT; \
505 typedef typename Expr<T>::derived_type derived; \
506 typedef OP< ConstT, \
507 typename add_volatile<derived>::type > expr_t; \
509 return expr_t(c, expr.derived()); \
512 template <typename T> \
513 KOKKOS_INLINE_FUNCTION \
514 OP< T, typename T::value_type > \
515 OPNAME (const Expr<T>& expr, \
516 const typename T::value_type& c) \
518 typedef typename T::value_type ConstT; \
519 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
521 return expr_t(expr.derived(), c); \
524 template <typename T> \
525 KOKKOS_INLINE_FUNCTION \
526 OP< volatile T, typename T::value_type > \
527 OPNAME (const volatile Expr<T>& expr, \
528 const typename T::value_type& c) \
530 typedef typename T::value_type ConstT; \
531 typedef typename Expr<T>::derived_type derived; \
532 typedef OP< typename add_volatile<derived>::type, \
535 return expr_t(expr.derived(), c); \
538 template <typename T> \
539 KOKKOS_INLINE_FUNCTION \
540 OP< Vector<T>, Vector<T> > \
541 OPNAME (const Vector<T>& vector1, \
542 const Vector<T>& vector2) \
544 return {vector1, vector2}; \
548 template <typename T1, typename T2> \
549 struct IsExpr< MP::OP<T1,T2> > { \
550 static const bool value = true; \
553 template <typename T1, typename T2> \
554 struct BaseExprType< MP::OP<T1,T2> > { \
555 typedef typename MP::OP<T1,T2>::base_expr_type type; \
564#undef MP_BINARYOP_MACRO
566#define MP_BINARYOP_MACRO(OPNAME,OP,OPER,USING_OP) \
570 template <typename T1, typename T2> \
572 public Expr< OP< T1, T2 > > { \
576 typedef typename T1::value_type value_type_1; \
577 typedef typename T2::value_type value_type_2; \
578 typedef typename Sacado::Promote<value_type_1, \
579 value_type_2>::type value_type; \
581 typedef typename T1::storage_type storage_type; \
582 typedef typename T1::base_expr_type base_expr_type; \
585 KOKKOS_INLINE_FUNCTION \
586 OP(const T1& expr1_, const T2& expr2_) : \
587 expr1(expr1_), expr2(expr2_) {} \
589 KOKKOS_INLINE_FUNCTION \
590 std::string name() const { \
591 return expr1.name() + std::string(#OPER) + expr2.name(); \
594 KOKKOS_INLINE_FUNCTION \
596 int sz1 = expr1.size(), sz2 = expr2.size(); \
597 return sz1 > sz2 ? sz1 : sz2; \
600 KOKKOS_INLINE_FUNCTION \
601 bool hasFastAccess(int sz) const { \
602 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
605 KOKKOS_INLINE_FUNCTION \
606 value_type val() const { \
608 return OPER(expr1.val(), expr2.val()); \
611 KOKKOS_INLINE_FUNCTION \
612 value_type coeff(int i) const { \
614 return OPER(expr1.coeff(i), expr2.coeff(i)); \
617 KOKKOS_INLINE_FUNCTION \
618 value_type fastAccessCoeff(int i) const { \
620 return OPER(expr1.fastAccessCoeff(i), expr2.fastAccessCoeff(i)); \
624 KOKKOS_INLINE_FUNCTION \
625 value_type getCoeff() const { \
627 return OPER(expr1.template getCoeff<i>(), \
628 expr2.template getCoeff<i>()); \
633 typename const_expr_ref<T1>::type expr1; \
634 typename const_expr_ref<T2>::type expr2; \
638 template <typename T1> \
639 class OP< T1, typename T1::value_type > : \
640 public Expr< OP< T1, typename T1::value_type > > { \
644 typedef typename T1::value_type value_type; \
645 typedef typename T1::value_type ConstT; \
647 typedef typename T1::storage_type storage_type; \
648 typedef typename T1::base_expr_type base_expr_type; \
650 KOKKOS_INLINE_FUNCTION \
651 OP(const T1& expr1_, const ConstT& c_) : \
652 expr1(expr1_), c(c_) {} \
654 KOKKOS_INLINE_FUNCTION \
655 std::string name() const { \
656 return expr1.name() + std::string(#OPER) + std::string("c"); \
659 KOKKOS_INLINE_FUNCTION \
660 int size() const { return expr1.size(); } \
662 KOKKOS_INLINE_FUNCTION \
663 bool hasFastAccess(int sz) const { \
664 return expr1.hasFastAccess(sz); \
667 KOKKOS_INLINE_FUNCTION \
668 value_type val() const { \
670 return OPER(expr1.val(), c); \
673 KOKKOS_INLINE_FUNCTION \
674 value_type coeff(int i) const { \
676 return OPER(expr1.coeff(i), c); \
679 KOKKOS_INLINE_FUNCTION \
680 value_type fastAccessCoeff(int i) const { \
682 return OPER(expr1.fastAccessCoeff(i), c); \
686 KOKKOS_INLINE_FUNCTION \
687 value_type getCoeff() const { \
689 return OPER(expr1.template getCoeff<i>(), c); \
694 typename const_expr_ref<T1>::type expr1; \
698 template <typename T2> \
699 class OP< typename T2::value_type, T2 > : \
700 public Expr< OP< typename T2::value_type, T2 > > { \
704 typedef typename T2::value_type value_type; \
705 typedef typename T2::value_type ConstT; \
707 typedef typename T2::storage_type storage_type; \
708 typedef typename T2::base_expr_type base_expr_type; \
710 KOKKOS_INLINE_FUNCTION \
711 OP(const ConstT& c_, const T2& expr2_) : \
712 c(c_), expr2(expr2_) {} \
714 KOKKOS_INLINE_FUNCTION \
715 std::string name() const { \
716 return std::string("c") + std::string(#OPER) + expr2.name(); \
719 KOKKOS_INLINE_FUNCTION \
720 int size() const { return expr2.size(); } \
722 KOKKOS_INLINE_FUNCTION \
723 bool hasFastAccess(int sz) const { \
724 return expr2.hasFastAccess(sz); \
727 KOKKOS_INLINE_FUNCTION \
728 value_type val() const { \
730 return OPER(c, expr2.val()); \
733 KOKKOS_INLINE_FUNCTION \
734 value_type coeff(int i) const { \
736 return OPER(c, expr2.coeff(i)); \
739 KOKKOS_INLINE_FUNCTION \
740 value_type fastAccessCoeff(int i) const { \
742 return OPER(c, expr2.fastAccessCoeff(i)); \
746 KOKKOS_INLINE_FUNCTION \
747 value_type getCoeff() const { \
749 return OPER(c, expr2.template getCoeff<i>()); \
755 typename const_expr_ref<T2>::type expr2; \
758 template <typename T1, typename T2> \
759 KOKKOS_INLINE_FUNCTION \
761 OPNAME (const Expr<T1>& expr1, \
762 const Expr<T2>& expr2) \
764 typedef OP< typename Expr<T1>::derived_type, \
765 typename Expr<T2>::derived_type > expr_t; \
767 return expr_t(expr1.derived(), expr2.derived()); \
770 template <typename T> \
771 KOKKOS_INLINE_FUNCTION \
772 OP< typename T::value_type, T > \
773 OPNAME (const typename T::value_type& c, \
774 const Expr<T>& expr) \
776 typedef typename T::value_type ConstT; \
777 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
779 return expr_t(c, expr.derived()); \
782 template <typename T> \
783 KOKKOS_INLINE_FUNCTION \
784 OP< T, typename T::value_type > \
785 OPNAME (const Expr<T>& expr, \
786 const typename T::value_type& c) \
788 typedef typename T::value_type ConstT; \
789 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
791 return expr_t(expr.derived(), c); \
794 template <typename T> \
795 KOKKOS_INLINE_FUNCTION \
796 OP< Vector<T>, Vector<T> > \
797 OPNAME (const Vector<T>& vector1, \
798 const Vector<T>& vector2) \
800 return {vector1, vector2}; \
804 template <typename T1, typename T2> \
805 struct IsExpr< MP::OP<T1,T2> > { \
806 static const bool value = true; \
809 template <typename T1, typename T2> \
810 struct BaseExprType< MP::OP<T1,T2> > { \
811 typedef typename MP::OP<T1,T2>::base_expr_type type; \
831 template <
typename T>
832 KOKKOS_INLINE_FUNCTION
833 bool operator ! (
const Expr<T>& expr)
835 return ! expr.derived().val();
848 template <
typename T>
849 KOKKOS_INLINE_FUNCTION
854 for (
int i=0; i<x.size(); i++)
855 is_zero = is_zero && (x.coeff(i) == 0.0);
863#define PCE_BOOL_MACRO(OP) \
867 template <typename T1, typename T2> \
868 KOKKOS_INLINE_FUNCTION \
870 operator OP (const Expr<T1>& expr1, \
871 const Expr<T2>& expr2) \
873 return toBool(expr1) OP toBool(expr2); \
876 template <typename T2> \
877 KOKKOS_INLINE_FUNCTION \
879 operator OP (const typename T2::value_type& a, \
880 const Expr<T2>& expr2) \
882 return a OP toBool(expr2); \
885 template <typename T1> \
886 KOKKOS_INLINE_FUNCTION \
888 operator OP (const Expr<T1>& expr1, \
889 const typename T1::value_type& b) \
891 return toBool(expr1) OP b; \
908 template <
typename T>
912 Vector<storage_type> a(x);
923 template <
typename T>
927 for (
int i=0; i<x.size(); i++)
expr2 j expr1 expr1 expr2 expr2 j expr1 c c c c MinOp
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 MultiplicationOp
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
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
expr expr expr expr ExpOp
expr2 j expr1 expr1 expr2 expr2 j expr1 c c c c MaxOp
#define MP_UNARYOP_MACRO(OPNAME, OP, OPER, USING_OP)
#define MP_BINARYOP_MACRO(OPNAME, OP, OPER)
#define PCE_BOOL_MACRO(OP)
Stokhos::StandardStorage< int, double > storage_type
std::ostream & operator<<(std::ostream &os, const Expr< T > &x)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
bool isfinite(const Sacado::MP::Expr< T > &xx)