52 #ifndef SACADO_LFAD_LOGICALSPARSEOPS_HPP
53 #define SACADO_LFAD_LOGICALSPARSEOPS_HPP
59 #define FAD_UNARYOP_MACRO(OPNAME,OP,VALUE) \
63 template <typename ExprT> \
66 template <typename ExprT> \
67 class Expr< OP<ExprT> > { \
70 typedef typename ExprT::value_type value_type; \
71 typedef typename ExprT::scalar_type scalar_type; \
72 typedef typename ExprT::base_expr_type base_expr_type; \
73 typedef typename ExprT::logical_type logical_type; \
75 Expr(const ExprT& expr_) : expr(expr_) {} \
77 int size() const { return expr.size(); } \
79 bool hasFastAccess() const { return expr.hasFastAccess(); } \
81 bool isPassive() const { return expr.isPassive();} \
83 value_type val() const { \
87 logical_type dx(int i) const { \
91 logical_type fastAccessDx(int i) const { \
92 return expr.fastAccessDx(i); \
100 template <typename T> \
101 inline Expr< OP< Expr<T> > > \
102 OPNAME (const Expr<T>& expr) \
104 typedef OP< Expr<T> > expr_t; \
106 return Expr<expr_t>(expr); \
122 std::log(expr.
val()))
125 std::log10(expr.
val()))
128 std::sqrt(expr.
val()))
131 std::cos(expr.
val()))
134 std::sin(expr.
val()))
137 std::tan(expr.
val()))
140 std::acos(expr.
val()))
143 std::asin(expr.
val()))
146 std::atan(expr.
val()))
149 std::cosh(expr.
val()))
152 std::sinh(expr.
val()))
155 std::tanh(expr.
val()))
167 std::abs(expr.
val()))
170 std::fabs(expr.
val()))
171 #ifdef HAVE_SACADO_CXX11
177 #undef FAD_UNARYOP_MACRO
179 #define FAD_BINARYOP_MACRO(OPNAME,OP,VALUE,DX,FASTACCESSDX,VAL_CONST_DX_1,VAL_CONST_DX_2,CONST_DX_1,CONST_DX_2,CONST_FASTACCESSDX_1,CONST_FASTACCESSDX_2) \
183 template <typename ExprT1, typename ExprT2> \
186 template <typename T1, typename T2> \
187 class Expr< OP< Expr<T1>, Expr<T2> > > { \
191 typedef Expr<T1> ExprT1; \
192 typedef Expr<T2> ExprT2; \
193 typedef typename ExprT1::value_type value_type_1; \
194 typedef typename ExprT2::value_type value_type_2; \
195 typedef typename Sacado::Promote<value_type_1, \
196 value_type_2>::type value_type; \
198 typedef typename ExprT1::scalar_type scalar_type_1; \
199 typedef typename ExprT2::scalar_type scalar_type_2; \
200 typedef typename Sacado::Promote<scalar_type_1, \
201 scalar_type_2>::type scalar_type; \
203 typedef typename ExprT1::base_expr_type base_expr_type_1; \
204 typedef typename ExprT2::base_expr_type base_expr_type_2; \
205 typedef typename Sacado::Promote<base_expr_type_1, \
206 base_expr_type_2>::type base_expr_type; \
208 typedef typename ExprT1::logical_type logical_type; \
210 Expr(const ExprT1& expr1_, const ExprT2& expr2_) : \
211 expr1(expr1_), expr2(expr2_) {} \
214 int sz1 = expr1.size(), sz2 = expr2.size(); \
215 return sz1 > sz2 ? sz1 : sz2; \
218 bool hasFastAccess() const { \
219 return expr1.hasFastAccess() && expr2.hasFastAccess(); \
222 bool isPassive() const { \
223 return expr1.isPassive() && expr2.isPassive(); \
226 const value_type val() const { \
230 const logical_type dx(int i) const { \
234 const logical_type fastAccessDx(int i) const { \
235 return FASTACCESSDX; \
240 const ExprT1& expr1; \
241 const ExprT2& expr2; \
245 template <typename T1> \
246 class Expr< OP< Expr<T1>, typename Expr<T1>::value_type> > { \
250 typedef Expr<T1> ExprT1; \
251 typedef typename ExprT1::value_type value_type; \
252 typedef typename ExprT1::scalar_type scalar_type; \
253 typedef typename ExprT1::base_expr_type base_expr_type; \
254 typedef typename ExprT1::value_type ConstT; \
255 typedef typename ExprT1::logical_type logical_type; \
257 Expr(const ExprT1& expr1_, const ConstT& c_) : \
258 expr1(expr1_), c(c_) {} \
261 return expr1.size(); \
264 bool hasFastAccess() const { \
265 return expr1.hasFastAccess(); \
268 bool isPassive() const { \
269 return expr1.isPassive(); \
272 const value_type val() const { \
273 return VAL_CONST_DX_2; \
276 const logical_type dx(int i) const { \
280 const logical_type fastAccessDx(int i) const { \
281 return CONST_FASTACCESSDX_2; \
286 const ExprT1& expr1; \
290 template <typename T2> \
291 class Expr< OP< typename Expr<T2>::value_type, Expr<T2> > > { \
295 typedef Expr<T2> ExprT2; \
296 typedef typename ExprT2::value_type value_type; \
297 typedef typename ExprT2::scalar_type scalar_type; \
298 typedef typename ExprT2::base_expr_type base_expr_type; \
299 typedef typename ExprT2::value_type ConstT; \
300 typedef typename ExprT2::logical_type logical_type; \
302 Expr(const ConstT& c_, const ExprT2& expr2_) : \
303 c(c_), expr2(expr2_) {} \
306 return expr2.size(); \
309 bool hasFastAccess() const { \
310 return expr2.hasFastAccess(); \
313 bool isPassive() const { \
314 return expr2.isPassive(); \
317 const value_type val() const { \
318 return VAL_CONST_DX_1; \
321 const logical_type dx(int i) const { \
325 const logical_type fastAccessDx(int i) const { \
326 return CONST_FASTACCESSDX_1; \
332 const ExprT2& expr2; \
335 template <typename T1, typename T2> \
336 inline Expr< OP< Expr<T1>, Expr<T2> > > \
337 OPNAME (const Expr<T1>& expr1, const Expr<T2>& expr2) \
339 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
341 return Expr<expr_t>(expr1, expr2); \
344 template <typename T> \
345 inline Expr< OP< Expr<T>, Expr<T> > > \
346 OPNAME (const Expr<T>& expr1, const Expr<T>& expr2) \
348 typedef OP< Expr<T>, Expr<T> > expr_t; \
350 return Expr<expr_t>(expr1, expr2); \
353 template <typename T> \
354 inline Expr< OP< typename Expr<T>::value_type, Expr<T> > > \
355 OPNAME (const typename Expr<T>::value_type& c, \
356 const Expr<T>& expr) \
358 typedef typename Expr<T>::value_type ConstT; \
359 typedef OP< ConstT, Expr<T> > expr_t; \
361 return Expr<expr_t>(c, expr); \
364 template <typename T> \
365 inline Expr< OP< Expr<T>, typename Expr<T>::value_type > > \
366 OPNAME (const Expr<T>& expr, \
367 const typename Expr<T>::value_type& c) \
369 typedef typename Expr<T>::value_type ConstT; \
370 typedef OP< Expr<T>, ConstT > expr_t; \
372 return Expr<expr_t>(expr, c); \
380 expr1.val() + expr2.val(),
381 expr1.dx(i) || expr2.dx(i),
382 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
387 expr2.fastAccessDx(i),
388 expr1.fastAccessDx(i))
391 expr1.val() - expr2.val(),
392 expr1.dx(i) || expr2.dx(i),
393 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
398 expr2.fastAccessDx(i),
399 expr1.fastAccessDx(i))
402 expr1.val() * expr2.val(),
403 expr1.dx(i) || expr2.dx(i),
404 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
409 expr2.fastAccessDx(i),
410 expr1.fastAccessDx(i))
413 expr1.val() / expr2.val(),
414 expr1.dx(i) || expr2.dx(i),
415 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
420 expr2.fastAccessDx(i),
421 expr1.fastAccessDx(i))
425 expr1.dx(i) || expr2.dx(i),
426 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
431 expr2.fastAccessDx(i),
432 expr1.fastAccessDx(i))
436 expr1.dx(i) || expr2.dx(i),
437 expr1.fastAccessDx(i) || expr2.fastAccessDx(i),
442 expr2.fastAccessDx(i),
443 expr1.fastAccessDx(i))
447 expr1.val() >= expr2.val() ? expr1.dx(i) : expr2.dx(i),
448 expr1.val() >= expr2.val() ? expr1.fastAccessDx(i) :
449 expr2.fastAccessDx(i),
452 c >= expr2.val() ? logical_type(0) : expr2.
dx(i),
453 expr1.
val() >=
c ? expr1.
dx(i) : logical_type(0),
459 expr1.
val() <= expr2.
val() ? expr1.
dx(i) : expr2.
dx(i),
464 c <= expr2.
val() ? logical_type(0) : expr2.
dx(i),
465 expr1.
val() <=
c ? expr1.
dx(i) : logical_type(0),
476 template <typename ExprT1, typename ExprT2> \
478 operator OP (
const Expr<ExprT1>& expr1, \
479 const Expr<ExprT2>& expr2) \
481 return expr1.val() OP expr2.val(); \
484 template <typename ExprT2> \
486 operator OP (
const typename Expr<ExprT2>::value_type&
a, \
487 const Expr<ExprT2>& expr2) \
489 return a OP expr2.val(); \
492 template <typename ExprT1> \
494 operator OP (
const Expr<ExprT1>& expr1, \
495 const typename Expr<ExprT1>::value_type& b) \
497 return expr1.val() OP b; \
513 #undef FAD_RELOP_MACRO
519 template <
typename ExprT>
520 inline bool operator ! (
const Expr<ExprT>& expr)
534 template <
typename ExprT>
535 bool toBool(
const Expr<ExprT>& x) {
536 bool is_zero = (x.val() == 0.0);
537 for (
int i=0; i<x.size(); i++)
538 is_zero = is_zero && (x.dx(i) == 0.0);
546 #define FAD_BOOL_MACRO(OP) \
549 template <typename ExprT1, typename ExprT2> \
551 operator OP (const Expr<ExprT1>& expr1, \
552 const Expr<ExprT2>& expr2) \
554 return toBool(expr1) OP toBool(expr2); \
557 template <typename ExprT2> \
559 operator OP (const typename Expr<ExprT2>::value_type& a, \
560 const Expr<ExprT2>& expr2) \
562 return a OP toBool(expr2); \
565 template <typename ExprT1> \
567 operator OP (const Expr<ExprT1>& expr1, \
568 const typename Expr<ExprT1>::value_type& b) \
570 return toBool(expr1) OP b; \
578 #undef FAD_BOOL_MACRO
586 template <
typename ExprT>
587 std::ostream& operator << (std::ostream& os, const Expr<ExprT>& x) {
588 os << x.val() <<
" [";
590 for (
int i=0; i< x.size(); i++) {
591 os <<
" " << x.dx(i);
603 #endif // SACADO_LFAD_LOGICALSPARSEOPS_HPP
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MaxOp
#define FAD_UNARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, FASTACCESSDX)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MinOp
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
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)
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
#define FAD_RELOP_MACRO(OP)
atan2(expr1.val(), expr2.val())
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define FAD_BOOL_MACRO(OP)
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