33 #ifndef SACADO_LFAD_LOGICALSPARSEOPS_HPP
34 #define SACADO_LFAD_LOGICALSPARSEOPS_HPP
40 #define FAD_UNARYOP_MACRO(OPNAME,OP,VALUE) \
44 template <typename ExprT> \
47 template <typename ExprT> \
48 class Expr< OP<ExprT> > { \
51 typedef typename ExprT::value_type value_type; \
52 typedef typename ExprT::scalar_type scalar_type; \
53 typedef typename ExprT::base_expr_type base_expr_type; \
54 typedef typename ExprT::logical_type logical_type; \
56 Expr(const ExprT& expr_) : expr(expr_) {} \
58 int size() const { return expr.size(); } \
60 bool hasFastAccess() const { return expr.hasFastAccess(); } \
62 bool isPassive() const { return expr.isPassive();} \
64 value_type val() const { \
68 logical_type dx(int i) const { \
72 logical_type fastAccessDx(int i) const { \
73 return expr.fastAccessDx(i); \
81 template <typename T> \
82 inline Expr< OP< Expr<T> > > \
83 OPNAME (const Expr<T>& expr) \
85 typedef OP< Expr<T> > expr_t; \
87 return Expr<expr_t>(expr); \
103 std::log(expr.
val()))
106 std::log10(expr.
val()))
109 std::sqrt(expr.
val()))
112 std::cos(expr.
val()))
115 std::sin(expr.
val()))
118 std::tan(expr.
val()))
121 std::acos(expr.
val()))
124 std::asin(expr.
val()))
127 std::atan(expr.
val()))
130 std::cosh(expr.
val()))
133 std::sinh(expr.
val()))
136 std::tanh(expr.
val()))
148 std::abs(expr.
val()))
151 std::fabs(expr.
val()))
154 std::cbrt(expr.
val()))
156 #undef FAD_UNARYOP_MACRO
158 #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) \
162 template <typename ExprT1, typename ExprT2> \
165 template <typename T1, typename T2> \
166 class Expr< OP< Expr<T1>, Expr<T2> > > { \
170 typedef Expr<T1> ExprT1; \
171 typedef Expr<T2> ExprT2; \
172 typedef typename ExprT1::value_type value_type_1; \
173 typedef typename ExprT2::value_type value_type_2; \
174 typedef typename Sacado::Promote<value_type_1, \
175 value_type_2>::type value_type; \
177 typedef typename ExprT1::scalar_type scalar_type_1; \
178 typedef typename ExprT2::scalar_type scalar_type_2; \
179 typedef typename Sacado::Promote<scalar_type_1, \
180 scalar_type_2>::type scalar_type; \
182 typedef typename ExprT1::base_expr_type base_expr_type_1; \
183 typedef typename ExprT2::base_expr_type base_expr_type_2; \
184 typedef typename Sacado::Promote<base_expr_type_1, \
185 base_expr_type_2>::type base_expr_type; \
187 typedef typename ExprT1::logical_type logical_type; \
189 Expr(const ExprT1& expr1_, const ExprT2& expr2_) : \
190 expr1(expr1_), expr2(expr2_) {} \
193 int sz1 = expr1.size(), sz2 = expr2.size(); \
194 return sz1 > sz2 ? sz1 : sz2; \
197 bool hasFastAccess() const { \
198 return expr1.hasFastAccess() && expr2.hasFastAccess(); \
201 bool isPassive() const { \
202 return expr1.isPassive() && expr2.isPassive(); \
205 const value_type val() const { \
209 const logical_type dx(int i) const { \
213 const logical_type fastAccessDx(int i) const { \
214 return FASTACCESSDX; \
219 const ExprT1& expr1; \
220 const ExprT2& expr2; \
224 template <typename T1> \
225 class Expr< OP< Expr<T1>, typename Expr<T1>::value_type> > { \
229 typedef Expr<T1> ExprT1; \
230 typedef typename ExprT1::value_type value_type; \
231 typedef typename ExprT1::scalar_type scalar_type; \
232 typedef typename ExprT1::base_expr_type base_expr_type; \
233 typedef typename ExprT1::value_type ConstT; \
234 typedef typename ExprT1::logical_type logical_type; \
236 Expr(const ExprT1& expr1_, const ConstT& c_) : \
237 expr1(expr1_), c(c_) {} \
240 return expr1.size(); \
243 bool hasFastAccess() const { \
244 return expr1.hasFastAccess(); \
247 bool isPassive() const { \
248 return expr1.isPassive(); \
251 const value_type val() const { \
252 return VAL_CONST_DX_2; \
255 const logical_type dx(int i) const { \
259 const logical_type fastAccessDx(int i) const { \
260 return CONST_FASTACCESSDX_2; \
265 const ExprT1& expr1; \
269 template <typename T2> \
270 class Expr< OP< typename Expr<T2>::value_type, Expr<T2> > > { \
274 typedef Expr<T2> ExprT2; \
275 typedef typename ExprT2::value_type value_type; \
276 typedef typename ExprT2::scalar_type scalar_type; \
277 typedef typename ExprT2::base_expr_type base_expr_type; \
278 typedef typename ExprT2::value_type ConstT; \
279 typedef typename ExprT2::logical_type logical_type; \
281 Expr(const ConstT& c_, const ExprT2& expr2_) : \
282 c(c_), expr2(expr2_) {} \
285 return expr2.size(); \
288 bool hasFastAccess() const { \
289 return expr2.hasFastAccess(); \
292 bool isPassive() const { \
293 return expr2.isPassive(); \
296 const value_type val() const { \
297 return VAL_CONST_DX_1; \
300 const logical_type dx(int i) const { \
304 const logical_type fastAccessDx(int i) const { \
305 return CONST_FASTACCESSDX_1; \
311 const ExprT2& expr2; \
314 template <typename T1, typename T2> \
315 inline Expr< OP< Expr<T1>, Expr<T2> > > \
316 OPNAME (const Expr<T1>& expr1, const Expr<T2>& expr2) \
318 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
320 return Expr<expr_t>(expr1, expr2); \
323 template <typename T> \
324 inline Expr< OP< Expr<T>, Expr<T> > > \
325 OPNAME (const Expr<T>& expr1, const Expr<T>& expr2) \
327 typedef OP< Expr<T>, Expr<T> > expr_t; \
329 return Expr<expr_t>(expr1, expr2); \
332 template <typename T> \
333 inline Expr< OP< typename Expr<T>::value_type, Expr<T> > > \
334 OPNAME (const typename Expr<T>::value_type& c, \
335 const Expr<T>& expr) \
337 typedef typename Expr<T>::value_type ConstT; \
338 typedef OP< ConstT, Expr<T> > expr_t; \
340 return Expr<expr_t>(c, expr); \
343 template <typename T> \
344 inline Expr< OP< Expr<T>, typename Expr<T>::value_type > > \
345 OPNAME (const Expr<T>& expr, \
346 const typename Expr<T>::value_type& c) \
348 typedef typename Expr<T>::value_type ConstT; \
349 typedef OP< Expr<T>, ConstT > expr_t; \
351 return Expr<expr_t>(expr, c); \
359 expr1.val() + expr2.val(),
360 expr1.dx(
i) || expr2.dx(
i),
361 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
366 expr2.fastAccessDx(
i),
367 expr1.fastAccessDx(
i))
370 expr1.val() - expr2.val(),
371 expr1.dx(
i) || expr2.dx(
i),
372 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
377 expr2.fastAccessDx(
i),
378 expr1.fastAccessDx(
i))
381 expr1.val() * expr2.val(),
382 expr1.dx(
i) || expr2.dx(
i),
383 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
388 expr2.fastAccessDx(
i),
389 expr1.fastAccessDx(
i))
392 expr1.val() / expr2.val(),
393 expr1.dx(
i) || expr2.dx(
i),
394 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
399 expr2.fastAccessDx(
i),
400 expr1.fastAccessDx(
i))
404 expr1.dx(
i) || expr2.dx(
i),
405 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
410 expr2.fastAccessDx(
i),
411 expr1.fastAccessDx(
i))
415 expr1.dx(
i) || expr2.dx(
i),
416 expr1.fastAccessDx(
i) || expr2.fastAccessDx(
i),
421 expr2.fastAccessDx(
i),
422 expr1.fastAccessDx(
i))
426 expr1.val() >= expr2.val() ? expr1.dx(
i) : expr2.dx(
i),
427 expr1.val() >= expr2.val() ? expr1.fastAccessDx(
i) :
428 expr2.fastAccessDx(
i),
431 c >= expr2.val() ? logical_type(0) : expr2.
dx(
i),
432 expr1.
val() >=
c ? expr1.
dx(
i) : logical_type(0),
443 c <= expr2.
val() ? logical_type(0) : expr2.
dx(
i),
444 expr1.
val() <=
c ? expr1.
dx(
i) : logical_type(0),
455 template <typename ExprT1, typename ExprT2> \
457 operator OP (
const Expr<ExprT1>& expr1, \
458 const Expr<ExprT2>& expr2) \
460 return expr1.val() OP expr2.val(); \
463 template <typename ExprT2> \
465 operator OP (
const typename Expr<ExprT2>::value_type&
a, \
466 const Expr<ExprT2>& expr2) \
468 return a OP expr2.val(); \
471 template <typename ExprT1> \
473 operator OP (
const Expr<ExprT1>& expr1, \
474 const typename Expr<ExprT1>::value_type& b) \
476 return expr1.val() OP b; \
492 #undef FAD_RELOP_MACRO
498 template <
typename ExprT>
499 inline bool operator ! (
const Expr<ExprT>& expr)
513 template <
typename ExprT>
514 bool toBool(
const Expr<ExprT>&
x) {
515 bool is_zero = (x.val() == 0.0);
516 for (
int i=0;
i<x.size();
i++)
517 is_zero = is_zero && (x.dx(
i) == 0.0);
525 #define FAD_BOOL_MACRO(OP) \
528 template <typename ExprT1, typename ExprT2> \
530 operator OP (const Expr<ExprT1>& expr1, \
531 const Expr<ExprT2>& expr2) \
533 return toBool(expr1) OP toBool(expr2); \
536 template <typename ExprT2> \
538 operator OP (const typename Expr<ExprT2>::value_type& a, \
539 const Expr<ExprT2>& expr2) \
541 return a OP toBool(expr2); \
544 template <typename ExprT1> \
546 operator OP (const Expr<ExprT1>& expr1, \
547 const typename Expr<ExprT1>::value_type& b) \
549 return toBool(expr1) OP b; \
557 #undef FAD_BOOL_MACRO
565 template <
typename ExprT>
566 std::ostream& operator << (std::ostream& os, const Expr<ExprT>&
x) {
567 os << x.val() <<
" [";
569 for (
int i=0;
i< x.size();
i++) {
570 os <<
" " << x.dx(
i);
582 #endif // SACADO_LFAD_LOGICALSPARSEOPS_HPP
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 MaxOp
SACADO_INLINE_FUNCTION bool operator!(const Expr< ExprT > &expr)
#define FAD_UNARYOP_MACRO(OPNAME, OP, USING, VALUE, DX, FASTACCESSDX)
expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 MultiplicationOp
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
SACADO_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SACADO_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)
#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