52 #ifndef SACADO_FAD_OPS_HPP
53 #define SACADO_FAD_OPS_HPP
60 #define FAD_UNARYOP_MACRO(OPNAME,OP,USING,VALUE,DX,FASTACCESSDX) \
64 template <typename ExprT> \
67 template <typename ExprT> \
68 struct ExprSpec< OP<ExprT> > { \
69 typedef typename ExprSpec<ExprT>::type type; \
72 template <typename ExprT> \
73 class Expr< OP<ExprT>,ExprSpecDefault > { \
76 typedef typename ExprT::value_type value_type; \
77 typedef typename ExprT::scalar_type scalar_type; \
78 typedef typename ExprT::base_expr_type base_expr_type; \
80 KOKKOS_INLINE_FUNCTION \
81 explicit Expr(const ExprT& expr_) : expr(expr_) {} \
83 KOKKOS_INLINE_FUNCTION \
84 int size() const { return expr.size(); } \
86 KOKKOS_INLINE_FUNCTION \
87 bool hasFastAccess() const { return expr.hasFastAccess(); } \
89 KOKKOS_INLINE_FUNCTION \
90 bool isPassive() const { return expr.isPassive();} \
92 KOKKOS_INLINE_FUNCTION \
93 bool updateValue() const { return expr.updateValue(); } \
95 KOKKOS_INLINE_FUNCTION \
96 void cache() const {} \
98 KOKKOS_INLINE_FUNCTION \
99 value_type val() const { \
104 KOKKOS_INLINE_FUNCTION \
105 value_type dx(int i) const { \
110 KOKKOS_INLINE_FUNCTION \
111 value_type fastAccessDx(int i) const { \
113 return FASTACCESSDX; \
121 template <typename T> \
122 KOKKOS_INLINE_FUNCTION \
123 Expr< OP< Expr<T> > > \
124 OPNAME (const Expr<T>& expr) \
126 typedef OP< Expr<T> > expr_t; \
128 return Expr<expr_t>(expr); \
139 expr.fastAccessDx(i))
145 -expr.fastAccessDx(i))
150 exp(expr.val())*expr.dx(i),
151 exp(expr.val())*expr.fastAccessDx(i))
156 expr.dx(i)/expr.val(),
157 expr.fastAccessDx(i)/expr.val())
162 expr.dx(i)/(
log(value_type(10))*expr.val()),
163 expr.fastAccessDx(i) / (
log(value_type(10))*expr.val()))
168 expr.
dx(i)/(value_type(2)*
sqrt(expr.
val())),
208 expr.
dx(i)/(value_type(1)+expr.
val()*expr.
val()),
232 expr.
dx(i)/
sqrt((expr.
val()-value_type(1)) *
233 (expr.
val()+value_type(1))),
235 (expr.
val()+value_type(1))))
247 expr.
dx(i)/(value_type(1)-expr.
val()*expr.
val()),
262 #ifdef HAVE_SACADO_CXX11
267 expr.dx(i)/(value_type(3)*
cbrt(expr.val()*expr.val())),
268 expr.fastAccessDx(i)/(value_type(3)*
cbrt(expr.val()*expr.val())))
271 #undef FAD_UNARYOP_MACRO
280 template <
typename ExprT,
bool is_simd>
283 template <
typename ExprT>
291 template <
typename ExprT>
295 typedef typename ExprT::value_type
value_type;
296 typedef typename ExprT::scalar_type scalar_type;
297 typedef typename ExprT::base_expr_type base_expr_type;
300 explicit Expr(
const ExprT& expr_) : expr(expr_) {}
303 int size()
const {
return expr.size(); }
306 bool hasFastAccess()
const {
return expr.hasFastAccess(); }
309 bool isPassive()
const {
return expr.isPassive();}
312 bool updateValue()
const {
return expr.updateValue(); }
315 void cache()
const {}
320 return sqrt(expr.val());
347 template <
typename ExprT>
351 typedef typename ExprT::value_type
value_type;
352 typedef typename ExprT::scalar_type scalar_type;
353 typedef typename ExprT::base_expr_type base_expr_type;
356 explicit Expr(
const ExprT& expr_) : expr(expr_) {}
359 int size()
const {
return expr.size(); }
362 bool hasFastAccess()
const {
return expr.hasFastAccess(); }
365 bool isPassive()
const {
return expr.isPassive();}
368 bool updateValue()
const {
return expr.updateValue(); }
371 void cache()
const {}
376 return sqrt(expr.val());
398 template <
typename T>
400 Expr< SafeSqrtOp< Expr<T> > >
403 typedef SafeSqrtOp< Expr<T> > expr_t;
405 return Expr<expr_t>(expr);
411 #define FAD_BINARYOP_MACRO(OPNAME,OP,USING,VALUE,DX,FASTACCESSDX,VAL_CONST_DX_1,VAL_CONST_DX_2,CONST_DX_1,CONST_DX_2,CONST_FASTACCESSDX_1,CONST_FASTACCESSDX_2) \
415 template <typename ExprT1, typename ExprT2> \
418 template <typename ExprT1, typename ExprT2> \
419 struct ExprSpec< OP< ExprT1, ExprT2 > > { \
420 typedef typename ExprSpec<ExprT1>::type type; \
423 template <typename ExprT1, typename ExprT2> \
424 class Expr< OP< ExprT1, ExprT2 >,ExprSpecDefault > { \
428 typedef typename ExprT1::value_type value_type_1; \
429 typedef typename ExprT2::value_type value_type_2; \
430 typedef typename Sacado::Promote<value_type_1, \
431 value_type_2>::type value_type; \
433 typedef typename ExprT1::scalar_type scalar_type_1; \
434 typedef typename ExprT2::scalar_type scalar_type_2; \
435 typedef typename Sacado::Promote<scalar_type_1, \
436 scalar_type_2>::type scalar_type; \
438 typedef typename ExprT1::base_expr_type base_expr_type_1; \
439 typedef typename ExprT2::base_expr_type base_expr_type_2; \
440 typedef typename Sacado::Promote<base_expr_type_1, \
441 base_expr_type_2>::type base_expr_type; \
443 KOKKOS_INLINE_FUNCTION \
444 Expr(const ExprT1& expr1_, const ExprT2& expr2_) : \
445 expr1(expr1_), expr2(expr2_) {} \
447 KOKKOS_INLINE_FUNCTION \
449 int sz1 = expr1.size(), sz2 = expr2.size(); \
450 return sz1 > sz2 ? sz1 : sz2; \
453 KOKKOS_INLINE_FUNCTION \
454 bool hasFastAccess() const { \
455 return expr1.hasFastAccess() && expr2.hasFastAccess(); \
458 KOKKOS_INLINE_FUNCTION \
459 bool isPassive() const { \
460 return expr1.isPassive() && expr2.isPassive(); \
463 KOKKOS_INLINE_FUNCTION \
464 bool updateValue() const { \
465 return expr1.updateValue() && expr2.updateValue(); \
468 KOKKOS_INLINE_FUNCTION \
469 void cache() const {} \
471 KOKKOS_INLINE_FUNCTION \
472 const value_type val() const { \
477 KOKKOS_INLINE_FUNCTION \
478 const value_type dx(int i) const { \
483 KOKKOS_INLINE_FUNCTION \
484 const value_type fastAccessDx(int i) const { \
486 return FASTACCESSDX; \
491 const ExprT1& expr1; \
492 const ExprT2& expr2; \
496 template <typename ExprT1, typename T2> \
497 struct ExprSpec< OP< ExprT1, ConstExpr<T2> > > { \
498 typedef typename ExprSpec<ExprT1>::type type; \
501 template <typename ExprT1, typename T2> \
502 class Expr< OP< ExprT1, ConstExpr<T2> >,ExprSpecDefault > { \
506 typedef ConstExpr<T2> ConstT; \
507 typedef ConstExpr<T2> ExprT2; \
508 typedef typename ExprT1::value_type value_type_1; \
509 typedef typename ExprT2::value_type value_type_2; \
510 typedef typename Sacado::Promote<value_type_1, \
511 value_type_2>::type value_type; \
513 typedef typename ExprT1::scalar_type scalar_type_1; \
514 typedef typename ExprT2::scalar_type scalar_type_2; \
515 typedef typename Sacado::Promote<scalar_type_1, \
516 scalar_type_2>::type scalar_type; \
518 typedef typename ExprT1::base_expr_type base_expr_type_1; \
519 typedef typename ExprT2::base_expr_type base_expr_type_2; \
520 typedef typename Sacado::Promote<base_expr_type_1, \
521 base_expr_type_2>::type base_expr_type; \
523 KOKKOS_INLINE_FUNCTION \
524 Expr(const ExprT1& expr1_, const ConstT& c_) : \
525 expr1(expr1_), c(c_) {} \
527 KOKKOS_INLINE_FUNCTION \
529 return expr1.size(); \
532 KOKKOS_INLINE_FUNCTION \
533 bool hasFastAccess() const { \
534 return expr1.hasFastAccess(); \
537 KOKKOS_INLINE_FUNCTION \
538 bool isPassive() const { \
539 return expr1.isPassive(); \
542 KOKKOS_INLINE_FUNCTION \
543 bool updateValue() const { return expr1.updateValue(); } \
545 KOKKOS_INLINE_FUNCTION \
546 void cache() const {} \
548 KOKKOS_INLINE_FUNCTION \
549 const value_type val() const { \
551 return VAL_CONST_DX_2; \
554 KOKKOS_INLINE_FUNCTION \
555 const value_type dx(int i) const { \
560 KOKKOS_INLINE_FUNCTION \
561 const value_type fastAccessDx(int i) const { \
563 return CONST_FASTACCESSDX_2; \
568 const ExprT1& expr1; \
572 template <typename T1, typename ExprT2> \
573 struct ExprSpec< OP< ConstExpr<T1>, ExprT2 > > { \
574 typedef typename ExprSpec<ExprT2>::type type; \
577 template <typename T1, typename ExprT2> \
578 class Expr< OP< ConstExpr<T1>, ExprT2 >,ExprSpecDefault > { \
582 typedef ConstExpr<T1> ConstT; \
583 typedef ConstExpr<T1> ExprT1; \
584 typedef typename ExprT1::value_type value_type_1; \
585 typedef typename ExprT2::value_type value_type_2; \
586 typedef typename Sacado::Promote<value_type_1, \
587 value_type_2>::type value_type; \
589 typedef typename ExprT1::scalar_type scalar_type_1; \
590 typedef typename ExprT2::scalar_type scalar_type_2; \
591 typedef typename Sacado::Promote<scalar_type_1, \
592 scalar_type_2>::type scalar_type; \
594 typedef typename ExprT1::base_expr_type base_expr_type_1; \
595 typedef typename ExprT2::base_expr_type base_expr_type_2; \
596 typedef typename Sacado::Promote<base_expr_type_1, \
597 base_expr_type_2>::type base_expr_type; \
600 KOKKOS_INLINE_FUNCTION \
601 Expr(const ConstT& c_, const ExprT2& expr2_) : \
602 c(c_), expr2(expr2_) {} \
604 KOKKOS_INLINE_FUNCTION \
606 return expr2.size(); \
609 KOKKOS_INLINE_FUNCTION \
610 bool hasFastAccess() const { \
611 return expr2.hasFastAccess(); \
614 KOKKOS_INLINE_FUNCTION \
615 bool isPassive() const { \
616 return expr2.isPassive(); \
619 KOKKOS_INLINE_FUNCTION \
620 bool updateValue() const { return expr2.updateValue(); } \
622 KOKKOS_INLINE_FUNCTION \
623 void cache() const {} \
625 KOKKOS_INLINE_FUNCTION \
626 const value_type val() const { \
628 return VAL_CONST_DX_1; \
631 KOKKOS_INLINE_FUNCTION \
632 const value_type dx(int i) const { \
637 KOKKOS_INLINE_FUNCTION \
638 const value_type fastAccessDx(int i) const { \
640 return CONST_FASTACCESSDX_1; \
646 const ExprT2& expr2; \
649 template <typename T1, typename T2> \
650 KOKKOS_INLINE_FUNCTION \
651 typename mpl::enable_if_c< \
652 ExprLevel< Expr<T1> >::value == ExprLevel< Expr<T2> >::value, \
653 Expr< OP< Expr<T1>, Expr<T2> > > \
656 OPNAME (const Expr<T1>& expr1, const Expr<T2>& expr2) \
658 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
660 return Expr<expr_t>(expr1, expr2); \
663 template <typename T> \
664 KOKKOS_INLINE_FUNCTION \
665 Expr< OP< Expr<T>, Expr<T> > > \
666 OPNAME (const Expr<T>& expr1, const Expr<T>& expr2) \
668 typedef OP< Expr<T>, Expr<T> > expr_t; \
670 return Expr<expr_t>(expr1, expr2); \
673 template <typename T> \
674 KOKKOS_INLINE_FUNCTION \
675 Expr< OP< ConstExpr<typename Expr<T>::value_type>, \
677 OPNAME (const typename Expr<T>::value_type& c, \
678 const Expr<T>& expr) \
680 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
681 typedef OP< ConstT, Expr<T> > expr_t; \
683 return Expr<expr_t>(ConstT(c), expr); \
686 template <typename T> \
687 KOKKOS_INLINE_FUNCTION \
689 ConstExpr<typename Expr<T>::value_type> > > \
690 OPNAME (const Expr<T>& expr, \
691 const typename Expr<T>::value_type& c) \
693 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
694 typedef OP< Expr<T>, ConstT > expr_t; \
696 return Expr<expr_t>(expr, ConstT(c)); \
699 template <typename T> \
700 KOKKOS_INLINE_FUNCTION \
701 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(OP) \
702 OPNAME (const typename Expr<T>::scalar_type& c, \
703 const Expr<T>& expr) \
705 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
706 typedef OP< ConstT, Expr<T> > expr_t; \
708 return Expr<expr_t>(ConstT(c), expr); \
711 template <typename T> \
712 KOKKOS_INLINE_FUNCTION \
713 SACADO_FAD_OP_ENABLE_EXPR_SCALAR(OP) \
714 OPNAME (const Expr<T>& expr, \
715 const typename Expr<T>::scalar_type& c) \
717 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
718 typedef OP< Expr<T>, ConstT > expr_t; \
720 return Expr<expr_t>(expr, ConstT(c)); \
730 expr1.val() + expr2.val(),
731 expr1.dx(i) + expr2.dx(i),
732 expr1.fastAccessDx(i) + expr2.fastAccessDx(i),
733 c.val() + expr2.val(),
734 expr1.val() +
c.val(),
737 expr2.fastAccessDx(i),
738 expr1.fastAccessDx(i))
742 expr1.val() - expr2.val(),
743 expr1.dx(i) - expr2.dx(i),
744 expr1.fastAccessDx(i) - expr2.fastAccessDx(i),
745 c.val() - expr2.val(),
746 expr1.val() -
c.val(),
749 -expr2.fastAccessDx(i),
750 expr1.fastAccessDx(i))
767 expr1.val() / expr2.val(),
768 (expr1.dx(i)*expr2.val() - expr2.dx(i)*expr1.val()) /
769 (expr2.val()*expr2.val()),
770 (expr1.fastAccessDx(i)*expr2.val() -
771 expr2.fastAccessDx(i)*expr1.val()) /
772 (expr2.val()*expr2.val()),
773 c.val() / expr2.val(),
774 expr1.val() /
c.val(),
775 -expr2.dx(i)*
c.val() / (expr2.val()*expr2.val()),
777 -expr2.fastAccessDx(i)*
c.val() / (expr2.val()*expr2.val()),
778 expr1.fastAccessDx(i)/
c.val())
783 (expr2.
val()*expr1.
dx(i) - expr1.
val()*expr2.
dx(i))/
831 #undef FAD_BINARYOP_MACRO
836 template <
typename ExprT1,
typename ExprT2>
839 template <
typename ExprT1,
typename ExprT2>
844 template <
typename ExprT1,
typename ExprT2>
849 typedef typename ExprT1::value_type value_type_1;
850 typedef typename ExprT2::value_type value_type_2;
854 typedef typename ExprT1::scalar_type scalar_type_1;
855 typedef typename ExprT2::scalar_type scalar_type_2;
857 scalar_type_2>::type scalar_type;
859 typedef typename ExprT1::base_expr_type base_expr_type_1;
860 typedef typename ExprT2::base_expr_type base_expr_type_2;
862 base_expr_type_2>::type base_expr_type;
865 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) :
866 expr1(expr1_), expr2(expr2_) {}
870 int sz1 = expr1.size(), sz2 = expr2.size();
871 return sz1 > sz2 ? sz1 : sz2;
875 bool hasFastAccess()
const {
876 return expr1.hasFastAccess() && expr2.hasFastAccess();
880 bool isPassive()
const {
881 return expr1.isPassive() && expr2.isPassive();
885 bool updateValue()
const {
886 return expr1.updateValue() && expr2.updateValue();
890 void cache()
const {}
894 return expr1.val()*expr2.val();
899 if (expr1.size() > 0 && expr2.size() > 0)
900 return expr1.val()*expr2.dx(i) + expr1.dx(i)*expr2.val();
901 else if (expr1.size() > 0)
902 return expr1.dx(i)*expr2.val();
904 return expr1.val()*expr2.dx(i);
909 return expr1.val()*expr2.fastAccessDx(i) +
910 expr1.fastAccessDx(i)*expr2.val();
920 template <
typename ExprT1,
typename T2>
925 template <
typename ExprT1,
typename T2>
930 typedef ConstExpr<T2> ConstT;
931 typedef ConstExpr<T2> ExprT2;
932 typedef typename ExprT1::value_type value_type_1;
933 typedef typename ExprT2::value_type value_type_2;
937 typedef typename ExprT1::scalar_type scalar_type_1;
938 typedef typename ExprT2::scalar_type scalar_type_2;
940 scalar_type_2>::type scalar_type;
942 typedef typename ExprT1::base_expr_type base_expr_type_1;
943 typedef typename ExprT2::base_expr_type base_expr_type_2;
945 base_expr_type_2>::type base_expr_type;
948 Expr(
const ExprT1& expr1_,
const ConstT& c_) :
949 expr1(expr1_),
c(c_) {}
957 bool hasFastAccess()
const {
958 return expr1.hasFastAccess();
962 bool isPassive()
const {
963 return expr1.isPassive();
967 bool updateValue()
const {
return expr1.updateValue(); }
970 void cache()
const {}
974 return expr1.val()*
c.val();
979 return expr1.dx(i)*
c.val();
984 return expr1.fastAccessDx(i)*
c.val();
993 template <
typename T1,
typename ExprT2>
998 template <
typename T1,
typename ExprT2>
1003 typedef ConstExpr<T1> ConstT;
1004 typedef ConstExpr<T1> ExprT1;
1005 typedef typename ExprT1::value_type value_type_1;
1006 typedef typename ExprT2::value_type value_type_2;
1010 typedef typename ExprT1::scalar_type scalar_type_1;
1011 typedef typename ExprT2::scalar_type scalar_type_2;
1013 scalar_type_2>::type scalar_type;
1015 typedef typename ExprT1::base_expr_type base_expr_type_1;
1016 typedef typename ExprT2::base_expr_type base_expr_type_2;
1018 base_expr_type_2>::type base_expr_type;
1021 Expr(
const ConstT& c_,
const ExprT2& expr2_) :
1022 c(c_), expr2(expr2_) {}
1026 return expr2.size();
1030 bool hasFastAccess()
const {
1031 return expr2.hasFastAccess();
1035 bool isPassive()
const {
1036 return expr2.isPassive();
1040 bool updateValue()
const {
return expr2.updateValue(); }
1043 void cache()
const {}
1047 return c.val()*expr2.val();
1052 return c.val()*expr2.dx(i);
1057 return c.val()*expr2.fastAccessDx(i);
1063 const ExprT2& expr2;
1066 template <
typename T1,
typename T2>
1068 typename mpl::enable_if_c<
1069 ExprLevel< Expr<T1> >::value == ExprLevel< Expr<T2> >::value,
1070 Expr< MultiplicationOp< Expr<T1>, Expr<T2> > >
1073 operator* (
const Expr<T1>& expr1,
const Expr<T2>& expr2)
1075 typedef MultiplicationOp< Expr<T1>, Expr<T2> > expr_t;
1077 return Expr<expr_t>(expr1, expr2);
1080 template <
typename T>
1082 Expr< MultiplicationOp< Expr<T>, Expr<T> > >
1083 operator* (
const Expr<T>& expr1,
const Expr<T>& expr2)
1085 typedef MultiplicationOp< Expr<T>, Expr<T> > expr_t;
1087 return Expr<expr_t>(expr1, expr2);
1090 template <
typename T>
1094 const Expr<T>& expr)
1097 typedef MultiplicationOp< ConstT, Expr<T> > expr_t;
1099 return Expr<expr_t>(ConstT(
c), expr);
1102 template <
typename T>
1109 typedef MultiplicationOp< Expr<T>, ConstT > expr_t;
1111 return Expr<expr_t>(expr, ConstT(
c));
1114 template <
typename T>
1117 operator* (
const typename Expr<T>::scalar_type&
c,
1118 const Expr<T>& expr)
1121 typedef MultiplicationOp< ConstT, Expr<T> > expr_t;
1123 return Expr<expr_t>(ConstT(
c), expr);
1126 template <
typename T>
1130 const typename Expr<T>::scalar_type&
c)
1133 typedef MultiplicationOp< Expr<T>, ConstT > expr_t;
1135 return Expr<expr_t>(expr, ConstT(
c));
1147 template <
typename ExprT1,
typename ExprT2,
bool is_simd>
1150 template <
typename ExprT1,
typename ExprT2>
1155 template <
typename ExprT1,
typename T2>
1160 template <
typename T1,
typename ExprT2>
1168 template <
typename ExprT1,
typename ExprT2>
1189 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) :
1190 expr1(expr1_), expr2(expr2_) {}
1194 int sz1 = expr1.size(), sz2 = expr2.size();
1195 return sz1 > sz2 ? sz1 : sz2;
1200 return expr1.hasFastAccess() && expr2.hasFastAccess();
1205 return expr1.isPassive() && expr2.isPassive();
1210 return expr1.updateValue() && expr2.updateValue();
1219 return pow(expr1.val(), expr2.val());
1241 template <
typename ExprT1,
typename T2>
1265 expr1(expr1_),
c(c_) {}
1269 return expr1.size();
1274 return expr1.hasFastAccess();
1279 return expr1.isPassive();
1291 return pow(expr1.val(),
c.val());
1316 template <
typename T1,
typename ExprT2>
1341 c(c_), expr2(expr2_) {}
1345 return expr2.size();
1350 return expr2.hasFastAccess();
1355 return expr2.isPassive();
1367 return pow(
c.val(), expr2.val());
1392 template <
typename ExprT1,
typename ExprT2>
1413 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) :
1414 expr1(expr1_), expr2(expr2_) {}
1418 int sz1 = expr1.size(), sz2 = expr2.size();
1419 return sz1 > sz2 ? sz1 : sz2;
1424 return expr1.hasFastAccess() && expr2.hasFastAccess();
1429 return expr1.isPassive() && expr2.isPassive();
1434 return expr1.updateValue() && expr2.updateValue();
1443 return pow(expr1.val(), expr2.val());
1455 return expr1.val() ==
value_type(0.0) ?
value_type(0.0) :
value_type((expr2.fastAccessDx(i)*
log(expr1.val())+expr2.val()*expr1.fastAccessDx(i)/expr1.val())*
pow(expr1.val(),expr2.val()));
1465 template <
typename ExprT1,
typename T2>
1489 expr1(expr1_),
c(c_) {}
1493 return expr1.size();
1498 return expr1.hasFastAccess();
1503 return expr1.isPassive();
1515 return pow(expr1.val(),
c.val());
1540 template <
typename T1,
typename ExprT2>
1565 c(c_), expr2(expr2_) {}
1569 return expr2.size();
1574 return expr2.hasFastAccess();
1579 return expr2.isPassive();
1591 return pow(
c.val(), expr2.val());
1612 template <
typename T1,
typename T2>
1626 template <
typename T>
1628 Expr< PowerOp< Expr<T>, Expr<T> > >
1636 template <
typename T>
1648 template <
typename T>
1660 template <
typename T>
1664 const
Expr<
T>& expr)
1672 template <
typename T>
1676 const typename
Expr<
T>::scalar_type&
c)
1690 #ifdef HAVE_SACADO_CXX11
1695 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1696 class IfThenElseOp {};
1698 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1699 struct ExprSpec< IfThenElseOp< CondT, ExprT1, ExprT2 > > {
1703 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1704 class Expr< IfThenElseOp< CondT, ExprT1, ExprT2 >,ExprSpecDefault > {
1708 typedef typename ExprT1::value_type value_type_1;
1709 typedef typename ExprT2::value_type value_type_2;
1713 typedef typename ExprT1::scalar_type scalar_type_1;
1714 typedef typename ExprT2::scalar_type scalar_type_2;
1716 scalar_type_2>::type scalar_type;
1718 typedef typename ExprT1::base_expr_type base_expr_type_1;
1719 typedef typename ExprT2::base_expr_type base_expr_type_2;
1721 base_expr_type_2>::type base_expr_type;
1724 Expr(
const CondT& cond_,
const ExprT1& expr1_,
const ExprT2& expr2_) :
1725 cond(cond_), expr1(expr1_), expr2(expr2_) {}
1729 int sz1 = expr1.size(), sz2 = expr2.size();
1730 return sz1 > sz2 ? sz1 : sz2;
1734 bool hasFastAccess()
const {
1735 return expr1.hasFastAccess() && expr2.hasFastAccess();
1739 bool isPassive()
const {
1740 return expr1.isPassive() && expr2.isPassive();
1744 bool updateValue()
const {
1745 return expr1.updateValue() && expr2.updateValue();
1749 void cache()
const {}
1766 return if_then_else( cond, expr1.fastAccessDx(i), expr2.fastAccessDx(i) );
1772 const ExprT1& expr1;
1773 const ExprT2& expr2;
1777 template <
typename CondT,
typename ExprT1,
typename T2>
1778 struct ExprSpec< IfThenElseOp< CondT, ExprT1, ConstExpr<
T2> > > {
1782 template <
typename CondT,
typename ExprT1,
typename T2>
1783 class Expr< IfThenElseOp< CondT, ExprT1, ConstExpr<
T2> >,ExprSpecDefault > {
1787 typedef ConstExpr<T2> ConstT;
1788 typedef ConstExpr<T2> ExprT2;
1789 typedef typename ExprT1::value_type value_type_1;
1790 typedef typename ExprT2::value_type value_type_2;
1794 typedef typename ExprT1::scalar_type scalar_type_1;
1795 typedef typename ExprT2::scalar_type scalar_type_2;
1797 scalar_type_2>::type scalar_type;
1799 typedef typename ExprT1::base_expr_type base_expr_type_1;
1800 typedef typename ExprT2::base_expr_type base_expr_type_2;
1802 base_expr_type_2>::type base_expr_type;
1805 Expr(
const CondT& cond_,
const ExprT1& expr1_,
const ConstT& c_) :
1806 cond(cond_), expr1(expr1_),
c(c_) {}
1810 return expr1.size();
1814 bool hasFastAccess()
const {
1815 return expr1.hasFastAccess();
1819 bool isPassive()
const {
1820 return expr1.isPassive();
1824 bool updateValue()
const {
return expr1.updateValue(); }
1827 void cache()
const {}
1850 const ExprT1& expr1;
1854 template <
typename CondT,
typename T1,
typename ExprT2>
1855 struct ExprSpec< IfThenElseOp< CondT, ConstExpr<
T1>, ExprT2 > > {
1859 template <
typename CondT,
typename T1,
typename ExprT2>
1860 class Expr< IfThenElseOp< CondT, ConstExpr<
T1>, ExprT2 >,ExprSpecDefault > {
1864 typedef ConstExpr<T1> ConstT;
1865 typedef ConstExpr<T1> ExprT1;
1866 typedef typename ExprT1::value_type value_type_1;
1867 typedef typename ExprT2::value_type value_type_2;
1871 typedef typename ExprT1::scalar_type scalar_type_1;
1872 typedef typename ExprT2::scalar_type scalar_type_2;
1874 scalar_type_2>::type scalar_type;
1876 typedef typename ExprT1::base_expr_type base_expr_type_1;
1877 typedef typename ExprT2::base_expr_type base_expr_type_2;
1879 base_expr_type_2>::type base_expr_type;
1882 Expr(
const CondT& cond_,
const ConstT& c_,
const ExprT2& expr2_) :
1883 cond(cond_),
c(c_), expr2(expr2_) {}
1887 return expr2.size();
1891 bool hasFastAccess()
const {
1892 return expr2.hasFastAccess();
1896 bool isPassive()
const {
1897 return expr2.isPassive();
1901 bool updateValue()
const {
return expr2.updateValue(); }
1904 void cache()
const {}
1928 const ExprT2& expr2;
1931 template <
typename CondT,
typename T1,
typename T2>
1935 Expr< IfThenElseOp< CondT, T1, T2 > >
1939 typedef IfThenElseOp< CondT, T1, T2 > expr_t;
1941 return Expr<expr_t>(cond, expr1, expr2);
1944 template <
typename CondT,
typename T>
1946 Expr< IfThenElseOp< CondT, Expr<T>, Expr<T> > >
1947 if_then_else (
const CondT& cond,
const Expr<T>& expr1,
const Expr<T>& expr2)
1949 typedef IfThenElseOp< CondT, Expr<T>, Expr<T> > expr_t;
1951 return Expr<expr_t>(cond, expr1, expr2);
1954 template <
typename CondT,
typename T>
1959 const Expr<T>& expr)
1962 typedef IfThenElseOp< CondT, ConstT, Expr<T> > expr_t;
1964 return Expr<expr_t>(cond, ConstT(
c), expr);
1967 template <
typename CondT,
typename T>
1969 Expr< IfThenElseOp< CondT, Expr<T>,
1975 typedef IfThenElseOp< CondT, Expr<T>, ConstT > expr_t;
1977 return Expr<expr_t>(cond, expr, ConstT(
c));
1980 template <
typename CondT,
typename T>
1982 typename mpl::disable_if<
1983 mpl::is_same< typename Expr<T>::value_type,
1984 typename Expr<T>::scalar_type>,
1985 Expr< IfThenElseOp< CondT, ConstExpr<typename Expr<T>::scalar_type>,
1988 if_then_else (
const CondT& cond,
const typename Expr<T>::scalar_type&
c,
1989 const Expr<T>& expr)
1992 typedef IfThenElseOp< CondT, ConstT, Expr<T> > expr_t;
1994 return Expr<expr_t>(cond, ConstT(
c), expr);
1997 template <
typename CondT,
typename T>
1999 typename mpl::disable_if<
2000 mpl::is_same< typename Expr<T>::value_type,
2001 typename Expr<T>::scalar_type>,
2002 Expr< IfThenElseOp< CondT, Expr<T>,
2006 const typename Expr<T>::scalar_type&
c)
2009 typedef IfThenElseOp< CondT, Expr<T>, ConstT > expr_t;
2011 return Expr<expr_t>(cond, expr, ConstT(
c));
2020 #ifdef HAVE_SACADO_CXX11
2024 template <
typename T1,
typename T2 = T1>
2025 struct ConditionalReturnType {
2026 typedef decltype( std::declval<T1>() == std::declval<T2>() ) type;
2031 #define FAD_RELOP_MACRO(OP) \
2032 namespace Sacado { \
2034 template <typename ExprT1, typename ExprT2> \
2035 KOKKOS_INLINE_FUNCTION \
2036 typename ConditionalReturnType<typename Expr<ExprT1>::value_type, \
2037 typename Expr<ExprT2>::value_type>::type \
2038 operator OP (const Expr<ExprT1>& expr1, \
2039 const Expr<ExprT2>& expr2) \
2041 return expr1.val() OP expr2.val(); \
2044 template <typename ExprT2> \
2045 KOKKOS_INLINE_FUNCTION \
2046 typename ConditionalReturnType<typename Expr<ExprT2>::value_type>::type \
2047 operator OP (const typename Expr<ExprT2>::value_type& a, \
2048 const Expr<ExprT2>& expr2) \
2050 return a OP expr2.val(); \
2053 template <typename ExprT1> \
2054 KOKKOS_INLINE_FUNCTION \
2055 typename ConditionalReturnType<typename Expr<ExprT1>::value_type>::type \
2056 operator OP (const Expr<ExprT1>& expr1, \
2057 const typename Expr<ExprT1>::value_type& b) \
2059 return expr1.val() OP b; \
2066 #define FAD_RELOP_MACRO(OP) \
2067 namespace Sacado { \
2069 template <typename ExprT1, typename ExprT2> \
2070 KOKKOS_INLINE_FUNCTION \
2072 operator OP (const Expr<ExprT1>& expr1, \
2073 const Expr<ExprT2>& expr2) \
2075 return expr1.val() OP expr2.val(); \
2078 template <typename ExprT2> \
2079 KOKKOS_INLINE_FUNCTION \
2081 operator OP (const typename Expr<ExprT2>::value_type& a, \
2082 const Expr<ExprT2>& expr2) \
2084 return a OP expr2.val(); \
2087 template <typename ExprT1> \
2088 KOKKOS_INLINE_FUNCTION \
2090 operator OP (const Expr<ExprT1>& expr1, \
2091 const typename Expr<ExprT1>::value_type& b) \
2093 return expr1.val() OP b; \
2111 #undef FAD_RELOP_MACRO
2117 template <
typename ExprT>
2121 return ! expr.val();
2133 template <
typename ExprT>
2136 bool is_zero = (x.val() == 0.0);
2137 for (
int i=0; i<x.size(); i++)
2138 is_zero = is_zero && (x.dx(i) == 0.0);
2146 #define FAD_BOOL_MACRO(OP) \
2147 namespace Sacado { \
2149 template <typename ExprT1, typename ExprT2> \
2150 KOKKOS_INLINE_FUNCTION \
2152 operator OP (const Expr<ExprT1>& expr1, \
2153 const Expr<ExprT2>& expr2) \
2155 return toBool(expr1) OP toBool(expr2); \
2158 template <typename ExprT2> \
2159 KOKKOS_INLINE_FUNCTION \
2161 operator OP (const typename Expr<ExprT2>::value_type& a, \
2162 const Expr<ExprT2>& expr2) \
2164 return a OP toBool(expr2); \
2167 template <typename ExprT1> \
2168 KOKKOS_INLINE_FUNCTION \
2170 operator OP (const Expr<ExprT1>& expr1, \
2171 const typename Expr<ExprT1>::value_type& b) \
2173 return toBool(expr1) OP b; \
2181 #undef FAD_BOOL_MACRO
2189 template <
typename ExprT>
2191 os << x.val() <<
" [";
2193 for (
int i=0; i< x.size(); i++) {
2194 os <<
" " << x.dx(i);
#define KOKKOS_INLINE_FUNCTION
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 MultiplicationOp
#define FAD_BINARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, FASTACCESSDX, VAL_CONST_DX_1, VAL_CONST_DX_2, CONST_DX_1, CONST_DX_2, CONST_FASTACCESSDX_1, CONST_FASTACCESSDX_2)
expr1 expr1 expr1 c expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr1 expr2 expr1 expr2 expr1 Atan2Op
#define FAD_UNARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, FASTACCESSDX)
expr1 expr1 expr1 c expr1 expr2 expr1 expr2 expr1 DivisionOp
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
#define FAD_RELOP_MACRO(OP)
if_then_else(expr.val() >=0, expr.dx(i), value_type(-expr.dx(i)))
#define FAD_BOOL_MACRO(OP)
expr2 expr2 c c c c MaxOp
atan2(expr1.val(), expr2.val())
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 expr1 expr1 c
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 SACADO_FAD_OP_ENABLE_SCALAR_EXPR(OP)
#define SACADO_FAD_OP_ENABLE_EXPR_SCALAR(OP)
Constant expression template.
T2 base_expr_type
Typename of base-expressions.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from ConstT)
ConstT value_type
Typename of argument values.
KOKKOS_INLINE_FUNCTION void cache() const
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
KOKKOS_INLINE_FUNCTION int size() const
KOKKOS_INLINE_FUNCTION const value_type val() const
Sacado::Promote< value_type_1, value_type_2 >::type value_type
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
ExprT2::value_type value_type_2
ExprT1::value_type value_type_1
KOKKOS_INLINE_FUNCTION bool isPassive() const
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
ExprT1::base_expr_type base_expr_type_1
KOKKOS_INLINE_FUNCTION bool updateValue() const
KOKKOS_INLINE_FUNCTION Expr(const ConstT &c_, const ExprT2 &expr2_)
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
ExprT1::scalar_type scalar_type_1
ExprT2::scalar_type scalar_type_2
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
ExprT2::base_expr_type base_expr_type_2
ExprT1::value_type value_type_1
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
ExprT2::scalar_type scalar_type_2
KOKKOS_INLINE_FUNCTION bool isPassive() const
Sacado::Promote< value_type_1, value_type_2 >::type value_type
ExprT1::base_expr_type base_expr_type_1
KOKKOS_INLINE_FUNCTION Expr(const ConstT &c_, const ExprT2 &expr2_)
KOKKOS_INLINE_FUNCTION const value_type val() const
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
KOKKOS_INLINE_FUNCTION void cache() const
KOKKOS_INLINE_FUNCTION bool updateValue() const
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
ExprT2::value_type value_type_2
KOKKOS_INLINE_FUNCTION int size() const
ExprT1::scalar_type scalar_type_1
ExprT2::base_expr_type base_expr_type_2
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Sacado::Promote< value_type_1, value_type_2 >::type value_type
KOKKOS_INLINE_FUNCTION void cache() const
ExprT1::base_expr_type base_expr_type_1
KOKKOS_INLINE_FUNCTION bool updateValue() const
KOKKOS_INLINE_FUNCTION int size() const
ExprT1::scalar_type scalar_type_1
ExprT2::scalar_type scalar_type_2
ExprT1::value_type value_type_1
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
ExprT2::value_type value_type_2
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
KOKKOS_INLINE_FUNCTION const value_type val() const
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
KOKKOS_INLINE_FUNCTION Expr(const ExprT1 &expr1_, const ConstT &c_)
ExprT2::base_expr_type base_expr_type_2
KOKKOS_INLINE_FUNCTION bool isPassive() const
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
KOKKOS_INLINE_FUNCTION const value_type val() const
ExprT2::scalar_type scalar_type_2
KOKKOS_INLINE_FUNCTION Expr(const ExprT1 &expr1_, const ConstT &c_)
Sacado::Promote< value_type_1, value_type_2 >::type value_type
KOKKOS_INLINE_FUNCTION int size() const
KOKKOS_INLINE_FUNCTION bool isPassive() const
ExprT1::value_type value_type_1
ExprT1::scalar_type scalar_type_1
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
KOKKOS_INLINE_FUNCTION void cache() const
ExprT2::value_type value_type_2
KOKKOS_INLINE_FUNCTION bool updateValue() const
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
ExprT1::base_expr_type base_expr_type_1
ExprT2::base_expr_type base_expr_type_2
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
KOKKOS_INLINE_FUNCTION bool isPassive() const
ExprT1::value_type value_type_1
KOKKOS_INLINE_FUNCTION const value_type val() const
ExprT2::value_type value_type_2
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
ExprT2::scalar_type scalar_type_2
Sacado::Promote< value_type_1, value_type_2 >::type value_type
ExprT1::base_expr_type base_expr_type_1
KOKKOS_INLINE_FUNCTION Expr(const ExprT1 &expr1_, const ExprT2 &expr2_)
KOKKOS_INLINE_FUNCTION int size() const
KOKKOS_INLINE_FUNCTION bool updateValue() const
ExprT1::scalar_type scalar_type_1
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
KOKKOS_INLINE_FUNCTION void cache() const
ExprT2::base_expr_type base_expr_type_2
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
ExprT2::scalar_type scalar_type_2
ExprT1::scalar_type scalar_type_1
KOKKOS_INLINE_FUNCTION const value_type val() const
KOKKOS_INLINE_FUNCTION void cache() const
Sacado::Promote< value_type_1, value_type_2 >::type value_type
ExprT2::base_expr_type base_expr_type_2
KOKKOS_INLINE_FUNCTION Expr(const ExprT1 &expr1_, const ExprT2 &expr2_)
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
ExprT1::base_expr_type base_expr_type_1
KOKKOS_INLINE_FUNCTION bool isPassive() const
KOKKOS_INLINE_FUNCTION int size() const
ExprT1::value_type value_type_1
KOKKOS_INLINE_FUNCTION bool updateValue() const
ExprT2::value_type value_type_2
KOKKOS_INLINE_FUNCTION const value_type fastAccessDx(int i) const
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
KOKKOS_INLINE_FUNCTION const value_type dx(int i) const
Wrapper for a generic expression template.
SimpleFad< ValueT > sqrt(const SimpleFad< ValueT > &a)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< ExprT > &x)
KOKKOS_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
KOKKOS_INLINE_FUNCTION pow(const Expr< T > &expr, const typename Expr< T >::scalar_type &c)
SimpleFad< ValueT > log(const SimpleFad< ValueT > &a)
SimpleFad< ValueT > operator*(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< ExprT > &expr)
KOKKOS_INLINE_FUNCTION Expr< SafeSqrtOp< Expr< T > > > safe_sqrt(const Expr< T > &)
std::ostream & operator<<(std::ostream &os, const Expr< ExprT > &x)
KOKKOS_INLINE_FUNCTION T if_then_else(const Cond cond, const T &a, const T &b)
Meta-function for determining nesting with an expression.
static const unsigned value
ExprSpec< ExprT2 >::type type
ExprSpec< ExprT1 >::type type
ExprSpec< ExprT1 >::type type