52 #ifndef SACADO_ELRFAD_OPS_HPP
53 #define SACADO_ELRFAD_OPS_HPP
59 #define FAD_UNARYOP_MACRO(OPNAME,OP,VALUE,ADJOINT, \
60 LINEAR,DX,FASTACCESSDX) \
64 template <typename ExprT> \
67 template <typename ExprT> \
68 class Expr< OP<ExprT> > { \
71 typedef typename ExprT::value_type value_type; \
72 typedef typename ExprT::scalar_type scalar_type; \
73 typedef typename ExprT::base_expr_type base_expr_type; \
75 static const int num_args = ExprT::num_args; \
77 static const bool is_linear = LINEAR; \
79 KOKKOS_INLINE_FUNCTION \
80 explicit Expr(const ExprT& expr_) : expr(expr_) {} \
82 KOKKOS_INLINE_FUNCTION \
83 int size() const { return expr.size(); } \
86 KOKKOS_INLINE_FUNCTION \
87 bool isActive() const { return expr.template isActive<Arg>(); } \
89 KOKKOS_INLINE_FUNCTION \
90 bool isActive2(int j) const { return expr.isActive2(j); } \
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 { \
103 KOKKOS_INLINE_FUNCTION \
104 void computePartials(const value_type& bar, \
105 value_type partials[]) const { \
106 expr.computePartials(ADJOINT, partials); \
109 KOKKOS_INLINE_FUNCTION \
110 void getTangents(int i, value_type dots[]) const { \
111 expr.getTangents(i, dots); } \
114 KOKKOS_INLINE_FUNCTION \
115 const value_type& getTangent(int i) const { \
116 return expr.template getTangent<Arg>(i); \
119 KOKKOS_INLINE_FUNCTION \
120 bool isLinear() const { \
124 KOKKOS_INLINE_FUNCTION \
125 bool hasFastAccess() const { \
126 return expr.hasFastAccess(); \
129 KOKKOS_INLINE_FUNCTION \
130 const value_type dx(int i) const { \
134 KOKKOS_INLINE_FUNCTION \
135 const value_type fastAccessDx(int i) const { \
136 return FASTACCESSDX; \
139 KOKKOS_INLINE_FUNCTION \
140 const value_type* getDx(int j) const { \
141 return expr.getDx(j); \
144 KOKKOS_INLINE_FUNCTION \
145 int numActiveArgs() const { \
146 return expr.numActiveArgs(); \
149 KOKKOS_INLINE_FUNCTION \
150 void computeActivePartials(const value_type& bar, \
151 value_type *partials) const { \
152 expr.computePartials(ADJOINT, partials); \
160 template <typename T> \
161 KOKKOS_INLINE_FUNCTION \
162 Expr< OP< Expr<T> > > \
163 OPNAME (const Expr<T>& expr) \
165 typedef OP< Expr<T> > expr_t; \
167 return Expr<expr_t>(expr); \
178 expr.fastAccessDx(i))
185 -expr.fastAccessDx(i))
192 std::exp(expr.val())*expr.fastAccessDx(i))
198 expr.dx(i)/expr.val(),
199 expr.fastAccessDx(i)/expr.val())
206 expr.fastAccessDx(i) / (
std::log(value_type(10))*expr.val()))
209 std::sqrt(expr.
val()),
210 value_type(0.5)*
bar/std::sqrt(expr.val()),
212 expr.
dx(i)/(value_type(2)* std::sqrt(expr.val())),
213 expr.
fastAccessDx(i)/(value_type(2)* std::sqrt(expr.val())))
216 std::sqrt(expr.val()),
217 expr.val() == value_type(0.0) ? value_type(0.0) : value_type(value_type(0.5)*
bar/std::sqrt(expr.val())),
219 expr.val() == value_type(0.0) ? value_type(0.0) : value_type(expr.
dx(i)/(value_type(2)*std::sqrt(expr.val()))),
220 expr.val() == value_type(0.0) ? value_type(0.0) : value_type(expr.
fastAccessDx(i)/(value_type(2)*std::sqrt(expr.val()))))
223 std::cos(expr.val()),
224 -
bar*std::
sin(expr.val()),
226 -expr.
dx(i)* std::
sin(expr.val()),
230 std::sin(expr.val()),
231 bar*std::cos(expr.val()),
233 expr.
dx(i)* std::cos(expr.val()),
237 std::tan(expr.val()),
238 bar*(value_type(1.)+ std::tan(expr.val())*std::tan(expr.val())),
241 (value_type(1)+ std::tan(expr.val())* std::tan(expr.val())),
243 (value_type(1)+ std::tan(expr.val())* std::tan(expr.val())))
246 std::acos(expr.val()),
247 -
bar/std::sqrt(value_type(1.)-expr.val()*expr.val()),
249 -expr.
dx(i)/ std::sqrt(value_type(1)-expr.val()*expr.val()),
251 std::sqrt(value_type(1)-expr.val()*expr.val()))
254 std::asin(expr.val()),
255 bar/std::sqrt(value_type(1.)-expr.val()*expr.val()),
257 expr.
dx(i)/ std::sqrt(value_type(1)-expr.val()*expr.val()),
259 std::sqrt(value_type(1)-expr.val()*expr.val()))
262 std::atan(expr.val()),
263 bar/(value_type(1.)+expr.val()*expr.val()),
265 expr.
dx(i)/(value_type(1)+expr.val()*expr.val()),
266 expr.
fastAccessDx(i)/(value_type(1)+expr.val()*expr.val()))
269 std::cosh(expr.val()),
272 expr.
dx(i)* std::
sinh(expr.val()),
276 std::sinh(expr.val()),
277 bar*std::cosh(expr.val()),
279 expr.
dx(i)* std::cosh(expr.val()),
283 std::tanh(expr.val()),
284 bar*(value_type(1)-std::tanh(expr.val())*std::tanh(expr.val())),
286 expr.
dx(i)*(value_type(1)-std::tanh(expr.val())*std::tanh(expr.val())),
287 expr.
fastAccessDx(i)*(value_type(1)-std::tanh(expr.val())*std::tanh(expr.val())))
290 std::acosh(expr.val()),
291 bar/std::sqrt((expr.val()-value_type(1.)) *
292 (expr.val()+value_type(1.))),
294 expr.
dx(i)/ std::sqrt((expr.val()-value_type(1)) *
295 (expr.val()+value_type(1))),
296 expr.
fastAccessDx(i)/ std::sqrt((expr.val()-value_type(1)) *
297 (expr.val()+value_type(1))))
300 std::asinh(expr.val()),
301 bar/std::sqrt(value_type(1.)+expr.val()*expr.val()),
303 expr.
dx(i)/ std::sqrt(value_type(1)+expr.val()*expr.val()),
305 expr.val()*expr.val()))
308 std::atanh(expr.val()),
309 bar/(value_type(1.)-expr.val()*expr.val()),
311 expr.
dx(i)/(value_type(1)-expr.val()*expr.val()),
313 expr.val()*expr.val()))
316 std::abs(expr.val()),
317 (expr.val() >= value_type(0.)) ?
bar : value_type(-
bar),
319 expr.val() >= 0 ? value_type(+expr.
dx(i)) :
320 value_type(-expr.
dx(i)),
325 std::fabs(expr.val()),
326 (expr.val() >= value_type(0.)) ? bar : value_type(-bar),
328 expr.val() >= 0 ? value_type(+expr.
dx(i)) :
329 value_type(-expr.
dx(i)),
332 #ifdef HAVE_SACADO_CXX11
336 bar/(value_type(3)*
std::cbrt(expr.val()*expr.val())),
338 expr.dx(i)/(value_type(3)*
std::cbrt(expr.val()*expr.val())),
339 expr.fastAccessDx(i)/(value_type(3)*
std::cbrt(expr.val()*expr.val())))
345 OPNAME,OP,VALUE,LADJOINT,RADJOINT, \
346 LINEAR,CONST_LINEAR_1, CONST_LINEAR_2, \
347 LINEAR_2,CONST_LINEAR_1_2, CONST_LINEAR_2_2, \
348 DX,FASTACCESSDX,CONST_DX_1,CONST_DX_2, \
349 CONST_FASTACCESSDX_1,CONST_FASTACCESSDX_2) \
353 template <typename ExprT1, typename ExprT2> \
356 template <typename ExprT1, typename ExprT2> \
357 class Expr< OP<ExprT1,ExprT2> > { \
361 typedef
typename ExprT1::value_type value_type_1; \
362 typedef
typename ExprT2::value_type value_type_2; \
364 value_type_2>::type value_type; \
366 typedef
typename ExprT1::scalar_type scalar_type_1; \
367 typedef
typename ExprT2::scalar_type scalar_type_2; \
369 scalar_type_2>::type scalar_type; \
371 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
372 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
374 base_expr_type_2>::type base_expr_type; \
376 static
const int num_args1 = ExprT1::num_args; \
377 static
const int num_args2 = ExprT2::num_args; \
378 static
const int num_args = num_args1 + num_args2; \
380 static
const bool is_linear = LINEAR_2; \
382 KOKKOS_INLINE_FUNCTION \
383 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) : \
384 expr1(expr1_), expr2(expr2_) {} \
386 KOKKOS_INLINE_FUNCTION \
388 int sz1 = expr1.size(), sz2 = expr2.size(); \
389 return sz1 > sz2 ? sz1 : sz2; \
393 KOKKOS_INLINE_FUNCTION \
394 bool isActive()
const {
\
395 if (Arg < num_args1) \
396 return expr1.template isActive<Arg>(); \
398 return expr2.template isActive<Arg-num_args1>(); \
401 KOKKOS_INLINE_FUNCTION \
402 bool isActive2(
int j)
const {
\
404 return expr1.isActive2(j); \
406 return expr2.isActive2(j); \
409 KOKKOS_INLINE_FUNCTION \
410 bool updateValue()
const { \
411 return expr1.updateValue() && expr2.updateValue(); \
415 void cache()
const {} \
417 KOKKOS_INLINE_FUNCTION \
418 value_type
val()
const { \
423 void computePartials(
const value_type& bar, \
424 value_type partials[])
const {
\
426 expr1.computePartials(LADJOINT, partials);
\
428 expr2.computePartials(RADJOINT, partials+num_args1); \
432 void getTangents(
int i, value_type dots[])
const { \
433 expr1.getTangents(i, dots); \
434 expr2.getTangents(i, dots+num_args1); \
438 KOKKOS_INLINE_FUNCTION \
439 const value_type& getTangent(
int i)
const {
\
440 if (Arg < num_args1) \
441 return expr1.template getTangent<Arg>(i); \
443 return expr2.template getTangent<Arg-num_args1>(i); \
446 KOKKOS_INLINE_FUNCTION \
447 bool isLinear()
const { \
451 KOKKOS_INLINE_FUNCTION \
452 bool hasFastAccess()
const { \
453 return expr1.hasFastAccess() && expr2.hasFastAccess(); \
456 KOKKOS_INLINE_FUNCTION \
457 const value_type
dx(
int i)
const { \
461 KOKKOS_INLINE_FUNCTION \
463 return FASTACCESSDX; \
466 KOKKOS_INLINE_FUNCTION \
467 const value_type* getDx(
int j)
const {
\
469 return expr1.getDx(j); \
471 return expr2.getDx(j-num_args1); \
474 KOKKOS_INLINE_FUNCTION \
475 int numActiveArgs()
const { \
476 return expr1.numActiveArgs() + expr2.numActiveArgs(); \
480 void computeActivePartials(
const value_type& bar, \
481 value_type *partials)
const {
\
482 if (expr1.numActiveArgs() > 0) \
483 expr1.computePartials(LADJOINT, partials);
\
484 if (expr2.numActiveArgs() > 0) \
485 expr2.computePartials(RADJOINT, partials+expr2.numActiveArgs()); \
489 typename ExprConstRef<ExprT1>::type expr1; \
490 typename ExprConstRef<ExprT2>::type expr2; \
494 template <typename ExprT1, typename T2> \
495 class Expr< OP<ExprT1, ConstExpr<T2> > > { \
499 typedef ConstExpr<T2> ExprT2; \
500 typedef
typename ExprT1::value_type value_type_1; \
501 typedef
typename ExprT2::value_type value_type_2; \
503 value_type_2>::type value_type; \
505 typedef
typename ExprT1::scalar_type scalar_type_1; \
506 typedef
typename ExprT2::scalar_type scalar_type_2; \
508 scalar_type_2>::type scalar_type; \
510 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
511 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
513 base_expr_type_2>::type base_expr_type; \
515 static
const int num_args = ExprT1::num_args; \
517 static
const bool is_linear = CONST_LINEAR_2_2; \
519 KOKKOS_INLINE_FUNCTION \
520 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) : \
521 expr1(expr1_), expr2(expr2_) {} \
523 KOKKOS_INLINE_FUNCTION \
525 return expr1.size(); \
529 KOKKOS_INLINE_FUNCTION \
530 bool isActive()
const { \
531 return expr1.template isActive<Arg>(); \
534 KOKKOS_INLINE_FUNCTION \
535 bool isActive2(
int j)
const {
return expr1.isActive2(j); } \
537 KOKKOS_INLINE_FUNCTION \
538 bool updateValue()
const { \
539 return expr1.updateValue(); \
543 void cache()
const {} \
545 KOKKOS_INLINE_FUNCTION \
546 value_type
val()
const { \
551 void computePartials(
const value_type& bar, \
552 value_type partials[])
const { \
553 expr1.computePartials(LADJOINT, partials); \
557 void getTangents(
int i, value_type dots[])
const { \
558 expr1.getTangents(i, dots); \
562 KOKKOS_INLINE_FUNCTION \
563 const value_type& getTangent(
int i)
const { \
564 return expr1.template getTangent<Arg>(i); \
567 KOKKOS_INLINE_FUNCTION \
568 bool isLinear()
const { \
569 return CONST_LINEAR_2; \
572 KOKKOS_INLINE_FUNCTION \
573 bool hasFastAccess()
const { \
574 return expr1.hasFastAccess(); \
577 KOKKOS_INLINE_FUNCTION \
578 const value_type
dx(
int i)
const { \
582 KOKKOS_INLINE_FUNCTION \
584 return CONST_FASTACCESSDX_2; \
587 KOKKOS_INLINE_FUNCTION \
588 const value_type* getDx(
int j)
const { \
589 return expr1.getDx(j); \
592 KOKKOS_INLINE_FUNCTION \
593 int numActiveArgs()
const { \
594 return expr1.numActiveArgs(); \
598 void computeActivePartials(
const value_type& bar, \
599 value_type *partials)
const { \
600 expr1.computePartials(LADJOINT, partials); \
605 typename ExprConstRef<ExprT1>::type expr1; \
606 typename ExprConstRef<ExprT2>::type expr2; \
610 template <typename T1, typename ExprT2> \
611 class Expr< OP<ConstExpr<T1>,ExprT2> > { \
615 typedef ConstExpr<T1> ExprT1; \
616 typedef
typename ExprT1::value_type value_type_1; \
617 typedef
typename ExprT2::value_type value_type_2; \
619 value_type_2>::type value_type; \
621 typedef
typename ExprT1::scalar_type scalar_type_1; \
622 typedef
typename ExprT2::scalar_type scalar_type_2; \
624 scalar_type_2>::type scalar_type; \
626 typedef
typename ExprT1::base_expr_type base_expr_type_1; \
627 typedef
typename ExprT2::base_expr_type base_expr_type_2; \
629 base_expr_type_2>::type base_expr_type; \
631 static
const int num_args = ExprT2::num_args; \
633 static
const bool is_linear = CONST_LINEAR_1_2; \
635 KOKKOS_INLINE_FUNCTION \
636 Expr(
const ExprT1& expr1_,
const ExprT2& expr2_) : \
637 expr1(expr1_), expr2(expr2_) {} \
639 KOKKOS_INLINE_FUNCTION \
641 return expr2.size(); \
645 KOKKOS_INLINE_FUNCTION \
646 bool isActive()
const { \
647 return expr2.template isActive<Arg>(); \
650 KOKKOS_INLINE_FUNCTION \
651 bool isActive2(
int j)
const {
return expr2.isActive2(j); } \
653 KOKKOS_INLINE_FUNCTION \
654 bool updateValue()
const { \
655 return expr2.updateValue(); \
659 void cache()
const {} \
661 KOKKOS_INLINE_FUNCTION \
662 value_type
val()
const { \
667 void computePartials(
const value_type& bar, \
668 value_type partials[])
const { \
669 expr2.computePartials(RADJOINT, partials); \
673 void getTangents(
int i, value_type dots[])
const { \
674 expr2.getTangents(i, dots); \
678 KOKKOS_INLINE_FUNCTION \
679 const value_type& getTangent(
int i)
const { \
680 return expr2.template getTangent<Arg>(i); \
683 KOKKOS_INLINE_FUNCTION \
684 bool isLinear()
const { \
685 return CONST_LINEAR_1; \
688 KOKKOS_INLINE_FUNCTION \
689 bool hasFastAccess()
const { \
690 return expr2.hasFastAccess(); \
693 KOKKOS_INLINE_FUNCTION \
694 const value_type
dx(
int i)
const { \
698 KOKKOS_INLINE_FUNCTION \
700 return CONST_FASTACCESSDX_1; \
703 KOKKOS_INLINE_FUNCTION \
704 const value_type* getDx(
int j)
const { \
705 return expr2.getDx(j); \
708 KOKKOS_INLINE_FUNCTION \
709 int numActiveArgs()
const { \
710 return expr2.numActiveArgs(); \
714 void computeActivePartials(
const value_type& bar, \
715 value_type *partials)
const { \
716 expr2.computePartials(RADJOINT, partials); \
720 typename ExprConstRef<ExprT1>::type expr1; \
721 typename ExprConstRef<ExprT2>::type expr2; \
725 template <typename T1, typename T2>
\
728 OPNAME (
const T1& expr1,
const T2& expr2) \
730 typedef OP< T1, T2 > expr_t; \
732 return Expr<expr_t>(expr1, expr2); \
735 template <typename T> \
736 KOKKOS_INLINE_FUNCTION \
737 Expr< OP< Expr<T>, Expr<T> > > \
738 OPNAME (
const Expr<T>& expr1,
const Expr<T>& expr2) \
740 typedef OP< Expr<T>, Expr<T> > expr_t; \
742 return Expr<expr_t>(expr1, expr2); \
745 template <typename T> \
746 KOKKOS_INLINE_FUNCTION \
747 Expr< OP< ConstExpr<typename Expr<T>::value_type>, \
749 OPNAME (
const typename Expr<T>::value_type&
c, \
750 const Expr<T>& expr) \
752 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
753 typedef OP< ConstT, Expr<T> > expr_t; \
755 return Expr<expr_t>(ConstT(c), expr); \
758 template <typename T> \
759 KOKKOS_INLINE_FUNCTION \
761 ConstExpr<typename Expr<T>::value_type> > > \
762 OPNAME (
const Expr<T>& expr, \
763 const typename Expr<T>::value_type& c) \
765 typedef ConstExpr<typename Expr<T>::value_type> ConstT; \
766 typedef OP< Expr<T>, ConstT > expr_t; \
768 return Expr<expr_t>(expr, ConstT(c)); \
771 template <typename T>
\
774 OPNAME (
const typename Expr<T>::scalar_type& c, \
775 const Expr<T>& expr) \
777 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
778 typedef OP< ConstT, Expr<T> > expr_t; \
780 return Expr<expr_t>(ConstT(c), expr); \
783 template <typename T>
\
786 OPNAME (
const Expr<T>& expr, \
787 const typename Expr<T>::scalar_type& c) \
789 typedef ConstExpr<typename Expr<T>::scalar_type> ConstT; \
790 typedef OP< Expr<T>, ConstT > expr_t; \
792 return Expr<expr_t>(expr, ConstT(c)); \
800 expr1.val() + expr2.val(),
803 expr1.isLinear() && expr2.isLinear(),
806 ExprT1::is_linear && ExprT2::is_linear,
809 expr1.dx(i) + expr2.dx(i),
810 expr1.fastAccessDx(i) + expr2.fastAccessDx(i),
813 expr2.fastAccessDx(i),
814 expr1.fastAccessDx(i))
817 expr1.val() - expr2.val(),
820 expr1.isLinear() && expr2.isLinear(),
823 ExprT1::is_linear && ExprT2::is_linear,
826 expr1.dx(i) - expr2.dx(i),
827 expr1.fastAccessDx(i) - expr2.fastAccessDx(i),
830 -expr2.fastAccessDx(i),
831 expr1.fastAccessDx(i))
834 expr1.val() * expr2.val(),
843 expr1.val()*expr2.dx(i) + expr1.dx(i)*expr2.val(),
844 expr1.val()*expr2.fastAccessDx(i) +
845 expr1.fastAccessDx(i)*expr2.val(),
846 expr1.val()*expr2.dx(i),
847 expr1.dx(i)*expr2.val(),
848 expr1.val()*expr2.fastAccessDx(i),
849 expr1.fastAccessDx(i)*expr2.val())
852 expr1.val() / expr2.val(),
854 -bar*expr1.val()/(expr2.val()*expr2.val()),
861 (expr1.dx(i)*expr2.val() - expr2.dx(i)*expr1.val()) /
862 (expr2.val()*expr2.val()),
863 (expr1.fastAccessDx(i)*expr2.val() -
864 expr2.fastAccessDx(i)*expr1.val()) /
865 (expr2.val()*expr2.val()),
866 -expr2.dx(i)*expr1.val() / (expr2.val()*expr2.val()),
867 expr1.dx(i)/expr2.val(),
868 -expr2.fastAccessDx(i)*expr1.val() / (expr2.val()*expr2.val()),
869 expr1.fastAccessDx(i)/expr2.val())
874 (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
876 (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
883 (expr2.val()*expr1.dx(i) - expr1.val()*expr2.dx(i))/ (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
884 (expr2.val()*expr1.fastAccessDx(i) - expr1.val()*expr2.fastAccessDx(i))/
885 (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
886 (-expr1.val()*expr2.dx(i)) / (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
887 (expr2.val()*expr1.dx(i))/ (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
888 (-expr1.val()*expr2.fastAccessDx(i))/ (expr1.val()*expr1.val() + expr2.val()*expr2.val()),
889 (expr2.val()*expr1.fastAccessDx(i))/ (expr1.val()*expr1.val() + expr2.val()*expr2.val()))
892 std::pow(expr1.val(), expr2.val()),
893 expr1.val() == value_type(0) ? value_type(0) : value_type(bar*std::pow(expr1.val(),expr2.val())*expr2.val()/expr1.val()),
894 expr1.val() == value_type(0) ? value_type(0) : value_type(bar*std::pow(expr1.val(),expr2.val())*std::
log(expr1.val())),
901 expr1.val() == value_type(0) ? value_type(0) : value_type((expr2.
dx(i)*std::
log(expr1.val())+expr2.val()*expr1.
dx(i)/expr1.val())*std::pow(expr1.val(),expr2.val())),
902 expr1.val() == value_type(0) ? value_type(0.0) : value_type((expr2.
fastAccessDx(i)*std::
log(expr1.val())+expr2.val()*expr1.
fastAccessDx(i)/expr1.val())*std::pow(expr1.val(),expr2.val())),
903 expr1.val() == value_type(0) ? value_type(0) : value_type(expr2.
dx(i)*std::
log(expr1.val())*std::pow(expr1.val(),expr2.val())),
904 expr1.val() == value_type(0.0) ? value_type(0.0) : value_type(expr2.val()*expr1.
dx(i)/expr1.val()*std::pow(expr1.val(),expr2.val())),
905 expr1.val() == value_type(0) ? value_type(0) : value_type(expr2.
fastAccessDx(i)*std::
log(expr1.val())*std::pow(expr1.val(),expr2.val())),
906 expr1.val() == value_type(0.0) ? value_type(0.0) : value_type(expr2.val()*expr1.
fastAccessDx(i)/expr1.val()*std::pow(expr1.val(),expr2.val())))
909 expr1.val() >= expr2.val() ? expr1.val() : expr2.val(),
910 expr1.val() >= expr2.val() ? bar : value_type(0.),
911 expr2.val() > expr1.val() ? bar : value_type(0.),
912 expr1.isLinear() && expr2.isLinear(),
915 ExprT1::is_linear && ExprT2::is_linear,
918 expr1.val() >= expr2.val() ? expr1.
dx(i) : expr2.
dx(i),
921 expr1.val() >= expr2.val() ? value_type(0) : expr2.
dx(i),
922 expr1.val() >= expr2.val() ? expr1.
dx(i) : value_type(0),
923 expr1.val() >= expr2.val() ? value_type(0) :
929 expr1.val() <= expr2.val() ? expr1.val() : expr2.val(),
930 expr1.val() <= expr2.val() ? bar : value_type(0.),
931 expr2.val() < expr1.val() ? bar : value_type(0.),
932 expr1.isLinear() && expr2.isLinear(),
935 ExprT1::is_linear && ExprT2::is_linear,
938 expr1.val() <= expr2.val() ? expr1.
dx(i) : expr2.
dx(i),
941 expr1.val() <= expr2.val() ? value_type(0) : expr2.
dx(i),
942 expr1.val() <= expr2.val() ? expr1.
dx(i) : value_type(0),
943 expr1.val() <= expr2.val() ? value_type(0) :
948 #undef FAD_BINARYOP_MACRO
952 #define FAD_RELOP_MACRO(OP) \
955 template <typename ExprT1, typename ExprT2> \
956 KOKKOS_INLINE_FUNCTION \
958 operator OP (const Expr<ExprT1>& expr1, \
959 const Expr<ExprT2>& expr2) \
961 return expr1.val() OP expr2.val(); \
964 template <typename ExprT2> \
965 KOKKOS_INLINE_FUNCTION \
967 operator OP (const typename Expr<ExprT2>::value_type& a, \
968 const Expr<ExprT2>& expr2) \
970 return a OP expr2.val(); \
973 template <typename ExprT1> \
974 KOKKOS_INLINE_FUNCTION \
976 operator OP (const Expr<ExprT1>& expr1, \
977 const typename Expr<ExprT1>::value_type& b) \
979 return expr1.val() OP b; \
995 #undef FAD_RELOP_MACRO
1001 template <
typename ExprT>
1005 return ! expr.val();
1017 template <
typename ExprT>
1020 bool is_zero = (x.val() == 0.0);
1021 for (
int i=0; i<x.size(); i++)
1022 is_zero = is_zero && (x.dx(i) == 0.0);
1030 #define FAD_BOOL_MACRO(OP) \
1031 namespace Sacado { \
1032 namespace ELRFad { \
1033 template <typename ExprT1, typename ExprT2> \
1034 KOKKOS_INLINE_FUNCTION \
1036 operator OP (const Expr<ExprT1>& expr1, \
1037 const Expr<ExprT2>& expr2) \
1039 return toBool(expr1) OP toBool(expr2); \
1042 template <typename ExprT2> \
1043 KOKKOS_INLINE_FUNCTION \
1045 operator OP (const typename Expr<ExprT2>::value_type& a, \
1046 const Expr<ExprT2>& expr2) \
1048 return a OP toBool(expr2); \
1051 template <typename ExprT1> \
1052 KOKKOS_INLINE_FUNCTION \
1054 operator OP (const Expr<ExprT1>& expr1, \
1055 const typename Expr<ExprT1>::value_type& b) \
1057 return toBool(expr1) OP b; \
1065 #undef FAD_BOOL_MACRO
1073 template <
typename ExprT>
1074 std::ostream& operator << (std::ostream& os, const Expr<ExprT>& x) {
1075 os << x.val() <<
" [";
1077 for (
int i=0; i< x.size(); i++) {
1078 os <<
" " << x.dx(i);
1089 #endif // SACADO_FAD_OPS_HPP
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MaxOp
#define FAD_UNARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, FASTACCESSDX)
#define FAD_BOOL_MACRO(OP)
#define SACADO_FAD_OP_ENABLE_EXPR_EXPR(OP)
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MinOp
#define SACADO_FAD_OP_ENABLE_SCALAR_EXPR(OP)
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< ExprT > &expr)
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 MultiplicationOp
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)
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 expr1 expr1 c *expr2 expr1 c *expr2 expr1 c *expr2 expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 Atan2Op
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION T safe_sqrt(const T &x)
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
#define FAD_BINARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, CDX1, CDX2, FASTACCESSDX, VAL_CONST_DX_1, VAL_CONST_DX_2, CONST_DX_1, CONST_DX_2, CONST_FASTACCESSDX_1, CONST_FASTACCESSDX_2)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< ExprT > &x)
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 expr1 expr1 c *expr2 expr1 c *expr2 expr1 c *expr2 expr1 DivisionOp
atan2(expr1.val(), expr2.val())
#define FAD_RELOP_MACRO(OP)
Wrapper for a generic expression template.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
#define SACADO_FAD_OP_ENABLE_EXPR_SCALAR(OP)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
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