42 #include "Sacado_cmath.hpp" 46 #include <math_functions.h> 113 #define MP_UNARYOP_MACRO(OPNAME,OP,OPER) \ 118 template <typename T> \ 120 public Expr< OP< T > > { \ 123 typedef typename remove_volatile<T>::type Tnv; \ 124 typedef typename Tnv::value_type value_type; \ 125 typedef typename Tnv::storage_type storage_type; \ 126 typedef typename Tnv::base_expr_type base_expr_type; \ 128 KOKKOS_INLINE_FUNCTION \ 129 explicit OP(const T& expr_) : expr(expr_) {} \ 131 KOKKOS_INLINE_FUNCTION \ 132 std::string name() const { \ 133 return std::string(#OPER) + expr.name(); \ 136 KOKKOS_INLINE_FUNCTION \ 138 return expr.size(); \ 141 KOKKOS_INLINE_FUNCTION \ 142 bool hasFastAccess(int sz) const { \ 143 return expr.hasFastAccess(sz); \ 146 KOKKOS_INLINE_FUNCTION \ 147 value_type val() const { \ 148 return OPER(expr.val()); \ 151 KOKKOS_INLINE_FUNCTION \ 152 value_type coeff(int i) const { \ 153 return OPER(expr.coeff(i)); \ 156 KOKKOS_INLINE_FUNCTION \ 157 value_type fastAccessCoeff(int i) const { \ 158 return OPER(expr.fastAccessCoeff(i)); \ 162 KOKKOS_INLINE_FUNCTION \ 163 value_type getCoeff() const { \ 164 return OPER(expr.template getCoeff<i>()); \ 169 typename const_expr_ref<T>::type expr; \ 173 template <typename T> \ 174 KOKKOS_INLINE_FUNCTION \ 176 OPNAME (const Expr<T>& expr) \ 178 typedef OP< typename Expr<T>::derived_type > expr_t; \ 180 return expr_t(expr.derived()); \ 183 template <typename T> \ 184 KOKKOS_INLINE_FUNCTION \ 186 OPNAME (const volatile Expr<T>& expr) \ 188 typedef typename Expr<T>::derived_type derived; \ 189 typedef OP< typename add_volatile<derived>::type > expr_t; \ 191 return expr_t(expr.derived()); \ 195 template <typename T> \ 196 struct IsExpr< MP::OP<T> > { \ 197 static const bool value = true; \ 200 template <typename T> \ 201 struct BaseExprType< MP::OP<T> > { \ 202 typedef typename MP::OP<T>::base_expr_type type; \ 229 #undef MP_UNARYOP_MACRO 231 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \ 235 template <typename T1, typename T2> \ 237 public Expr< OP< T1, T2> > { \ 241 typedef typename remove_volatile<T1>::type Tnv1; \ 242 typedef typename remove_volatile<T2>::type Tnv2; \ 243 typedef typename Tnv1::value_type value_type_1; \ 244 typedef typename Tnv2::value_type value_type_2; \ 245 typedef typename Sacado::Promote<value_type_1, \ 246 value_type_2>::type value_type; \ 248 typedef typename Tnv1::storage_type storage_type; \ 249 typedef typename Tnv1::base_expr_type base_expr_type; \ 251 KOKKOS_INLINE_FUNCTION \ 252 OP(const T1& expr1_, const T2& expr2_) : \ 253 expr1(expr1_), expr2(expr2_) {} \ 255 KOKKOS_INLINE_FUNCTION \ 256 std::string name() const { \ 257 return expr1.name() + std::string(#OPER) + expr2.name(); \ 260 KOKKOS_INLINE_FUNCTION \ 262 int sz1 = expr1.size(), sz2 = expr2.size(); \ 263 return sz1 > sz2 ? sz1 : sz2; \ 266 KOKKOS_INLINE_FUNCTION \ 267 bool hasFastAccess(int sz) const { \ 268 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \ 271 KOKKOS_INLINE_FUNCTION \ 272 value_type val() const { \ 273 return (expr1.val() OPER expr2.val()); \ 276 KOKKOS_INLINE_FUNCTION \ 277 value_type coeff(int i) const { \ 278 return (expr1.coeff(i) OPER expr2.coeff(i)); \ 281 KOKKOS_INLINE_FUNCTION \ 282 value_type fastAccessCoeff(int i) const { \ 283 return (expr1.fastAccessCoeff(i) OPER expr2.fastAccessCoeff(i)); \ 287 KOKKOS_INLINE_FUNCTION \ 288 value_type getCoeff() const { \ 289 return expr1.template getCoeff<i>() OPER expr2.template getCoeff<i>(); \ 294 typename const_expr_ref<T1>::type expr1; \ 295 typename const_expr_ref<T2>::type expr2; \ 299 template <typename T1> \ 300 class OP< T1, typename T1::value_type > : \ 301 public Expr< OP< T1, typename T1::value_type > > { \ 305 typedef typename remove_volatile<T1>::type Tnv1; \ 306 typedef typename Tnv1::value_type value_type; \ 307 typedef typename Tnv1::value_type ConstT; \ 309 typedef typename Tnv1::storage_type storage_type; \ 310 typedef typename Tnv1::base_expr_type base_expr_type; \ 312 KOKKOS_INLINE_FUNCTION \ 313 OP(const T1& expr1_, const ConstT& c_) : \ 314 expr1(expr1_), c(c_) {} \ 316 KOKKOS_INLINE_FUNCTION \ 317 std::string name() const { \ 318 return expr1.name() + std::string(#OPER) + std::string("c"); \ 321 KOKKOS_INLINE_FUNCTION \ 323 return expr1.size(); \ 326 KOKKOS_INLINE_FUNCTION \ 327 bool hasFastAccess(int sz) const { \ 328 return expr1.hasFastAccess(sz); \ 331 KOKKOS_INLINE_FUNCTION \ 332 value_type val() const { \ 333 return (expr1.val() OPER c); \ 336 KOKKOS_INLINE_FUNCTION \ 337 value_type coeff(int i) const { \ 338 return (expr1.coeff(i) OPER c); \ 341 KOKKOS_INLINE_FUNCTION \ 342 value_type fastAccessCoeff(int i) const { \ 343 return (expr1.fastAccessCoeff(i) OPER c); \ 347 KOKKOS_INLINE_FUNCTION \ 348 value_type getCoeff() const { \ 349 return expr1.template getCoeff<i>() OPER c; \ 354 typename const_expr_ref<T1>::type expr1; \ 358 template <typename T2> \ 359 class OP< typename T2::value_type, T2 > : \ 360 public Expr< OP< typename T2::value_type, T2 > > { \ 364 typedef typename remove_volatile<T2>::type Tnv2; \ 365 typedef typename Tnv2::value_type value_type; \ 366 typedef typename Tnv2::value_type ConstT; \ 368 typedef typename Tnv2::storage_type storage_type; \ 369 typedef typename Tnv2::base_expr_type base_expr_type; \ 371 KOKKOS_INLINE_FUNCTION \ 372 OP(const ConstT& c_, const T2& expr2_) : \ 373 c(c_), expr2(expr2_) {} \ 375 KOKKOS_INLINE_FUNCTION \ 376 std::string name() const { \ 377 return std::string("c") + std::string(#OPER) + expr2.name(); \ 380 KOKKOS_INLINE_FUNCTION \ 381 int size() const { return expr2.size(); } \ 383 KOKKOS_INLINE_FUNCTION \ 384 bool hasFastAccess(int sz) const { \ 385 return expr2.hasFastAccess(sz); \ 388 KOKKOS_INLINE_FUNCTION \ 389 value_type val() const { \ 390 return (c OPER expr2.val()); \ 393 KOKKOS_INLINE_FUNCTION \ 394 value_type coeff(int i) const { \ 395 return (c OPER expr2.coeff(i)); \ 398 KOKKOS_INLINE_FUNCTION \ 399 value_type fastAccessCoeff(int i) const { \ 400 return (c OPER expr2.fastAccessCoeff(i)); \ 404 KOKKOS_INLINE_FUNCTION \ 405 value_type getCoeff() const { \ 406 return c OPER expr2.template getCoeff<i>(); \ 412 typename const_expr_ref<T2>::type expr2; \ 415 template <typename T1, typename T2> \ 416 KOKKOS_INLINE_FUNCTION \ 418 OPNAME (const Expr<T1>& expr1, \ 419 const Expr<T2>& expr2) \ 421 typedef OP< typename Expr<T1>::derived_type, \ 422 typename Expr<T2>::derived_type > expr_t; \ 424 return expr_t(expr1.derived(), expr2.derived()); \ 427 template <typename T1, typename T2> \ 428 KOKKOS_INLINE_FUNCTION \ 429 OP< volatile T1, volatile T2 > \ 430 OPNAME (const volatile Expr<T1>& expr1, \ 431 const volatile Expr<T2>& expr2) \ 433 typedef typename Expr<T1>::derived_type derived1; \ 434 typedef typename Expr<T2>::derived_type derived2; \ 435 typedef OP< typename add_volatile<derived1>::type, \ 436 typename add_volatile<derived2>::type > expr_t; \ 438 return expr_t(expr1.derived(), expr2.derived()); \ 441 template <typename T1, typename T2> \ 442 KOKKOS_INLINE_FUNCTION \ 443 OP< T1, volatile T2 > \ 444 OPNAME (const Expr<T1>& expr1, \ 445 const volatile Expr<T2>& expr2) \ 447 typedef typename Expr<T1>::derived_type derived1; \ 448 typedef typename Expr<T2>::derived_type derived2; \ 449 typedef OP< derived1, \ 450 typename add_volatile<derived2>::type > expr_t; \ 452 return expr_t(expr1.derived(), expr2.derived()); \ 455 template <typename T1, typename T2> \ 456 KOKKOS_INLINE_FUNCTION \ 457 OP< volatile T1, T2 > \ 458 OPNAME (const volatile Expr<T1>& expr1, \ 459 const Expr<T2>& expr2) \ 461 typedef typename Expr<T1>::derived_type derived1; \ 462 typedef typename Expr<T2>::derived_type derived2; \ 463 typedef OP< typename add_volatile<derived1>::type, \ 466 return expr_t(expr1.derived(), expr2.derived()); \ 469 template <typename T> \ 470 KOKKOS_INLINE_FUNCTION \ 471 OP< typename T::value_type, T > \ 472 OPNAME (const typename T::value_type& c, \ 473 const Expr<T>& expr) \ 475 typedef typename T::value_type ConstT; \ 476 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \ 478 return expr_t(c, expr.derived()); \ 481 template <typename T> \ 482 KOKKOS_INLINE_FUNCTION \ 483 OP< typename T::value_type, volatile T > \ 484 OPNAME (const typename T::value_type& c, \ 485 const volatile Expr<T>& expr) \ 487 typedef typename T::value_type ConstT; \ 488 typedef typename Expr<T>::derived_type derived; \ 489 typedef OP< ConstT, \ 490 typename add_volatile<derived>::type > expr_t; \ 492 return expr_t(c, expr.derived()); \ 495 template <typename T> \ 496 KOKKOS_INLINE_FUNCTION \ 497 OP< T, typename T::value_type > \ 498 OPNAME (const Expr<T>& expr, \ 499 const typename T::value_type& c) \ 501 typedef typename T::value_type ConstT; \ 502 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \ 504 return expr_t(expr.derived(), c); \ 507 template <typename T> \ 508 KOKKOS_INLINE_FUNCTION \ 509 OP< volatile T, typename T::value_type > \ 510 OPNAME (const volatile Expr<T>& expr, \ 511 const typename T::value_type& c) \ 513 typedef typename T::value_type ConstT; \ 514 typedef typename Expr<T>::derived_type derived; \ 515 typedef OP< typename add_volatile<derived>::type, \ 518 return expr_t(expr.derived(), c); \ 522 template <typename T1, typename T2> \ 523 struct IsExpr< MP::OP<T1,T2> > { \ 524 static const bool value = true; \ 527 template <typename T1, typename T2> \ 528 struct BaseExprType< MP::OP<T1,T2> > { \ 529 typedef typename MP::OP<T1,T2>::base_expr_type type; \ 538 #undef MP_BINARYOP_MACRO 540 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \ 544 template <typename T1, typename T2> \ 546 public Expr< OP< T1, T2 > > { \ 550 typedef typename T1::value_type value_type_1; \ 551 typedef typename T2::value_type value_type_2; \ 552 typedef typename Sacado::Promote<value_type_1, \ 553 value_type_2>::type value_type; \ 555 typedef typename T1::storage_type storage_type; \ 556 typedef typename T1::base_expr_type base_expr_type; \ 559 KOKKOS_INLINE_FUNCTION \ 560 OP(const T1& expr1_, const T2& expr2_) : \ 561 expr1(expr1_), expr2(expr2_) {} \ 563 KOKKOS_INLINE_FUNCTION \ 564 std::string name() const { \ 565 return expr1.name() + std::string(#OPER) + expr2.name(); \ 568 KOKKOS_INLINE_FUNCTION \ 570 int sz1 = expr1.size(), sz2 = expr2.size(); \ 571 return sz1 > sz2 ? sz1 : sz2; \ 574 KOKKOS_INLINE_FUNCTION \ 575 bool hasFastAccess(int sz) const { \ 576 return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \ 579 KOKKOS_INLINE_FUNCTION \ 580 value_type val() const { \ 581 return OPER(expr1.val(), expr2.val()); \ 584 KOKKOS_INLINE_FUNCTION \ 585 value_type coeff(int i) const { \ 586 return OPER(expr1.coeff(i), expr2.coeff(i)); \ 589 KOKKOS_INLINE_FUNCTION \ 590 value_type fastAccessCoeff(int i) const { \ 591 return OPER(expr1.fastAccessCoeff(i), expr2.fastAccessCoeff(i)); \ 595 KOKKOS_INLINE_FUNCTION \ 596 value_type getCoeff() const { \ 597 return OPER(expr1.template getCoeff<i>(), \ 598 expr2.template getCoeff<i>()); \ 603 typename const_expr_ref<T1>::type expr1; \ 604 typename const_expr_ref<T2>::type expr2; \ 608 template <typename T1> \ 609 class OP< T1, typename T1::value_type > : \ 610 public Expr< OP< T1, typename T1::value_type > > { \ 614 typedef typename T1::value_type value_type; \ 615 typedef typename T1::value_type ConstT; \ 617 typedef typename T1::storage_type storage_type; \ 618 typedef typename T1::base_expr_type base_expr_type; \ 620 KOKKOS_INLINE_FUNCTION \ 621 OP(const T1& expr1_, const ConstT& c_) : \ 622 expr1(expr1_), c(c_) {} \ 624 KOKKOS_INLINE_FUNCTION \ 625 std::string name() const { \ 626 return expr1.name() + std::string(#OPER) + std::string("c"); \ 629 KOKKOS_INLINE_FUNCTION \ 630 int size() const { return expr1.size(); } \ 632 KOKKOS_INLINE_FUNCTION \ 633 bool hasFastAccess(int sz) const { \ 634 return expr1.hasFastAccess(sz); \ 637 KOKKOS_INLINE_FUNCTION \ 638 value_type val() const { \ 639 return OPER(expr1.val(), c); \ 642 KOKKOS_INLINE_FUNCTION \ 643 value_type coeff(int i) const { \ 644 return OPER(expr1.coeff(i), c); \ 647 KOKKOS_INLINE_FUNCTION \ 648 value_type fastAccessCoeff(int i) const { \ 649 return OPER(expr1.fastAccessCoeff(i), c); \ 653 KOKKOS_INLINE_FUNCTION \ 654 value_type getCoeff() const { \ 655 return OPER(expr1.template getCoeff<i>(), c); \ 660 typename const_expr_ref<T1>::type expr1; \ 664 template <typename T2> \ 665 class OP< typename T2::value_type, T2 > : \ 666 public Expr< OP< typename T2::value_type, T2 > > { \ 670 typedef typename T2::value_type value_type; \ 671 typedef typename T2::value_type ConstT; \ 673 typedef typename T2::storage_type storage_type; \ 674 typedef typename T2::base_expr_type base_expr_type; \ 676 KOKKOS_INLINE_FUNCTION \ 677 OP(const ConstT& c_, const T2& expr2_) : \ 678 c(c_), expr2(expr2_) {} \ 680 KOKKOS_INLINE_FUNCTION \ 681 std::string name() const { \ 682 return std::string("c") + std::string(#OPER) + expr2.name(); \ 685 KOKKOS_INLINE_FUNCTION \ 686 int size() const { return expr2.size(); } \ 688 KOKKOS_INLINE_FUNCTION \ 689 bool hasFastAccess(int sz) const { \ 690 return expr2.hasFastAccess(sz); \ 693 KOKKOS_INLINE_FUNCTION \ 694 value_type val() const { \ 695 return OPER(c, expr2.val()); \ 698 KOKKOS_INLINE_FUNCTION \ 699 value_type coeff(int i) const { \ 700 return OPER(c, expr2.coeff(i)); \ 703 KOKKOS_INLINE_FUNCTION \ 704 value_type fastAccessCoeff(int i) const { \ 705 return OPER(c, expr2.fastAccessCoeff(i)); \ 709 KOKKOS_INLINE_FUNCTION \ 710 value_type getCoeff() const { \ 711 return OPER(c, expr2.template getCoeff<i>()); \ 717 typename const_expr_ref<T2>::type expr2; \ 720 template <typename T1, typename T2> \ 721 KOKKOS_INLINE_FUNCTION \ 723 OPNAME (const Expr<T1>& expr1, \ 724 const Expr<T2>& expr2) \ 726 typedef OP< typename Expr<T1>::derived_type, \ 727 typename Expr<T2>::derived_type > expr_t; \ 729 return expr_t(expr1.derived(), expr2.derived()); \ 732 template <typename T> \ 733 KOKKOS_INLINE_FUNCTION \ 734 OP< typename T::value_type, T > \ 735 OPNAME (const typename T::value_type& c, \ 736 const Expr<T>& expr) \ 738 typedef typename T::value_type ConstT; \ 739 typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \ 741 return expr_t(c, expr.derived()); \ 744 template <typename T> \ 745 KOKKOS_INLINE_FUNCTION \ 746 OP< T, typename T::value_type > \ 747 OPNAME (const Expr<T>& expr, \ 748 const typename T::value_type& c) \ 750 typedef typename T::value_type ConstT; \ 751 typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \ 753 return expr_t(expr.derived(), c); \ 757 template <typename T1, typename T2> \ 758 struct IsExpr< MP::OP<T1,T2> > { \ 759 static const bool value = true; \ 762 template <typename T1, typename T2> \ 763 struct BaseExprType< MP::OP<T1,T2> > { \ 764 typedef typename MP::OP<T1,T2>::base_expr_type type; \ 778 #undef MP_BINARYOP_MACRO 784 template <
typename T>
785 KOKKOS_INLINE_FUNCTION
788 return ! expr.derived().val();
801 template <
typename T>
802 KOKKOS_INLINE_FUNCTION
807 for (
int i=0; i<
x.size(); i++)
808 is_zero = is_zero && (
x.coeff(i) == 0.0);
816 #define PCE_BOOL_MACRO(OP) \ 820 template <typename T1, typename T2> \ 821 KOKKOS_INLINE_FUNCTION \ 823 operator OP (const Expr<T1>& expr1, \ 824 const Expr<T2>& expr2) \ 826 return toBool(expr1) OP toBool(expr2); \ 829 template <typename T2> \ 830 KOKKOS_INLINE_FUNCTION \ 832 operator OP (const typename T2::value_type& a, \ 833 const Expr<T2>& expr2) \ 835 return a OP toBool(expr2); \ 838 template <typename T1> \ 839 KOKKOS_INLINE_FUNCTION \ 841 operator OP (const Expr<T1>& expr1, \ 842 const typename T1::value_type& b) \ 844 return toBool(expr1) OP b; \ 852 #undef PCE_BOOL_MACRO 861 template <
typename T>
876 template <
typename T>
880 for (
int i=0; i<
x.size(); 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)
bool isfinite(const Sacado::MP::Expr< T > &xx)
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
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
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
#define MP_UNARYOP_MACRO(OPNAME, OP, OPER)
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
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)