52 #ifndef SACADO_FAD_OPS_HPP
53 #define SACADO_FAD_OPS_HPP
59 #define FAD_UNARYOP_MACRO(OPNAME,OP,USING,VALUE,DX,FASTACCESSDX) \
63 template <typename ExprT> \
66 template <typename ExprT> \
67 struct ExprSpec< OP<ExprT> > { \
68 typedef typename ExprSpec<ExprT>::type type; \
71 template <typename ExprT> \
72 class Expr< OP<ExprT>,ExprSpecDefault > { \
75 typedef typename ExprT::value_type value_type; \
76 typedef typename ExprT::scalar_type scalar_type; \
77 typedef typename ExprT::base_expr_type base_expr_type; \
79 KOKKOS_INLINE_FUNCTION \
80 Expr(const ExprT& expr_) : expr(expr_) {} \
82 KOKKOS_INLINE_FUNCTION \
83 int size() const { return expr.size(); } \
85 KOKKOS_INLINE_FUNCTION \
86 bool hasFastAccess() const { return expr.hasFastAccess(); } \
88 KOKKOS_INLINE_FUNCTION \
89 bool isPassive() const { return expr.isPassive();} \
91 KOKKOS_INLINE_FUNCTION \
92 bool updateValue() const { return expr.updateValue(); } \
94 KOKKOS_INLINE_FUNCTION \
95 void cache() const {} \
97 KOKKOS_INLINE_FUNCTION \
98 value_type val() const { \
103 KOKKOS_INLINE_FUNCTION \
104 value_type dx(int i) const { \
109 KOKKOS_INLINE_FUNCTION \
110 value_type fastAccessDx(int i) const { \
112 return FASTACCESSDX; \
120 template <typename T> \
121 KOKKOS_INLINE_FUNCTION \
122 Expr< OP< Expr<T> > > \
123 OPNAME (const Expr<T>& expr) \
125 typedef OP< Expr<T> > expr_t; \
127 return Expr<expr_t>(expr); \
138 expr.fastAccessDx(i))
144 -expr.fastAccessDx(i))
149 exp(expr.val())*expr.dx(i),
150 exp(expr.val())*expr.fastAccessDx(i))
155 expr.dx(i)/expr.val(),
156 expr.fastAccessDx(i)/expr.val())
161 expr.dx(i)/(
log(value_type(10))*expr.val()),
162 expr.fastAccessDx(i) / (
log(value_type(10))*expr.val()))
167 expr.
dx(i)/(value_type(2)*
sqrt(expr.
val())),
207 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())))
273 #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) \
277 template <typename ExprT1, typename ExprT2> \
280 template <typename ExprT1, typename ExprT2> \
281 struct ExprSpec< OP< ExprT1, ExprT2 > > { \
282 typedef
typename ExprSpec<ExprT1>::type type; \
285 template <typename ExprT1, typename ExprT2> \
286 class Expr< OP< ExprT1, ExprT2 >,ExprSpecDefault > { \
290 typedef
typename ExprT1::value_type value_type_1; \
291 typedef
typename ExprT2::value_type value_type_2; \
293 value_type_2>::type value_type; \
295 typedef
typename ExprT1::scalar_type scalar_type_1; \
296 typedef
typename ExprT2::scalar_type scalar_type_2; \
298 scalar_type_2>::type scalar_type; \
300 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
301 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
303 base_expr_type_2>::type base_expr_type; \
305 KOKKOS_INLINE_FUNCTION \
306 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) : \
307 expr1(expr1_), expr2(expr2_) {} \
309 KOKKOS_INLINE_FUNCTION \
311 int sz1 = expr1.size(), sz2 = expr2.size(); \
312 return sz1 > sz2 ? sz1 : sz2; \
315 KOKKOS_INLINE_FUNCTION \
316 bool hasFastAccess()
const { \
317 return expr1.hasFastAccess() && expr2.hasFastAccess(); \
320 KOKKOS_INLINE_FUNCTION \
321 bool isPassive()
const { \
322 return expr1.isPassive() && expr2.isPassive(); \
325 KOKKOS_INLINE_FUNCTION \
326 bool updateValue()
const { \
327 return expr1.updateValue() && expr2.updateValue(); \
330 KOKKOS_INLINE_FUNCTION \
331 void cache()
const {} \
333 KOKKOS_INLINE_FUNCTION \
334 const value_type
val()
const { \
339 KOKKOS_INLINE_FUNCTION \
340 const value_type
dx(
int i)
const { \
345 KOKKOS_INLINE_FUNCTION \
348 return FASTACCESSDX; \
353 const ExprT1& expr1; \
354 const ExprT2& expr2; \
358 template <typename ExprT1, typename T2> \
359 struct ExprSpec< OP< ExprT1, ConstExpr<T2> > > { \
360 typedef
typename ExprSpec<ExprT1>::type type; \
363 template <typename ExprT1, typename T2> \
364 class Expr< OP< ExprT1, ConstExpr<T2> >,ExprSpecDefault > { \
368 typedef ConstExpr<T2> ConstT; \
369 typedef ConstExpr<T2> ExprT2; \
370 typedef
typename ExprT1::value_type value_type_1; \
371 typedef
typename ExprT2::value_type value_type_2; \
373 value_type_2>::type value_type; \
375 typedef
typename ExprT1::scalar_type scalar_type_1; \
376 typedef
typename ExprT2::scalar_type scalar_type_2; \
378 scalar_type_2>::type scalar_type; \
380 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
381 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
383 base_expr_type_2>::type base_expr_type; \
385 KOKKOS_INLINE_FUNCTION \
386 Expr(
const ExprT1& expr1_,
const ConstT& c_) : \
387 expr1(expr1_),
c(c_) {} \
389 KOKKOS_INLINE_FUNCTION \
391 return expr1.size(); \
394 KOKKOS_INLINE_FUNCTION \
395 bool hasFastAccess()
const { \
396 return expr1.hasFastAccess(); \
399 KOKKOS_INLINE_FUNCTION \
400 bool isPassive()
const { \
401 return expr1.isPassive(); \
404 KOKKOS_INLINE_FUNCTION \
405 bool updateValue()
const {
return expr1.updateValue(); } \
407 KOKKOS_INLINE_FUNCTION \
408 void cache()
const {} \
410 KOKKOS_INLINE_FUNCTION \
411 const value_type
val()
const { \
413 return VAL_CONST_DX_2; \
416 KOKKOS_INLINE_FUNCTION \
417 const value_type
dx(
int i)
const { \
422 KOKKOS_INLINE_FUNCTION \
425 return CONST_FASTACCESSDX_2; \
430 const ExprT1& expr1; \
434 template <typename T1, typename ExprT2> \
435 struct ExprSpec< OP< ConstExpr<T1>, ExprT2 > > { \
436 typedef
typename ExprSpec<ExprT2>::type type; \
439 template <typename T1, typename ExprT2> \
440 class Expr< OP< ConstExpr<T1>, ExprT2 >,ExprSpecDefault > { \
444 typedef ConstExpr<T1> ConstT; \
445 typedef ConstExpr<T1> ExprT1; \
446 typedef
typename ExprT1::value_type value_type_1; \
447 typedef
typename ExprT2::value_type value_type_2; \
449 value_type_2>::type value_type; \
451 typedef
typename ExprT1::scalar_type scalar_type_1; \
452 typedef
typename ExprT2::scalar_type scalar_type_2; \
454 scalar_type_2>::type scalar_type; \
456 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
457 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
459 base_expr_type_2>::type base_expr_type; \
462 KOKKOS_INLINE_FUNCTION \
463 Expr(
const ConstT& c_,
const ExprT2& expr2_) : \
464 c(c_), expr2(expr2_) {} \
466 KOKKOS_INLINE_FUNCTION \
468 return expr2.size(); \
471 KOKKOS_INLINE_FUNCTION \
472 bool hasFastAccess()
const { \
473 return expr2.hasFastAccess(); \
476 KOKKOS_INLINE_FUNCTION \
477 bool isPassive()
const { \
478 return expr2.isPassive(); \
481 KOKKOS_INLINE_FUNCTION \
482 bool updateValue()
const {
return expr2.updateValue(); } \
484 KOKKOS_INLINE_FUNCTION \
485 void cache()
const {} \
487 KOKKOS_INLINE_FUNCTION \
488 const value_type
val()
const { \
490 return VAL_CONST_DX_1; \
493 KOKKOS_INLINE_FUNCTION \
494 const value_type
dx(
int i)
const { \
499 KOKKOS_INLINE_FUNCTION \
502 return CONST_FASTACCESSDX_1; \
508 const ExprT2& expr2; \
511 template <typename T1, typename T2> \
512 KOKKOS_INLINE_FUNCTION \
513 typename mpl::enable_if_c< \
514 ExprLevel< Expr<T1> >::value == ExprLevel< Expr<T2> >::value, \
515 Expr< OP< Expr<T1>, Expr<T2> > > \
518 OPNAME (
const Expr<T1>& expr1,
const Expr<T2>& expr2) \
520 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
522 return Expr<expr_t>(expr1, expr2); \
525 template <typename T> \
526 KOKKOS_INLINE_FUNCTION \
527 Expr< OP< Expr<T>, Expr<T> > > \
528 OPNAME (
const Expr<T>& expr1,
const Expr<T>& expr2) \
530 typedef OP< Expr<T>, Expr<T> > expr_t; \
532 return Expr<expr_t>(expr1, expr2); \
535 template <typename T> \
536 KOKKOS_INLINE_FUNCTION \
537 Expr< OP< ConstExpr<typename Expr<T>::value_type>, \
539 OPNAME (
const typename Expr<T>::value_type&
c, \
540 const Expr<T>& expr) \
542 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
543 typedef OP< ConstT, Expr<T> > expr_t; \
545 return Expr<expr_t>(ConstT(
c), expr); \
548 template <typename T> \
549 KOKKOS_INLINE_FUNCTION \
551 ConstExpr<typename Expr<T>::value_type> > > \
552 OPNAME (
const Expr<T>& expr, \
553 const typename Expr<T>::value_type&
c) \
555 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
556 typedef OP< Expr<T>, ConstT > expr_t; \
558 return Expr<expr_t>(expr, ConstT(
c)); \
561 template <typename T>
\
564 OPNAME (
const typename Expr<T>::scalar_type&
c, \
565 const Expr<T>& expr) \
567 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
568 typedef OP< ConstT, Expr<T> > expr_t; \
570 return Expr<expr_t>(ConstT(
c), expr); \
573 template <typename T>
\
576 OPNAME (
const Expr<T>& expr, \
577 const typename Expr<T>::scalar_type&
c) \
579 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
580 typedef OP< Expr<T>, ConstT > expr_t; \
582 return Expr<expr_t>(expr, ConstT(
c)); \
592 expr1.val() + expr2.val(),
593 expr1.dx(i) + expr2.dx(i),
594 expr1.fastAccessDx(i) + expr2.fastAccessDx(i),
595 c.val() + expr2.val(),
596 expr1.val() +
c.val(),
599 expr2.fastAccessDx(i),
600 expr1.fastAccessDx(i))
604 expr1.val() - expr2.val(),
605 expr1.dx(i) - expr2.dx(i),
606 expr1.fastAccessDx(i) - expr2.fastAccessDx(i),
607 c.val() - expr2.val(),
608 expr1.val() -
c.val(),
611 -expr2.fastAccessDx(i),
612 expr1.fastAccessDx(i))
629 expr1.val() / expr2.val(),
630 (expr1.dx(i)*expr2.val() - expr2.dx(i)*expr1.val()) /
631 (expr2.val()*expr2.val()),
632 (expr1.fastAccessDx(i)*expr2.val() -
633 expr2.fastAccessDx(i)*expr1.val()) /
634 (expr2.val()*expr2.val()),
635 c.val() / expr2.val(),
636 expr1.val() /
c.val(),
637 -expr2.dx(i)*
c.val() / (expr2.val()*expr2.val()),
639 -expr2.fastAccessDx(i)*
c.val() / (expr2.val()*expr2.val()),
640 expr1.fastAccessDx(i)/
c.val())
644 atan2(expr1.val(), expr2.val()),
645 (expr2.val()*expr1.dx(i) - expr1.val()*expr2.dx(i))/
646 (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
647 (expr2.val()*expr1.fastAccessDx(i) - expr1.val()*expr2.fastAccessDx(i))/
648 (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
649 atan2(
c.val(), expr2.val()),
650 atan2(expr1.val(),
c.val()),
651 (-
c.val()*expr2.dx(i)) / (
c.val()*
c.val() + expr2.val()*expr2.val()),
652 (
c.val()*expr1.dx(i))/ (expr1.val()*expr1.val() +
c.val()*
c.val()),
653 (-
c.val()*expr2.fastAccessDx(i))/ (
c.val()*
c.val() + expr2.val()*expr2.val()),
654 (
c.val()*expr1.fastAccessDx(i))/ (expr1.val()*expr1.val() +
c.val()*
c.val()))
693 #undef FAD_BINARYOP_MACRO
698 template <
typename ExprT1,
typename ExprT2>
701 template <
typename ExprT1,
typename ExprT2>
706 template <
typename ExprT1,
typename ExprT2>
711 typedef typename ExprT1::value_type value_type_1;
712 typedef typename ExprT2::value_type value_type_2;
716 typedef typename ExprT1::scalar_type scalar_type_1;
717 typedef typename ExprT2::scalar_type scalar_type_2;
719 scalar_type_2>::type scalar_type;
721 typedef typename ExprT1::base_expr_type base_expr_type_1;
722 typedef typename ExprT2::base_expr_type base_expr_type_2;
724 base_expr_type_2>::type base_expr_type;
727 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) :
728 expr1(expr1_), expr2(expr2_) {}
732 int sz1 = expr1.size(), sz2 = expr2.size();
733 return sz1 > sz2 ? sz1 : sz2;
737 bool hasFastAccess()
const {
738 return expr1.hasFastAccess() && expr2.hasFastAccess();
742 bool isPassive()
const {
743 return expr1.isPassive() && expr2.isPassive();
747 bool updateValue()
const {
748 return expr1.updateValue() && expr2.updateValue();
752 void cache()
const {}
756 return expr1.val()*expr2.val();
761 if (expr1.size() > 0 && expr2.size() > 0)
762 return expr1.val()*expr2.dx(i) + expr1.dx(i)*expr2.val();
763 else if (expr1.size() > 0)
764 return expr1.dx(i)*expr2.val();
766 return expr1.val()*expr2.dx(i);
771 return expr1.val()*expr2.fastAccessDx(i) +
772 expr1.fastAccessDx(i)*expr2.val();
782 template <
typename ExprT1,
typename T2>
787 template <
typename ExprT1,
typename T2>
792 typedef ConstExpr<T2> ConstT;
793 typedef ConstExpr<T2> ExprT2;
794 typedef typename ExprT1::value_type value_type_1;
795 typedef typename ExprT2::value_type value_type_2;
799 typedef typename ExprT1::scalar_type scalar_type_1;
800 typedef typename ExprT2::scalar_type scalar_type_2;
802 scalar_type_2>::type scalar_type;
804 typedef typename ExprT1::base_expr_type base_expr_type_1;
805 typedef typename ExprT2::base_expr_type base_expr_type_2;
807 base_expr_type_2>::type base_expr_type;
810 Expr(
const ExprT1& expr1_,
const ConstT& c_) :
811 expr1(expr1_),
c(c_) {}
819 bool hasFastAccess()
const {
820 return expr1.hasFastAccess();
824 bool isPassive()
const {
825 return expr1.isPassive();
829 bool updateValue()
const {
return expr1.updateValue(); }
832 void cache()
const {}
836 return expr1.val()*
c.val();
841 return expr1.dx(i)*
c.val();
846 return expr1.fastAccessDx(i)*
c.val();
855 template <
typename T1,
typename ExprT2>
860 template <
typename T1,
typename ExprT2>
865 typedef ConstExpr<T1> ConstT;
866 typedef ConstExpr<T1> ExprT1;
867 typedef typename ExprT1::value_type value_type_1;
868 typedef typename ExprT2::value_type value_type_2;
872 typedef typename ExprT1::scalar_type scalar_type_1;
873 typedef typename ExprT2::scalar_type scalar_type_2;
875 scalar_type_2>::type scalar_type;
877 typedef typename ExprT1::base_expr_type base_expr_type_1;
878 typedef typename ExprT2::base_expr_type base_expr_type_2;
880 base_expr_type_2>::type base_expr_type;
883 Expr(
const ConstT& c_,
const ExprT2& expr2_) :
884 c(c_), expr2(expr2_) {}
892 bool hasFastAccess()
const {
893 return expr2.hasFastAccess();
897 bool isPassive()
const {
898 return expr2.isPassive();
902 bool updateValue()
const {
return expr2.updateValue(); }
905 void cache()
const {}
909 return c.val()*expr2.val();
914 return c.val()*expr2.dx(i);
919 return c.val()*expr2.fastAccessDx(i);
928 template <
typename T1,
typename T2>
933 typedef MultiplicationOp< T1, T2 > expr_t;
935 return Expr<expr_t>(expr1, expr2);
938 template <
typename T>
940 Expr< MultiplicationOp< Expr<T>, Expr<T> > >
941 operator* (
const Expr<T>& expr1,
const Expr<T>& expr2)
943 typedef MultiplicationOp< Expr<T>, Expr<T> > expr_t;
945 return Expr<expr_t>(expr1, expr2);
948 template <
typename T>
955 typedef MultiplicationOp< ConstT, Expr<T> > expr_t;
957 return Expr<expr_t>(ConstT(
c), expr);
960 template <
typename T>
967 typedef MultiplicationOp< Expr<T>, ConstT > expr_t;
969 return Expr<expr_t>(expr, ConstT(
c));
972 template <
typename T>
975 operator* (
const typename Expr<T>::scalar_type&
c,
979 typedef MultiplicationOp< ConstT, Expr<T> > expr_t;
981 return Expr<expr_t>(ConstT(
c), expr);
984 template <
typename T>
988 const typename Expr<T>::scalar_type&
c)
991 typedef MultiplicationOp< Expr<T>, ConstT > expr_t;
993 return Expr<expr_t>(expr, ConstT(
c));
1002 #ifdef HAVE_SACADO_CXX11
1007 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1008 class IfThenElseOp {};
1010 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1011 struct ExprSpec< IfThenElseOp< CondT, ExprT1, ExprT2 > > {
1015 template <
typename CondT,
typename ExprT1,
typename ExprT2>
1016 class Expr< IfThenElseOp< CondT, ExprT1, ExprT2 >,ExprSpecDefault > {
1020 typedef typename ExprT1::value_type value_type_1;
1021 typedef typename ExprT2::value_type value_type_2;
1025 typedef typename ExprT1::scalar_type scalar_type_1;
1026 typedef typename ExprT2::scalar_type scalar_type_2;
1028 scalar_type_2>::type scalar_type;
1030 typedef typename ExprT1::base_expr_type base_expr_type_1;
1031 typedef typename ExprT2::base_expr_type base_expr_type_2;
1033 base_expr_type_2>::type base_expr_type;
1036 Expr(
const CondT& cond_,
const ExprT1& expr1_,
const ExprT2& expr2_) :
1037 cond(cond_), expr1(expr1_), expr2(expr2_) {}
1041 int sz1 = expr1.size(), sz2 = expr2.size();
1042 return sz1 > sz2 ? sz1 : sz2;
1046 bool hasFastAccess()
const {
1047 return expr1.hasFastAccess() && expr2.hasFastAccess();
1051 bool isPassive()
const {
1052 return expr1.isPassive() && expr2.isPassive();
1056 bool updateValue()
const {
1057 return expr1.updateValue() && expr2.updateValue();
1061 void cache()
const {}
1078 return if_then_else( cond, expr1.fastAccessDx(i), expr2.fastAccessDx(i) );
1084 const ExprT1& expr1;
1085 const ExprT2& expr2;
1089 template <
typename CondT,
typename ExprT1,
typename T2>
1090 struct ExprSpec< IfThenElseOp< CondT, ExprT1, ConstExpr<
T2> > > {
1094 template <
typename CondT,
typename ExprT1,
typename T2>
1095 class Expr< IfThenElseOp< CondT, ExprT1, ConstExpr<
T2> >,ExprSpecDefault > {
1099 typedef ConstExpr<T2> ConstT;
1100 typedef ConstExpr<T2> ExprT2;
1101 typedef typename ExprT1::value_type value_type_1;
1102 typedef typename ExprT2::value_type value_type_2;
1106 typedef typename ExprT1::scalar_type scalar_type_1;
1107 typedef typename ExprT2::scalar_type scalar_type_2;
1109 scalar_type_2>::type scalar_type;
1111 typedef typename ExprT1::base_expr_type base_expr_type_1;
1112 typedef typename ExprT2::base_expr_type base_expr_type_2;
1114 base_expr_type_2>::type base_expr_type;
1117 Expr(
const CondT& cond_,
const ExprT1& expr1_,
const ConstT& c_) :
1118 cond(cond_), expr1(expr1_),
c(c_) {}
1122 return expr1.size();
1126 bool hasFastAccess()
const {
1127 return expr1.hasFastAccess();
1131 bool isPassive()
const {
1132 return expr1.isPassive();
1136 bool updateValue()
const {
return expr1.updateValue(); }
1139 void cache()
const {}
1162 const ExprT1& expr1;
1166 template <
typename CondT,
typename T1,
typename ExprT2>
1167 struct ExprSpec< IfThenElseOp< CondT, ConstExpr<
T1>, ExprT2 > > {
1171 template <
typename CondT,
typename T1,
typename ExprT2>
1172 class Expr< IfThenElseOp< CondT, ConstExpr<
T1>, ExprT2 >,ExprSpecDefault > {
1176 typedef ConstExpr<T1> ConstT;
1177 typedef ConstExpr<T1> ExprT1;
1178 typedef typename ExprT1::value_type value_type_1;
1179 typedef typename ExprT2::value_type value_type_2;
1183 typedef typename ExprT1::scalar_type scalar_type_1;
1184 typedef typename ExprT2::scalar_type scalar_type_2;
1186 scalar_type_2>::type scalar_type;
1188 typedef typename ExprT1::base_expr_type base_expr_type_1;
1189 typedef typename ExprT2::base_expr_type base_expr_type_2;
1191 base_expr_type_2>::type base_expr_type;
1194 Expr(
const CondT& cond_,
const ConstT& c_,
const ExprT2& expr2_) :
1195 cond(cond_),
c(c_), expr2(expr2_) {}
1199 return expr2.size();
1203 bool hasFastAccess()
const {
1204 return expr2.hasFastAccess();
1208 bool isPassive()
const {
1209 return expr2.isPassive();
1213 bool updateValue()
const {
return expr2.updateValue(); }
1216 void cache()
const {}
1240 const ExprT2& expr2;
1243 template <
typename CondT,
typename T1,
typename T2>
1247 Expr< IfThenElseOp< CondT, T1, T2 > >
1251 typedef IfThenElseOp< CondT, T1, T2 > expr_t;
1253 return Expr<expr_t>(cond, expr1, expr2);
1256 template <
typename CondT,
typename T>
1258 Expr< IfThenElseOp< CondT, Expr<T>, Expr<T> > >
1259 if_then_else (
const CondT& cond,
const Expr<T>& expr1,
const Expr<T>& expr2)
1261 typedef IfThenElseOp< CondT, Expr<T>, Expr<T> > expr_t;
1263 return Expr<expr_t>(cond, expr1, expr2);
1266 template <
typename CondT,
typename T>
1271 const Expr<T>& expr)
1274 typedef IfThenElseOp< CondT, ConstT, Expr<T> > expr_t;
1276 return Expr<expr_t>(cond, ConstT(
c), expr);
1279 template <
typename CondT,
typename T>
1281 Expr< IfThenElseOp< CondT, Expr<T>,
1287 typedef IfThenElseOp< CondT, Expr<T>, ConstT > expr_t;
1289 return Expr<expr_t>(cond, expr, ConstT(
c));
1292 template <
typename CondT,
typename T>
1294 typename mpl::disable_if<
1295 mpl::is_same< typename Expr<T>::value_type,
1296 typename Expr<T>::scalar_type>,
1297 Expr< IfThenElseOp< CondT, ConstExpr<typename Expr<T>::scalar_type>,
1300 if_then_else (
const CondT& cond,
const typename Expr<T>::scalar_type&
c,
1301 const Expr<T>& expr)
1304 typedef IfThenElseOp< CondT, ConstT, Expr<T> > expr_t;
1306 return Expr<expr_t>(cond, ConstT(
c), expr);
1309 template <
typename CondT,
typename T>
1311 typename mpl::disable_if<
1312 mpl::is_same< typename Expr<T>::value_type,
1313 typename Expr<T>::scalar_type>,
1314 Expr< IfThenElseOp< CondT, Expr<T>,
1318 const typename Expr<T>::scalar_type&
c)
1321 typedef IfThenElseOp< CondT, Expr<T>, ConstT > expr_t;
1323 return Expr<expr_t>(cond, expr, ConstT(
c));
1332 #ifdef HAVE_SACADO_CXX11
1336 template <
typename T1,
typename T2 = T1>
1337 struct ConditionalReturnType {
1338 typedef decltype( std::declval<T1>() == std::declval<T2>() ) type;
1343 #define FAD_RELOP_MACRO(OP) \
1344 namespace Sacado { \
1346 template <typename ExprT1, typename ExprT2> \
1347 KOKKOS_INLINE_FUNCTION \
1348 typename ConditionalReturnType<typename Expr<ExprT1>::value_type, \
1349 typename Expr<ExprT2>::value_type>::type \
1350 operator OP (const Expr<ExprT1>& expr1, \
1351 const Expr<ExprT2>& expr2) \
1353 return expr1.val() OP expr2.val(); \
1356 template <typename ExprT2> \
1357 KOKKOS_INLINE_FUNCTION \
1358 typename ConditionalReturnType<typename Expr<ExprT2>::value_type>::type \
1359 operator OP (const typename Expr<ExprT2>::value_type& a, \
1360 const Expr<ExprT2>& expr2) \
1362 return a OP expr2.val(); \
1365 template <typename ExprT1> \
1366 KOKKOS_INLINE_FUNCTION \
1367 typename ConditionalReturnType<typename Expr<ExprT1>::value_type>::type \
1368 operator OP (const Expr<ExprT1>& expr1, \
1369 const typename Expr<ExprT1>::value_type& b) \
1371 return expr1.val() OP b; \
1378 #define FAD_RELOP_MACRO(OP) \
1379 namespace Sacado { \
1381 template <typename ExprT1, typename ExprT2> \
1382 KOKKOS_INLINE_FUNCTION \
1384 operator OP (const Expr<ExprT1>& expr1, \
1385 const Expr<ExprT2>& expr2) \
1387 return expr1.val() OP expr2.val(); \
1390 template <typename ExprT2> \
1391 KOKKOS_INLINE_FUNCTION \
1393 operator OP (const typename Expr<ExprT2>::value_type& a, \
1394 const Expr<ExprT2>& expr2) \
1396 return a OP expr2.val(); \
1399 template <typename ExprT1> \
1400 KOKKOS_INLINE_FUNCTION \
1402 operator OP (const Expr<ExprT1>& expr1, \
1403 const typename Expr<ExprT1>::value_type& b) \
1405 return expr1.val() OP b; \
1423 #undef FAD_RELOP_MACRO
1429 template <
typename ExprT>
1433 return ! expr.val();
1445 template <
typename ExprT>
1448 bool is_zero = (x.val() == 0.0);
1449 for (
int i=0; i<x.size(); i++)
1450 is_zero = is_zero && (x.dx(i) == 0.0);
1458 #define FAD_BOOL_MACRO(OP) \
1459 namespace Sacado { \
1461 template <typename ExprT1, typename ExprT2> \
1462 KOKKOS_INLINE_FUNCTION \
1464 operator OP (const Expr<ExprT1>& expr1, \
1465 const Expr<ExprT2>& expr2) \
1467 return toBool(expr1) OP toBool(expr2); \
1470 template <typename ExprT2> \
1471 KOKKOS_INLINE_FUNCTION \
1473 operator OP (const typename Expr<ExprT2>::value_type& a, \
1474 const Expr<ExprT2>& expr2) \
1476 return a OP toBool(expr2); \
1479 template <typename ExprT1> \
1480 KOKKOS_INLINE_FUNCTION \
1482 operator OP (const Expr<ExprT1>& expr1, \
1483 const typename Expr<ExprT1>::value_type& b) \
1485 return toBool(expr1) OP b; \
1493 #undef FAD_BOOL_MACRO
1501 template <
typename ExprT>
1503 os << x.val() <<
" [";
1505 for (
int i=0; i< x.size(); i++) {
1506 os <<
" " << x.dx(i);
1517 #endif // SACADO_FAD_OPS_HPP