Debian Codegraph @

packages/stokhos/src/sacado/Sacado_ETPCE_OrthogPolyOps.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef SACADO_ETPCE_ORTHOGPOLY_OPS_HPP
11 #define SACADO_ETPCE_ORTHOGPOLY_OPS_HPP
12
13 #include "Sacado_cmath.hpp"
14 #include <ostream> // for std::ostream
15
16 #define LINEAR_PCE_UNARYOP_MACRO(OPNAME,OP,OPER) \
17 namespace Sacado { \
18 namespace ETPCE { \
19 \
20 template <typename ExprT> \
21 class OP {}; \
22 \
23 template <typename ExprT> \
24 class Expr< OP<ExprT> > { \
25 public: \
26 \
27 typedef typename ExprT::value_type value_type; \
28 typedef typename ExprT::approx_type approx_type; \
29 typedef typename ExprT::expansion_type expansion_type; \
30 typedef typename ExprT::quad_expansion_type quad_expansion_type; \
31 typedef typename ExprT::storage_type storage_type; \
32 typedef typename ExprT::base_expr_type base_expr_type; \
33 \
34 static const int num_args = ExprT::num_args; \
35 \
36 Expr(const ExprT& expr_) : expr(expr_) {} \
37 \
38 std::string name() const { \
39 return std::string(#OPER) + expr.name(); \
40 } \
41 \
42 int size() const { return expr.size(); } \
43 \
44 const approx_type& getArg(int i) const { return expr.getArg(i); } \
45 \
46 bool has_nonconst_expansion() const { \
47 return expr.has_nonconst_expansion(); \
48 } \
49 \
50 Teuchos::RCP<expansion_type> expansion() const { \
51 return expr.expansion(); \
52 } \
53 \
54 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
55 return expr.quad_expansion(); \
56 } \
57 \
58 bool has_fast_access(int sz) const { return expr.has_fast_access(sz); } \
59 \
60 int order() const { return expr.order(); } \
61 \
62 value_type val() const { return OPER (expr.val()); } \
63 \
64 value_type fast_higher_order_coeff(int i) const { \
65 return OPER (expr.fast_higher_order_coeff(i)); \
66 } \
67 \
68 value_type higher_order_coeff(int i) const { \
69 return OPER (expr.higher_order_coeff(i)); \
70 } \
71 \
72 template <int offset, typename tuple_type> \
73 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
74 return OPER (expr.template eval_sample<offset,tuple_type>(x)); \
75 } \
76 \
77 protected: \
78 \
79 const ExprT& expr; \
80 \
81 }; \
82 \
83 template <typename T> \
84 inline Expr< OP< Expr<T> > > \
85 OPNAME (const Expr<T>& expr) \
86 { \
87 typedef OP< Expr<T> > expr_t; \
88 \
89 return Expr<expr_t>(expr); \
90 } \
91 } \
92 }
93
94 #define NONLINEAR_PCE_UNARYOP_MACRO(OPNAME,OP,OPER) \
95 namespace Sacado { \
96 namespace ETPCE { \
97 \
98 template <typename ExprT> \
99 class OP {}; \
100 \
101 template <typename ExprT> \
102 class Expr< OP<ExprT> > { \
103 public: \
104 \
105 typedef typename ExprT::value_type value_type; \
106 typedef typename ExprT::approx_type approx_type; \
107 typedef typename ExprT::expansion_type expansion_type; \
108 typedef typename ExprT::quad_expansion_type quad_expansion_type; \
109 typedef typename ExprT::storage_type storage_type; \
110 typedef typename ExprT::base_expr_type base_expr_type; \
111 \
112 static const int num_args = ExprT::num_args; \
113 \
114 Expr(const ExprT& expr_) : expr(expr_) {} \
115 \
116 std::string name() const { \
117 return std::string(#OPER) + std::string("(") + expr.name() + \
118 std::string(")"); \
119 } \
120 \
121 int size() const { \
122 if (expr.size() == 1) \
123 return 1; \
124 else \
125 return expansion()->size(); \
126 } \
127 \
128 const approx_type& getArg(int i) const { return expr.getArg(i); } \
129 \
130 bool has_nonconst_expansion() const { \
131 return expr.has_nonconst_expansion(); \
132 } \
133 \
134 Teuchos::RCP<expansion_type> expansion() const { \
135 return expr.expansion(); \
136 } \
137 \
138 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
139 return expr.quad_expansion(); \
140 } \
141 \
142 bool has_fast_access(int sz) const { return false; } \
143 \
144 int order() const { return size() == 0 ? 0 : 100; } \
145 \
146 value_type val() const { return OPER (expr.val()); } \
147 \
148 value_type fast_higher_order_coeff(int i) const { \
149 return value_type(0); \
150 } \
151 \
152 value_type higher_order_coeff(int i) const { \
153 return value_type(0); \
154 } \
155 \
156 template <int offset, typename tuple_type> \
157 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
158 return OPER (expr.template eval_sample<offset,tuple_type>(x)); \
159 } \
160 \
161 protected: \
162 \
163 const ExprT& expr; \
164 \
165 }; \
166 \
167 template <typename T> \
168 inline Expr< OP< Expr<T> > > \
169 OPNAME (const Expr<T>& expr) \
170 { \
171 typedef OP< Expr<T> > expr_t; \
172 \
173 return Expr<expr_t>(expr); \
174 } \
175 } \
176 }
177
178 LINEAR_PCE_UNARYOP_MACRO(operator+, UnaryPlusOp, +)
179 LINEAR_PCE_UNARYOP_MACRO(operator-, UnaryMinusOp, -)
180
181 NONLINEAR_PCE_UNARYOP_MACRO(exp, ExpOp, std::exp)
182 NONLINEAR_PCE_UNARYOP_MACRO(log, LogOp, std::log)
183 NONLINEAR_PCE_UNARYOP_MACRO(log10, Log10Op, std::log10)
184 NONLINEAR_PCE_UNARYOP_MACRO(sqrt, SqrtOp, std::sqrt)
185 NONLINEAR_PCE_UNARYOP_MACRO(cbrt, CbrtOp, std::cbrt)
186 NONLINEAR_PCE_UNARYOP_MACRO(cos, CosOp, std::cos)
187 NONLINEAR_PCE_UNARYOP_MACRO(sin, SinOp, std::sin)
188 NONLINEAR_PCE_UNARYOP_MACRO(tan, TanOp, std::tan)
189 NONLINEAR_PCE_UNARYOP_MACRO(acos, ACosOp, std::acos)
190 NONLINEAR_PCE_UNARYOP_MACRO(asin, ASinOp, std::asin)
191 NONLINEAR_PCE_UNARYOP_MACRO(atan, ATanOp, std::atan)
192 NONLINEAR_PCE_UNARYOP_MACRO(cosh, CoshOp, std::cosh)
193 NONLINEAR_PCE_UNARYOP_MACRO(sinh, SinhOp, std::sinh)
194 NONLINEAR_PCE_UNARYOP_MACRO(tanh, TanhOp, std::tanh)
195 NONLINEAR_PCE_UNARYOP_MACRO(acosh, ACoshOp, std::acosh)
196 NONLINEAR_PCE_UNARYOP_MACRO(asinh, ASinhOp, std::asinh)
197 NONLINEAR_PCE_UNARYOP_MACRO(atanh, ATanhOp, std::atanh)
198 NONLINEAR_PCE_UNARYOP_MACRO(abs, AbsOp, std::abs)
199 NONLINEAR_PCE_UNARYOP_MACRO(fabs, FAbsOp, std::fabs)
200
201 #undef LINEAR_PCE_UNARYOP_MACRO
202 #undef NONLINEAR_PCE_UNARYOP_MACRO
203
204 #define LINEAR_PCE_BINARYOP_MACRO(OPNAME,OP,OPER) \
205 namespace Sacado { \
206 namespace ETPCE { \
207 \
208 template <typename ExprT1, typename ExprT2> \
209 class OP {}; \
210 \
211 template <typename T1, typename T2> \
212 class Expr< OP< Expr<T1>, Expr<T2> > > { \
213 \
214 public: \
215 \
216 typedef Expr<T1> ExprT1; \
217 typedef Expr<T2> ExprT2; \
218 typedef typename ExprT1::value_type value_type_1; \
219 typedef typename ExprT2::value_type value_type_2; \
220 typedef typename Sacado::Promote<value_type_1, \
221 value_type_2>::type value_type; \
222 \
223 typedef typename ExprT1::approx_type approx_type; \
224 typedef typename ExprT1::expansion_type expansion_type; \
225 typedef typename ExprT1::quad_expansion_type quad_expansion_type; \
226 typedef typename ExprT1::storage_type storage_type; \
227 typedef typename ExprT1::base_expr_type base_expr_type; \
228 \
229 static const int num_args1 = ExprT1::num_args; \
230 static const int num_args2 = ExprT2::num_args; \
231 static const int num_args = num_args1 + num_args2; \
232 \
233 Expr(const ExprT1& expr1_, const ExprT2& expr2_) : \
234 expr1(expr1_), expr2(expr2_) {} \
235 \
236 std::string name() const { \
237 return expr1.name() + std::string(#OPER) + expr2.name(); \
238 } \
239 \
240 int size() const { \
241 int sz1 = expr1.size(), sz2 = expr2.size(); \
242 return sz1 > sz2 ? sz1 : sz2; \
243 } \
244 \
245 const approx_type& getArg(int i) const { \
246 if (i < num_args1) \
247 return expr1.getArg(i); \
248 else \
249 return expr2.getArg(i-num_args1); \
250 } \
251 \
252 bool has_nonconst_expansion() const { \
253 return expr1.has_nonconst_expansion() || \
254 expr2.has_nonconst_expansion(); \
255 } \
256 \
257 Teuchos::RCP<expansion_type> expansion() const { \
258 return expr1.has_nonconst_expansion() ? expr1.expansion() : \
259 expr2.expansion(); \
260 } \
261 \
262 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
263 return expr1.quad_expansion() != Teuchos::null ? \
264 expr1.quad_expansion() : \
265 expr2.quad_expansion(); \
266 } \
267 \
268 bool has_fast_access(int sz) const { \
269 return expr1.has_fast_access(sz) && expr2.has_fast_access(sz); \
270 } \
271 \
272 int order() const { \
273 int o1 = expr1.order(), o2 = expr2.order(); \
274 return o1 > o2 ? o1 : o2; \
275 } \
276 \
277 value_type val() const { \
278 return expr1.val() OPER expr2.val(); \
279 } \
280 \
281 value_type fast_higher_order_coeff(int i) const { \
282 return expr1.fast_higher_order_coeff(i) OPER \
283 expr2.fast_higher_order_coeff(i); \
284 } \
285 \
286 value_type higher_order_coeff(int i) const { \
287 return expr1.higher_order_coeff(i) OPER \
288 expr2.higher_order_coeff(i); \
289 } \
290 \
291 template <int offset, typename tuple_type> \
292 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
293 return expr1.template eval_sample<offset,tuple_type>(x) OPER \
294 expr2.template eval_sample<offset+num_args1,tuple_type>(x); \
295 } \
296 \
297 protected: \
298 \
299 const ExprT1& expr1; \
300 const ExprT2& expr2; \
301 \
302 }; \
303 \
304 template <typename T1> \
305 class Expr< OP< Expr<T1>, typename Expr<T1>::value_type> > { \
306 \
307 public: \
308 \
309 typedef Expr<T1> ExprT1; \
310 typedef typename ExprT1::value_type value_type; \
311 typedef typename ExprT1::value_type ConstT; \
312 \
313 typedef typename ExprT1::approx_type approx_type; \
314 typedef typename ExprT1::expansion_type expansion_type; \
315 typedef typename ExprT1::quad_expansion_type quad_expansion_type; \
316 typedef typename ExprT1::storage_type storage_type; \
317 typedef typename ExprT1::base_expr_type base_expr_type; \
318 \
319 static const int num_args = ExprT1::num_args; \
320 \
321 Expr(const ExprT1& expr1_, const ConstT& c_) : \
322 expr1(expr1_), c(c_) {} \
323 \
324 std::string name() const { \
325 return expr1.name() + std::string(#OPER) + std::string("c"); \
326 } \
327 \
328 int size() const { return expr1.size(); } \
329 \
330 const approx_type& getArg(int i) const { \
331 return expr1.getArg(i); \
332 } \
333 \
334 bool has_nonconst_expansion() const { \
335 return expr1.has_nonconst_expansion(); \
336 } \
337 \
338 Teuchos::RCP<expansion_type> expansion() const { \
339 return expr1.expansion(); \
340 } \
341 \
342 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
343 return expr1.quad_expansion(); \
344 } \
345 \
346 bool has_fast_access(int sz) const { return expr1.has_fast_access(sz); } \
347 \
348 int order() const { return expr1.order(); } \
349 \
350 value_type val() const { \
351 return expr1.val() OPER c; \
352 } \
353 \
354 value_type fast_higher_order_coeff(int i) const { \
355 return expr1.fast_higher_order_coeff(i); \
356 } \
357 \
358 value_type higher_order_coeff(int i) const { \
359 return expr1.higher_order_coeff(i); \
360 } \
361 \
362 template <int offset, typename tuple_type> \
363 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
364 return expr1.template eval_sample<offset,tuple_type>(x) OPER c; \
365 } \
366 \
367 protected: \
368 \
369 const ExprT1& expr1; \
370 const ConstT& c; \
371 }; \
372 \
373 template <typename T2> \
374 class Expr< OP< typename Expr<T2>::value_type, Expr<T2> > > { \
375 \
376 public: \
377 \
378 typedef Expr<T2> ExprT2; \
379 typedef typename ExprT2::value_type value_type; \
380 typedef typename ExprT2::value_type ConstT; \
381 \
382 typedef typename ExprT2::approx_type approx_type; \
383 typedef typename ExprT2::expansion_type expansion_type; \
384 typedef typename ExprT2::quad_expansion_type quad_expansion_type; \
385 typedef typename ExprT2::storage_type storage_type; \
386 typedef typename ExprT2::base_expr_type base_expr_type; \
387 \
388 static const int num_args = ExprT2::num_args; \
389 \
390 Expr(const ConstT& c_, const ExprT2& expr2_) : \
391 c(c_), expr2(expr2_) {} \
392 \
393 std::string name() const { \
394 return std::string("c") + std::string(#OPER) + expr2.name(); \
395 } \
396 \
397 int size() const { return expr2.size(); } \
398 \
399 const approx_type& getArg(int i) const { return expr2.getArg(i); } \
400 \
401 bool has_nonconst_expansion() const { \
402 return expr2.has_nonconst_expansion(); \
403 } \
404 \
405 Teuchos::RCP<expansion_type> expansion() const { \
406 return expr2.expansion(); \
407 } \
408 \
409 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
410 return expr2.quad_expansion(); \
411 } \
412 \
413 bool has_fast_access(int sz) const { return expr2.has_fast_access(sz); } \
414 \
415 int order() const { return expr2.order(); } \
416 \
417 value_type val() const { \
418 return c OPER expr2.val(); \
419 } \
420 \
421 value_type fast_higher_order_coeff(int i) const { \
422 return OPER expr2.fast_higher_order_coeff(i); \
423 } \
424 \
425 value_type higher_order_coeff(int i) const { \
426 return OPER expr2.higher_order_coeff(i); \
427 } \
428 \
429 template <int offset, typename tuple_type> \
430 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
431 return c OPER expr2.template eval_sample<offset,tuple_type>(x); \
432 } \
433 \
434 protected: \
435 \
436 const ConstT& c; \
437 const ExprT2& expr2; \
438 }; \
439 \
440 template <typename T1, typename T2> \
441 inline Expr< OP< Expr<T1>, Expr<T2> > > \
442 OPNAME (const Expr<T1>& expr1, const Expr<T2>& expr2) \
443 { \
444 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
445 \
446 return Expr<expr_t>(expr1, expr2); \
447 } \
448 \
449 template <typename T> \
450 inline Expr< OP< Expr<T>, Expr<T> > > \
451 OPNAME (const Expr<T>& expr1, const Expr<T>& expr2) \
452 { \
453 typedef OP< Expr<T>, Expr<T> > expr_t; \
454 \
455 return Expr<expr_t>(expr1, expr2); \
456 } \
457 \
458 template <typename T> \
459 inline Expr< OP< typename Expr<T>::value_type, Expr<T> > > \
460 OPNAME (const typename Expr<T>::value_type& c, \
461 const Expr<T>& expr) \
462 { \
463 typedef typename Expr<T>::value_type ConstT; \
464 typedef OP< ConstT, Expr<T> > expr_t; \
465 \
466 return Expr<expr_t>(c, expr); \
467 } \
468 \
469 template <typename T> \
470 inline Expr< OP< Expr<T>, typename Expr<T>::value_type > > \
471 OPNAME (const Expr<T>& expr, \
472 const typename Expr<T>::value_type& c) \
473 { \
474 typedef typename Expr<T>::value_type ConstT; \
475 typedef OP< Expr<T>, ConstT > expr_t; \
476 \
477 return Expr<expr_t>(expr, c); \
478 } \
479 } \
480 }
481
482 #define NONLINEAR_PCE_BINARYOP_MACRO(OPNAME,OP,OPER) \
483 namespace Sacado { \
484 namespace ETPCE { \
485 \
486 template <typename ExprT1, typename ExprT2> \
487 class OP {}; \
488 \
489 template <typename T1, typename T2> \
490 class Expr< OP< Expr<T1>, Expr<T2> > > { \
491 \
492 public: \
493 \
494 typedef Expr<T1> ExprT1; \
495 typedef Expr<T2> ExprT2; \
496 typedef typename ExprT1::value_type value_type_1; \
497 typedef typename ExprT2::value_type value_type_2; \
498 typedef typename Sacado::Promote<value_type_1, \
499 value_type_2>::type value_type; \
500 \
501 typedef typename ExprT1::approx_type approx_type; \
502 typedef typename ExprT1::expansion_type expansion_type; \
503 typedef typename ExprT1::quad_expansion_type quad_expansion_type; \
504 typedef typename ExprT1::storage_type storage_type; \
505 typedef typename ExprT1::base_expr_type base_expr_type; \
506 \
507 static const int num_args1 = ExprT1::num_args; \
508 static const int num_args2 = ExprT2::num_args; \
509 static const int num_args = num_args1 + num_args2; \
510 \
511 Expr(const ExprT1& expr1_, const ExprT2& expr2_) : \
512 expr1(expr1_), expr2(expr2_) {} \
513 \
514 std::string name() const { \
515 return std::string(#OPER) + std::string("(") + expr1.name() + \
516 std::string(",") + expr2.name() + std::string(")"); \
517 } \
518 \
519 int size() const { \
520 if (expr1.size() == 1 && expr2.size() == 1) \
521 return 1; \
522 else \
523 return expansion()->size(); \
524 } \
525 \
526 const approx_type& getArg(int i) const { \
527 if (i < num_args1) \
528 return expr1.getArg(i); \
529 else \
530 return expr2.getArg(i-num_args1); \
531 } \
532 \
533 bool has_nonconst_expansion() const { \
534 return expr1.has_nonconst_expansion() || \
535 expr2.has_nonconst_expansion(); \
536 } \
537 \
538 Teuchos::RCP<expansion_type> expansion() const { \
539 return expr1.has_nonconst_expansion() ? expr1.expansion() : \
540 expr2.expansion(); \
541 } \
542 \
543 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
544 return expr1.quad_expansion() != Teuchos::null ? \
545 expr1.quad_expansion() : \
546 expr2.quad_expansion(); \
547 } \
548 \
549 bool has_fast_access(int sz) const { return false; } \
550 \
551 int order() const { return size() == 0 ? 0 : 100; } \
552 \
553 value_type val() const { \
554 return OPER (expr1.val(), expr2.val()); \
555 } \
556 \
557 value_type fast_higher_order_coeff(int i) const { \
558 return value_type(0); \
559 } \
560 \
561 value_type higher_order_coeff(int i) const { \
562 return value_type(0); \
563 } \
564 \
565 template <int offset, typename tuple_type> \
566 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
567 return OPER (expr1.template eval_sample<offset,tuple_type>(x), \
568 expr2.template eval_sample<offset+num_args1,tuple_type>(x)); \
569 } \
570 \
571 protected: \
572 \
573 const ExprT1& expr1; \
574 const ExprT2& expr2; \
575 \
576 }; \
577 \
578 template <typename T1> \
579 class Expr< OP< Expr<T1>, typename Expr<T1>::value_type> > { \
580 \
581 public: \
582 \
583 typedef Expr<T1> ExprT1; \
584 typedef typename ExprT1::value_type value_type; \
585 typedef typename ExprT1::value_type ConstT; \
586 \
587 typedef typename ExprT1::approx_type approx_type; \
588 typedef typename ExprT1::expansion_type expansion_type; \
589 typedef typename ExprT1::quad_expansion_type quad_expansion_type; \
590 typedef typename ExprT1::storage_type storage_type; \
591 typedef typename ExprT1::base_expr_type base_expr_type; \
592 \
593 static const int num_args = ExprT1::num_args; \
594 \
595 Expr(const ExprT1& expr1_, const ConstT& c_) : \
596 expr1(expr1_), c(c_) {} \
597 \
598 std::string name() const { \
599 return std::string(#OPER) + std::string("(") + expr1.name() + \
600 std::string(",c)"); \
601 } \
602 \
603 int size() const { \
604 if (expr1.size() == 1) \
605 return 1; \
606 else \
607 return expansion()->size(); \
608 } \
609 \
610 const approx_type& getArg(int i) const { \
611 return expr1.getArg(i); \
612 } \
613 \
614 bool has_nonconst_expansion() const { \
615 return expr1.has_nonconst_expansion(); \
616 } \
617 \
618 Teuchos::RCP<expansion_type> expansion() const { \
619 return expr1.expansion(); \
620 } \
621 \
622 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
623 return expr1.quad_expansion(); \
624 } \
625 \
626 bool has_fast_access(int sz) const { return false; } \
627 \
628 int order() const { return size() == 0 ? 0 : 100; } \
629 \
630 value_type val() const { \
631 return OPER (expr1.val(), c); \
632 } \
633 \
634 value_type fast_higher_order_coeff(int i) const { \
635 return value_type(0); \
636 } \
637 \
638 value_type higher_order_coeff(int i) const { \
639 return value_type(0); \
640 } \
641 \
642 template <int offset, typename tuple_type> \
643 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
644 return OPER (expr1.template eval_sample<offset,tuple_type>(x), c); \
645 } \
646 \
647 protected: \
648 \
649 const ExprT1& expr1; \
650 const ConstT& c; \
651 }; \
652 \
653 template <typename T2> \
654 class Expr< OP< typename Expr<T2>::value_type, Expr<T2> > > { \
655 \
656 public: \
657 \
658 typedef Expr<T2> ExprT2; \
659 typedef typename ExprT2::value_type value_type; \
660 typedef typename ExprT2::value_type ConstT; \
661 \
662 typedef typename ExprT2::approx_type approx_type; \
663 typedef typename ExprT2::expansion_type expansion_type; \
664 typedef typename ExprT2::quad_expansion_type quad_expansion_type; \
665 typedef typename ExprT2::storage_type storage_type; \
666 typedef typename ExprT2::base_expr_type base_expr_type; \
667 \
668 static const int num_args = ExprT2::num_args; \
669 \
670 Expr(const ConstT& c_, const ExprT2& expr2_) : \
671 c(c_), expr2(expr2_) {} \
672 \
673 std::string name() const { \
674 return std::string(#OPER) + std::string("(c,") + \
675 expr2.name() + std::string(")"); \
676 } \
677 \
678 int size() const { \
679 if (expr2.size() == 1) \
680 return 1; \
681 else \
682 return expansion()->size(); \
683 } \
684 \
685 const approx_type& getArg(int i) const { return expr2.getArg(i); } \
686 \
687 Teuchos::RCP<expansion_type> expansion() const { \
688 return expr2.expansion(); \
689 } \
690 \
691 bool has_nonconst_expansion() const { \
692 return expr2.has_nonconst_expansion(); \
693 } \
694 \
695 Teuchos::RCP<quad_expansion_type> quad_expansion() const { \
696 return expr2.quad_expansion(); \
697 } \
698 \
699 bool has_fast_access(int sz) const { return false; } \
700 \
701 int order() const { return size() == 0 ? 0 : 100; } \
702 \
703 value_type val() const { \
704 return OPER (c, expr2.val()); \
705 } \
706 \
707 value_type fast_higher_order_coeff(int i) const { \
708 return value_type(0); \
709 } \
710 \
711 value_type higher_order_coeff(int i) const { \
712 return value_type(0); \
713 } \
714 \
715 template <int offset, typename tuple_type> \
716 KERNEL_PREFIX value_type eval_sample(tuple_type x) const { \
717 return OPER (c, expr2.template eval_sample<offset,tuple_type>(x)); \
718 } \
719 \
720 protected: \
721 \
722 const ConstT& c; \
723 const ExprT2& expr2; \
724 }; \
725 \
726 template <typename T1, typename T2> \
727 inline Expr< OP< Expr<T1>, Expr<T2> > > \
728 OPNAME (const Expr<T1>& expr1, const Expr<T2>& expr2) \
729 { \
730 typedef OP< Expr<T1>, Expr<T2> > expr_t; \
731 \
732 return Expr<expr_t>(expr1, expr2); \
733 } \
734 \
735 template <typename T> \
736 inline Expr< OP< Expr<T>, Expr<T> > > \
737 OPNAME (const Expr<T>& expr1, const Expr<T>& expr2) \
738 { \
739 typedef OP< Expr<T>, Expr<T> > expr_t; \
740 \
741 return Expr<expr_t>(expr1, expr2); \
742 } \
743 \
744 template <typename T> \
745 inline Expr< OP< typename Expr<T>::value_type, Expr<T> > > \
746 OPNAME (const typename Expr<T>::value_type& c, \
747 const Expr<T>& expr) \
748 { \
749 typedef typename Expr<T>::value_type ConstT; \
750 typedef OP< ConstT, Expr<T> > expr_t; \
751 \
752 return Expr<expr_t>(c, expr); \
753 } \
754 \
755 template <typename T> \
756 inline Expr< OP< Expr<T>, typename Expr<T>::value_type > > \
757 OPNAME (const Expr<T>& expr, \
758 const typename Expr<T>::value_type& c) \
759 { \
760 typedef typename Expr<T>::value_type ConstT; \
761 typedef OP< Expr<T>, ConstT > expr_t; \
762 \
763 return Expr<expr_t>(expr, c); \
764 } \
765 } \
766 }
767
768 LINEAR_PCE_BINARYOP_MACRO(operator+, AdditionOp, +)
769 LINEAR_PCE_BINARYOP_MACRO(operator-, SubtractionOp, -)
770
771 NONLINEAR_PCE_BINARYOP_MACRO(atan2, Atan2Op, std::atan2)
772 NONLINEAR_PCE_BINARYOP_MACRO(pow, PowerOp, std::pow)
773 NONLINEAR_PCE_BINARYOP_MACRO(max, MaxOp, std::max)
774 NONLINEAR_PCE_BINARYOP_MACRO(min, MinOp, std::min)
775
776 #undef LINEAR_PCE_BINARYOP_MACRO
777 #undef NONLINEAR_PCE_BINARYOP_MACRO
778
779 //-------------------------- Multiplication Operator -----------------------
780
781 namespace Sacado {
782 namespace ETPCE {
783
784 template <typename ExprT1, typename ExprT2>
785 class MultiplicationOp {};
786
787 template <typename T1, typename T2>
788 class Expr< MultiplicationOp< Expr<T1>, Expr<T2> > > {
789
790 public:
791
792 typedef Expr<T1> ExprT1;
793 typedef Expr<T2> ExprT2;
794 typedef typename ExprT1::value_type value_type_1;
795 typedef typename ExprT2::value_type value_type_2;
796 typedef typename Sacado::Promote<value_type_1,
797 value_type_2>::type value_type;
798
799 typedef typename ExprT1::approx_type approx_type;
800 typedef typename ExprT1::expansion_type expansion_type;
801 typedef typename ExprT1::quad_expansion_type quad_expansion_type;
802 typedef typename ExprT1::storage_type storage_type;
803 typedef typename ExprT1::base_expr_type base_expr_type;
804
805 static const int num_args1 = ExprT1::num_args;
806 static const int num_args2 = ExprT2::num_args;
807 static const int num_args = num_args1 + num_args2;
808
809 Expr(const ExprT1& expr1_, const ExprT2& expr2_) :
810 expr1(expr1_), expr2(expr2_) {}
811
812 std::string name() const {
813 return expr1.name() + std::string("*") + expr2.name();
814 }
815
816 int size() const {
817 int sz1 = expr1.size();
818 int sz2 = expr2.size();
819 if (sz1 > 1 && sz2 > 1)
820 return expansion()->size();
821 else
822 return sz1*sz2;
823 }
824
825 const approx_type& getArg(int i) const {
826 if (i < num_args1)
827 return expr1.getArg(i);
828 else
829 return expr2.getArg(i-num_args1);
830 }
831
832 bool has_nonconst_expansion() const {
833 return expr1.has_nonconst_expansion() || expr2.has_nonconst_expansion();
834 }
835
836 Teuchos::RCP<expansion_type> expansion() const {
837 return expr1.has_nonconst_expansion() ? expr1.expansion() :
838 expr2.expansion();
839 }
840
841 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
842 return expr1.quad_expansion() != Teuchos::null ?
843 expr1.quad_expansion() :
844 expr2.quad_expansion();
845 }
846
847 bool has_fast_access(int sz) const {
848 return expr1.has_fast_access(sz) && expr2.has_fast_access(sz);
849 }
850
851 int order() const { return expr1.order() + expr2.order(); }
852
853 value_type val() const {
854 if (order() == 0)
855 return expr1.val() * expr2.val();
856 else
857 return quad_expansion()->compute_times_coeff(0,expr1,expr2);
858 }
859
860 value_type fast_higher_order_coeff(int i) const {
861 return quad_expansion()->fast_compute_times_coeff(i,expr1,expr2);
862 }
863
864 value_type higher_order_coeff(int i) const {
865 return quad_expansion()->compute_times_coeff(i,expr1,expr2);
866 }
867
868 template <int offset, typename tuple_type>
869 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
870 return expr1.template eval_sample<offset,tuple_type>(x) *
871 expr2.template eval_sample<offset+num_args1,tuple_type>(x);
872 }
873
874 protected:
875
876 const ExprT1& expr1;
877 const ExprT2& expr2;
878
879 };
880
881 template <typename T1>
882 class Expr< MultiplicationOp< Expr<T1>, typename Expr<T1>::value_type> > {
883
884 public:
885
886 typedef Expr<T1> ExprT1;
887 typedef typename ExprT1::value_type value_type;
888 typedef typename ExprT1::value_type ConstT;
889
890 typedef typename ExprT1::approx_type approx_type;
891 typedef typename ExprT1::expansion_type expansion_type;
892 typedef typename ExprT1::quad_expansion_type quad_expansion_type;
893 typedef typename ExprT1::storage_type storage_type;
894 typedef typename ExprT1::base_expr_type base_expr_type;
895
896 static const int num_args = ExprT1::num_args;
897
898 Expr(const ExprT1& expr1_, const ConstT& c_) :
899 expr1(expr1_), c(c_) {}
900
901 std::string name() const {
902 return expr1.name() + std::string("*c");
903 }
904
905 int size() const { return expr1.size(); }
906
907 const approx_type& getArg(int i) const {
908 return expr1.getArg(i);
909 }
910
911 bool has_nonconst_expansion() const {
912 return expr1.has_nonconst_expansion();
913 }
914
915 Teuchos::RCP<expansion_type> expansion() const {
916 return expr1.expansion();
917 }
918
919 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
920 return expr1.quad_expansion();
921 }
922
923 bool has_fast_access(int sz) const { return expr1.has_fast_access(sz); }
924
925 int order() const { return expr1.order(); }
926
927 value_type val() const {
928 return expr1.val() * c;
929 }
930
931 value_type fast_higher_order_coeff(int i) const {
932 return expr1.fast_higher_order_coeff(i) * c;
933 }
934
935 value_type higher_order_coeff(int i) const {
936 return expr1.higher_order_coeff(i) * c;
937 }
938
939 template <int offset, typename tuple_type>
940 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
941 return expr1.template eval_sample<offset,tuple_type>(x) * c;
942 }
943
944 protected:
945
946 const ExprT1& expr1;
947 const ConstT& c;
948 };
949
950 template <typename T2>
951 class Expr< MultiplicationOp< typename Expr<T2>::value_type, Expr<T2> > > {
952
953 public:
954
955 typedef Expr<T2> ExprT2;
956 typedef typename ExprT2::value_type value_type;
957 typedef typename ExprT2::value_type ConstT;
958
959 typedef typename ExprT2::approx_type approx_type;
960 typedef typename ExprT2::expansion_type expansion_type;
961 typedef typename ExprT2::quad_expansion_type quad_expansion_type;
962 typedef typename ExprT2::storage_type storage_type;
963 typedef typename ExprT2::base_expr_type base_expr_type;
964
965 static const int num_args = ExprT2::num_args;
966
967 Expr(const ConstT& c_, const ExprT2& expr2_) :
968 c(c_), expr2(expr2_) {}
969
970 std::string name() const {
971 return std::string("c*") + expr2.name();
972 }
973
974 int size() const { return expr2.size(); }
975
976 const approx_type& getArg(int i) const { return expr2.getArg(i); }
977
978 bool has_nonconst_expansion() const {
979 return expr2.has_nonconst_expansion();
980 }
981
982 Teuchos::RCP<expansion_type> expansion() const {
983 return expr2.expansion();
984 }
985
986 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
987 return expr2.quad_expansion();
988 }
989
990 bool has_fast_access(int sz) const { return expr2.has_fast_access(sz); }
991
992 int order() const { return expr2.order(); }
993
994 value_type val() const {
995 return c * expr2.val();
996 }
997
998 value_type fast_higher_order_coeff(int i) const {
999 return c * expr2.fast_higher_order_coeff(i);
1000 }
1001
1002 value_type higher_order_coeff(int i) const {
1003 return c * expr2.higher_order_coeff(i);
1004 }
1005
1006 template <int offset, typename tuple_type>
1007 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
1008 return c * expr2.template eval_sample<offset,tuple_type>(x);
1009 }
1010
1011 protected:
1012
1013 const ConstT& c;
1014 const ExprT2& expr2;
1015 };
1016
1017 template <typename T1, typename T2>
1018 inline Expr< MultiplicationOp< Expr<T1>, Expr<T2> > >
1019 operator* (const Expr<T1>& expr1, const Expr<T2>& expr2)
1020 {
1021 typedef MultiplicationOp< Expr<T1>, Expr<T2> > expr_t;
1022
1023 return Expr<expr_t>(expr1, expr2);
1024 }
1025
1026 template <typename T>
1027 inline Expr< MultiplicationOp< Expr<T>, Expr<T> > >
1028 operator* (const Expr<T>& expr1, const Expr<T>& expr2)
1029 {
1030 typedef MultiplicationOp< Expr<T>, Expr<T> > expr_t;
1031
1032 return Expr<expr_t>(expr1, expr2);
1033 }
1034
1035 template <typename T>
1036 inline Expr< MultiplicationOp< typename Expr<T>::value_type, Expr<T> > >
1037 operator* (const typename Expr<T>::value_type& c,
1038 const Expr<T>& expr)
1039 {
1040 typedef typename Expr<T>::value_type ConstT;
1041 typedef MultiplicationOp< ConstT, Expr<T> > expr_t;
1042
1043 return Expr<expr_t>(c, expr);
1044 }
1045
1046 template <typename T>
1047 inline Expr< MultiplicationOp< Expr<T>, typename Expr<T>::value_type > >
1048 operator* (const Expr<T>& expr,
1049 const typename Expr<T>::value_type& c)
1050 {
1051 typedef typename Expr<T>::value_type ConstT;
1052 typedef MultiplicationOp< Expr<T>, ConstT > expr_t;
1053
1054 return Expr<expr_t>(expr, c);
1055 }
1056 }
1057 }
1058
1059 //-------------------------- Division Operator -----------------------
1060
1061 namespace Sacado {
1062 namespace ETPCE {
1063
1064 template <typename ExprT1, typename ExprT2>
1065 class DivisionOp {};
1066
1067 template <typename T1, typename T2>
1068 class Expr< DivisionOp< Expr<T1>, Expr<T2> > > {
1069
1070 public:
1071
1072 typedef Expr<T1> ExprT1;
1073 typedef Expr<T2> ExprT2;
1074 typedef typename ExprT1::value_type value_type_1;
1075 typedef typename ExprT2::value_type value_type_2;
1076 typedef typename Sacado::Promote<value_type_1,
1077 value_type_2>::type value_type;
1078
1079 typedef typename ExprT1::approx_type approx_type;
1080 typedef typename ExprT1::expansion_type expansion_type;
1081 typedef typename ExprT1::quad_expansion_type quad_expansion_type;
1082 typedef typename ExprT1::storage_type storage_type;
1083 typedef typename ExprT1::base_expr_type base_expr_type;
1084
1085 static const int num_args1 = ExprT1::num_args;
1086 static const int num_args2 = ExprT2::num_args;
1087 static const int num_args = num_args1 + num_args2;
1088
1089 Expr(const ExprT1& expr1_, const ExprT2& expr2_) :
1090 expr1(expr1_), expr2(expr2_) {}
1091
1092 std::string name() const {
1093 return expr1.name() + std::string("/") + expr2.name();
1094 }
1095
1096 int size() const {
1097 if (expr2.size() == 1)
1098 return expr1.size();
1099 else
1100 return expansion()->size();
1101 }
1102
1103 const approx_type& getArg(int i) const {
1104 if (i < num_args1)
1105 return expr1.getArg(i);
1106 else
1107 return expr2.getArg(i-num_args1);
1108 }
1109
1110 bool has_nonconst_expansion() const {
1111 return expr1.has_nonconst_expansion() || expr2.has_nonconst_expansion();
1112 }
1113
1114 Teuchos::RCP<expansion_type> expansion() const {
1115 return expr1.has_nonconst_expansion() ? expr1.expansion() :
1116 expr2.expansion();
1117 }
1118
1119 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
1120 return expr1.quad_expansion() != Teuchos::null ?
1121 expr1.quad_expansion() :
1122 expr2.quad_expansion();
1123 }
1124
1125 bool has_fast_access(int sz) const {
1126 return expr1.has_fast_access(sz) && (expr2.order() == 0);
1127 }
1128
1129 int order() const { return expr2.order() == 0 ? expr1.order() : 100; }
1130
1131 value_type val() const {
1132 return expr1.val() / expr2.val();
1133 }
1134
1135 value_type fast_higher_order_coeff(int i) const {
1136 return expr1.fast_higher_order_coeff(i) / expr2.val();
1137 }
1138
1139 value_type higher_order_coeff(int i) const {
1140 return expr1.higher_order_coeff(i) / expr2.val();
1141 }
1142
1143 template <int offset, typename tuple_type>
1144 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
1145 return expr1.template eval_sample<offset,tuple_type>(x) /
1146 expr2.template eval_sample<offset+num_args1,tuple_type>(x);
1147 }
1148
1149 protected:
1150
1151 const ExprT1& expr1;
1152 const ExprT2& expr2;
1153
1154 };
1155
1156 template <typename T1>
1157 class Expr< DivisionOp< Expr<T1>, typename Expr<T1>::value_type> > {
1158
1159 public:
1160
1161 typedef Expr<T1> ExprT1;
1162 typedef typename ExprT1::value_type value_type;
1163 typedef typename ExprT1::value_type ConstT;
1164
1165 typedef typename ExprT1::approx_type approx_type;
1166 typedef typename ExprT1::expansion_type expansion_type;
1167 typedef typename ExprT1::quad_expansion_type quad_expansion_type;
1168 typedef typename ExprT1::storage_type storage_type;
1169 typedef typename ExprT1::base_expr_type base_expr_type;
1170
1171 static const int num_args = ExprT1::num_args;
1172
1173 Expr(const ExprT1& expr1_, const ConstT& c_) :
1174 expr1(expr1_), c(c_) {}
1175
1176 std::string name() const {
1177 return expr1.name() + std::string("/c");
1178 }
1179
1180 int size() const { return expr1.size(); }
1181
1182 const approx_type& getArg(int i) const {
1183 return expr1.getArg(i);
1184 }
1185
1186 bool has_nonconst_expansion() const {
1187 return expr1.has_nonconst_expansion();
1188 }
1189
1190 Teuchos::RCP<expansion_type> expansion() const {
1191 return expr1.expansion();
1192 }
1193
1194 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
1195 return expr1.quad_expansion();
1196 }
1197
1198 bool has_fast_access(int sz) const { return expr1.has_fast_access(sz); }
1199
1200 int order() const { return expr1.order(); }
1201
1202 value_type val() const {
1203 return expr1.val() / c;
1204 }
1205
1206 value_type fast_higher_order_coeff(int i) const {
1207 return expr1.fast_higher_order_coeff(i) / c;
1208 }
1209
1210 value_type higher_order_coeff(int i) const {
1211 return expr1.higher_order_coeff(i) / c;
1212 }
1213
1214 template <int offset, typename tuple_type>
1215 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
1216 return expr1.template eval_sample<offset,tuple_type>(x) / c;
1217 }
1218
1219 protected:
1220
1221 const ExprT1& expr1;
1222 const ConstT& c;
1223 };
1224
1225 template <typename T2>
1226 class Expr< DivisionOp< typename Expr<T2>::value_type, Expr<T2> > > {
1227
1228 public:
1229
1230 typedef Expr<T2> ExprT2;
1231 typedef typename ExprT2::value_type value_type;
1232 typedef typename ExprT2::value_type ConstT;
1233
1234 typedef typename ExprT2::approx_type approx_type;
1235 typedef typename ExprT2::expansion_type expansion_type;
1236 typedef typename ExprT2::quad_expansion_type quad_expansion_type;
1237 typedef typename ExprT2::storage_type storage_type;
1238 typedef typename ExprT2::base_expr_type base_expr_type;
1239
1240 static const int num_args = ExprT2::num_args;
1241
1242 Expr(const ConstT& c_, const ExprT2& expr2_) :
1243 c(c_), expr2(expr2_) {}
1244
1245 std::string name() const {
1246 return std::string("c/") + expr2.name();
1247 }
1248
1249 int size() const {
1250 if (expr2.size() == 1)
1251 return 1;
1252 else
1253 return expansion()->size();
1254 }
1255
1256 const approx_type& getArg(int i) const { return expr2.getArg(i); }
1257
1258 bool has_nonconst_expansion() const {
1259 return expr2.has_nonconst_expansion();
1260 }
1261
1262 Teuchos::RCP<expansion_type> expansion() const {
1263 return expr2.expansion();
1264 }
1265
1266 Teuchos::RCP<quad_expansion_type> quad_expansion() const {
1267 return expr2.quad_expansion();
1268 }
1269
1270 bool has_fast_access(int sz) const { return false; }
1271
1272 int order() const { return expr2.order() == 0 ? 0 : 100; }
1273
1274 value_type val() const {
1275 return c / expr2.val();
1276 }
1277
1278 value_type fast_higher_order_coeff(int i) const {
1279 return value_type(0);
1280 }
1281
1282 value_type higher_order_coeff(int i) const {
1283 return value_type(0);
1284 }
1285
1286 template <int offset, typename tuple_type>
1287 KERNEL_PREFIX value_type eval_sample(tuple_type x) const {
1288 return c / expr2.template eval_sample<offset,tuple_type>(x);
1289 }
1290
1291 protected:
1292
1293 const ConstT& c;
1294 const ExprT2& expr2;
1295 };
1296
1297 template <typename T1, typename T2>
1298 inline Expr< DivisionOp< Expr<T1>, Expr<T2> > >
1299 operator/ (const Expr<T1>& expr1, const Expr<T2>& expr2)
1300 {
1301 typedef DivisionOp< Expr<T1>, Expr<T2> > expr_t;
1302
1303 return Expr<expr_t>(expr1, expr2);
1304 }
1305
1306 template <typename T>
1307 inline Expr< DivisionOp< Expr<T>, Expr<T> > >
1308 operator/ (const Expr<T>& expr1, const Expr<T>& expr2)
1309 {
1310 typedef DivisionOp< Expr<T>, Expr<T> > expr_t;
1311
1312 return Expr<expr_t>(expr1, expr2);
1313 }
1314
1315 template <typename T>
1316 inline Expr< DivisionOp< typename Expr<T>::value_type, Expr<T> > >
1317 operator/ (const typename Expr<T>::value_type& c,
1318 const Expr<T>& expr)
1319 {
1320 typedef typename Expr<T>::value_type ConstT;
1321 typedef DivisionOp< ConstT, Expr<T> > expr_t;
1322
1323 return Expr<expr_t>(c, expr);
1324 }
1325
1326 template <typename T>
1327 inline Expr< DivisionOp< Expr<T>, typename Expr<T>::value_type > >
1328 operator/ (const Expr<T>& expr,
1329 const typename Expr<T>::value_type& c)
1330 {
1331 typedef typename Expr<T>::value_type ConstT;
1332 typedef DivisionOp< Expr<T>, ConstT > expr_t;
1333
1334 return Expr<expr_t>(expr, c);
1335 }
1336 }
1337 }
1338
1339 //-------------------------- Relational Operators -----------------------
1340
1341 #define PCE_RELOP_MACRO(OP) \
1342 namespace Sacado { \
1343 namespace ETPCE { \
1344 template <typename ExprT1, typename ExprT2> \
1345 inline bool \
1346 operator OP (const Expr<ExprT1>& expr1, \
1347 const Expr<ExprT2>& expr2) \
1348 { \
1349 return expr1.val() OP expr2.val(); \
1350 } \
1351 \
1352 template <typename ExprT2> \
1353 inline bool \
1354 operator OP (const typename Expr<ExprT2>::value_type& a, \
1355 const Expr<ExprT2>& expr2) \
1356 { \
1357 return a OP expr2.val(); \
1358 } \
1359 \
1360 template <typename ExprT1> \
1361 inline bool \
1362 operator OP (const Expr<ExprT1>& expr1, \
1363 const typename Expr<ExprT1>::value_type& b) \
1364 { \
1365 return expr1.val() OP b; \
1366 } \
1367 } \
1368 }
1369
1370 PCE_RELOP_MACRO(==)
1371 PCE_RELOP_MACRO(!=)
1372 PCE_RELOP_MACRO(<)
1373 PCE_RELOP_MACRO(>)
1374 PCE_RELOP_MACRO(<=)
1375 PCE_RELOP_MACRO(>=)
1376 PCE_RELOP_MACRO(<<=)
1377 PCE_RELOP_MACRO(>>=)
1378 PCE_RELOP_MACRO(&)
1379 PCE_RELOP_MACRO(|)
1380
1381 #undef PCE_RELOP_MACRO
1382
1383 namespace Sacado {
1384
1385 namespace ETPCE {
1386
1387 template <typename ExprT>
1388 inline bool operator ! (const Expr<ExprT>& expr)
1389 {
1390 return ! expr.val();
1391 }
1392
1393 } // namespace ETPCE
1394
1395 } // namespace Sacado
1396
1397 //-------------------------- Boolean Operators -----------------------
1398 namespace Sacado {
1399
1400 namespace ETPCE {
1401
1402 template <typename ExprT>
1403 bool toBool(const Expr<ExprT>& x) {
1404 bool is_zero = true;
1405 for (int i=0; i<x.size(); i++)
1406 is_zero = is_zero && (x.coeff(i) == 0.0);
1407 return !is_zero;
1408 }
1409
1410 } // namespace ETPCE
1411
1412 } // namespace Sacado
1413
1414 #define PCE_BOOL_MACRO(OP) \
1415 namespace Sacado { \
1416 namespace ETPCE { \
1417 template <typename ExprT1, typename ExprT2> \
1418 inline bool \
1419 operator OP (const Expr<ExprT1>& expr1, \
1420 const Expr<ExprT2>& expr2) \
1421 { \
1422 return toBool(expr1) OP toBool(expr2); \
1423 } \
1424 \
1425 template <typename ExprT2> \
1426 inline bool \
1427 operator OP (const typename Expr<ExprT2>::value_type& a, \
1428 const Expr<ExprT2>& expr2) \
1429 { \
1430 return a OP toBool(expr2); \
1431 } \
1432 \
1433 template <typename ExprT1> \
1434 inline bool \
1435 operator OP (const Expr<ExprT1>& expr1, \
1436 const typename Expr<ExprT1>::value_type& b) \
1437 { \
1438 return toBool(expr1) OP b; \
1439 } \
1440 } \
1441 }
1442
1443 PCE_BOOL_MACRO(&&)
1444 PCE_BOOL_MACRO(||)
1445
1446 #undef PCE_BOOL_MACRO
1447
1448 //-------------------------- I/O Operators -----------------------
1449
1450 namespace Sacado {
1451
1452 namespace ETPCE {
1453
1454 template <typename ExprT>
1455 std::ostream& operator << (std::ostream& os, const Expr<ExprT>& x) {
1456 typedef typename ExprT::value_type value_type;
1457 typedef typename ExprT::storage_type storage_type;
1458 OrthogPoly<value_type, storage_type> a(x);
1459 os << a;
1460 return os;
1461 }
1462
1463 } // namespace ETPCE
1464
1465 } // namespace Sacado
1466
1467
1468
1469
1470 #endif // SACADO_ETPCE_ORTHOGPOLY_OPS_HPP