Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_MP_Vector_ops.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Sacado_cmath.hpp"
43 #include <ostream> // for std::ostream
44 
45 #ifdef __CUDACC__
46 #include <math_functions.h>
47 #endif
48 
49 /*
50 namespace Sacado {
51  namespace MP {
52 
53  template <typename T>
54  class LogOp :
55  public Expr< LogOp< T > > {
56  public:
57 
58  typedef typename T::value_type value_type;
59  typedef typename T::storage_type storage_type;
60 
61  KOKKOS_INLINE_FUNCTION
62  LogOp(const T& expr_) : expr(expr_) {}
63 
64  KOKKOS_INLINE_FUNCTION
65  std::string name() const {
66  return std::string("log") + expr.name();
67  }
68 
69  KOKKOS_INLINE_FUNCTION
70  int size() const {
71  return expr.size();
72  }
73 
74  KOKKOS_INLINE_FUNCTION
75  bool hasFastAccess(int sz) const {
76  return expr.hasFastAccess(sz);
77  }
78 
79  KOKKOS_INLINE_FUNCTION
80  value_type val() const {
81  return std::log(expr.val());
82  }
83 
84  KOKKOS_INLINE_FUNCTION
85  value_type coeff(int i) const {
86  return std::log(expr.coeff(i));
87  }
88 
89  KOKKOS_INLINE_FUNCTION
90  value_type fastAccessCoeff(int i) const {
91  return std::log(expr.fastAccessCoeff(i));
92  }
93 
94  protected:
95 
96  const T& expr;
97 
98  };
99 
100  template <typename T, typename N>
101  KOKKOS_INLINE_FUNCTION
102  LogOp< T >
103  log (const Expr<T>& expr)
104  {
105  typedef LogOp< typename Expr<T>::derived_type > expr_t;
106 
107  return expr_t(expr.derived());
108  }
109  }
110 }
111 */
112 
113 #define MP_UNARYOP_MACRO(OPNAME,OP,OPER) \
114 namespace Sacado { \
115  namespace MP { \
116  \
117  \
118  template <typename T> \
119  class OP : \
120  public Expr< OP< T > > { \
121  public: \
122  \
123  typedef typename remove_volatile<T>::type Tnv; \
124  typedef typename Tnv::value_type value_type; \
125  typedef typename Tnv::storage_type storage_type; \
126  typedef typename Tnv::base_expr_type base_expr_type; \
127  \
128  KOKKOS_INLINE_FUNCTION \
129  OP(const T& expr_) : expr(expr_) {} \
130  \
131  KOKKOS_INLINE_FUNCTION \
132  std::string name() const { \
133  return std::string(#OPER) + expr.name(); \
134  } \
135  \
136  KOKKOS_INLINE_FUNCTION \
137  int size() const { \
138  return expr.size(); \
139  } \
140  \
141  KOKKOS_INLINE_FUNCTION \
142  bool hasFastAccess(int sz) const { \
143  return expr.hasFastAccess(sz); \
144  } \
145  \
146  KOKKOS_INLINE_FUNCTION \
147  value_type val() const { \
148  return OPER(expr.val()); \
149  } \
150  \
151  KOKKOS_INLINE_FUNCTION \
152  value_type coeff(int i) const { \
153  return OPER(expr.coeff(i)); \
154  } \
155  \
156  KOKKOS_INLINE_FUNCTION \
157  value_type fastAccessCoeff(int i) const { \
158  return OPER(expr.fastAccessCoeff(i)); \
159  } \
160  \
161  template <int i> \
162  KOKKOS_INLINE_FUNCTION \
163  value_type getCoeff() const { \
164  return OPER(expr.template getCoeff<i>()); \
165  } \
166  \
167  protected: \
168  \
169  typename const_expr_ref<T>::type expr; \
170  \
171  }; \
172  \
173  template <typename T> \
174  KOKKOS_INLINE_FUNCTION \
175  OP< T > \
176  OPNAME (const Expr<T>& expr) \
177  { \
178  typedef OP< typename Expr<T>::derived_type > expr_t; \
179  \
180  return expr_t(expr.derived()); \
181  } \
182  \
183  template <typename T> \
184  KOKKOS_INLINE_FUNCTION \
185  OP< volatile T > \
186  OPNAME (const volatile Expr<T>& expr) \
187  { \
188  typedef typename Expr<T>::derived_type derived; \
189  typedef OP< typename add_volatile<derived>::type > expr_t; \
190  \
191  return expr_t(expr.derived()); \
192  } \
193  } \
194  \
195  template <typename T> \
196  struct IsExpr< MP::OP<T> > { \
197  static const bool value = true; \
198  }; \
199  \
200  template <typename T> \
201  struct BaseExprType< MP::OP<T> > { \
202  typedef typename MP::OP<T>::base_expr_type type; \
203  }; \
204 }
205 
206 MP_UNARYOP_MACRO(operator+, UnaryPlusOp, +)
207 MP_UNARYOP_MACRO(operator-, UnaryMinusOp, -)
209 MP_UNARYOP_MACRO(log, LogOp, std::log)
227 
228 #undef MP_UNARYOP_MACRO
229 
230 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \
231 namespace Sacado { \
232  namespace MP { \
233  \
234  template <typename T1, typename T2> \
235  class OP : \
236  public Expr< OP< T1, T2> > { \
237  \
238  public: \
239  \
240  typedef typename remove_volatile<T1>::type Tnv1; \
241  typedef typename remove_volatile<T2>::type Tnv2; \
242  typedef typename Tnv1::value_type value_type_1; \
243  typedef typename Tnv2::value_type value_type_2; \
244  typedef typename Sacado::Promote<value_type_1, \
245  value_type_2>::type value_type; \
246  \
247  typedef typename Tnv1::storage_type storage_type; \
248  typedef typename Tnv1::base_expr_type base_expr_type; \
249  \
250  KOKKOS_INLINE_FUNCTION \
251  OP(const T1& expr1_, const T2& expr2_) : \
252  expr1(expr1_), expr2(expr2_) {} \
253  \
254  KOKKOS_INLINE_FUNCTION \
255  std::string name() const { \
256  return expr1.name() + std::string(#OPER) + expr2.name(); \
257  } \
258  \
259  KOKKOS_INLINE_FUNCTION \
260  int size() const { \
261  int sz1 = expr1.size(), sz2 = expr2.size(); \
262  return sz1 > sz2 ? sz1 : sz2; \
263  } \
264  \
265  KOKKOS_INLINE_FUNCTION \
266  bool hasFastAccess(int sz) const { \
267  return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
268  } \
269  \
270  KOKKOS_INLINE_FUNCTION \
271  value_type val() const { \
272  return (expr1.val() OPER expr2.val()); \
273  } \
274  \
275  KOKKOS_INLINE_FUNCTION \
276  value_type coeff(int i) const { \
277  return (expr1.coeff(i) OPER expr2.coeff(i)); \
278  } \
279  \
280  KOKKOS_INLINE_FUNCTION \
281  value_type fastAccessCoeff(int i) const { \
282  return (expr1.fastAccessCoeff(i) OPER expr2.fastAccessCoeff(i)); \
283  } \
284  \
285  template <int i> \
286  KOKKOS_INLINE_FUNCTION \
287  value_type getCoeff() const { \
288  return expr1.template getCoeff<i>() OPER expr2.template getCoeff<i>(); \
289  } \
290  \
291  protected: \
292  \
293  typename const_expr_ref<T1>::type expr1; \
294  typename const_expr_ref<T2>::type expr2; \
295  \
296  }; \
297  \
298  template <typename T1> \
299  class OP< T1, typename T1::value_type > : \
300  public Expr< OP< T1, typename T1::value_type > > { \
301  \
302  public: \
303  \
304  typedef typename remove_volatile<T1>::type Tnv1; \
305  typedef typename Tnv1::value_type value_type; \
306  typedef typename Tnv1::value_type ConstT; \
307  \
308  typedef typename Tnv1::storage_type storage_type; \
309  typedef typename Tnv1::base_expr_type base_expr_type; \
310  \
311  KOKKOS_INLINE_FUNCTION \
312  OP(const T1& expr1_, const ConstT& c_) : \
313  expr1(expr1_), c(c_) {} \
314  \
315  KOKKOS_INLINE_FUNCTION \
316  std::string name() const { \
317  return expr1.name() + std::string(#OPER) + std::string("c"); \
318  } \
319  \
320  KOKKOS_INLINE_FUNCTION \
321  int size() const { \
322  return expr1.size(); \
323  } \
324  \
325  KOKKOS_INLINE_FUNCTION \
326  bool hasFastAccess(int sz) const { \
327  return expr1.hasFastAccess(sz); \
328  } \
329  \
330  KOKKOS_INLINE_FUNCTION \
331  value_type val() const { \
332  return (expr1.val() OPER c); \
333  } \
334  \
335  KOKKOS_INLINE_FUNCTION \
336  value_type coeff(int i) const { \
337  return (expr1.coeff(i) OPER c); \
338  } \
339  \
340  KOKKOS_INLINE_FUNCTION \
341  value_type fastAccessCoeff(int i) const { \
342  return (expr1.fastAccessCoeff(i) OPER c); \
343  } \
344  \
345  template <int i> \
346  KOKKOS_INLINE_FUNCTION \
347  value_type getCoeff() const { \
348  return expr1.template getCoeff<i>() OPER c; \
349  } \
350  \
351  protected: \
352  \
353  typename const_expr_ref<T1>::type expr1; \
354  const ConstT& c; \
355  }; \
356  \
357  template <typename T2> \
358  class OP< typename T2::value_type, T2 > : \
359  public Expr< OP< typename T2::value_type, T2 > > { \
360  \
361  public: \
362  \
363  typedef typename remove_volatile<T2>::type Tnv2; \
364  typedef typename Tnv2::value_type value_type; \
365  typedef typename Tnv2::value_type ConstT; \
366  \
367  typedef typename Tnv2::storage_type storage_type; \
368  typedef typename Tnv2::base_expr_type base_expr_type; \
369  \
370  KOKKOS_INLINE_FUNCTION \
371  OP(const ConstT& c_, const T2& expr2_) : \
372  c(c_), expr2(expr2_) {} \
373  \
374  KOKKOS_INLINE_FUNCTION \
375  std::string name() const { \
376  return std::string("c") + std::string(#OPER) + expr2.name(); \
377  } \
378  \
379  KOKKOS_INLINE_FUNCTION \
380  int size() const { return expr2.size(); } \
381  \
382  KOKKOS_INLINE_FUNCTION \
383  bool hasFastAccess(int sz) const { \
384  return expr2.hasFastAccess(sz); \
385  } \
386  \
387  KOKKOS_INLINE_FUNCTION \
388  value_type val() const { \
389  return (c OPER expr2.val()); \
390  } \
391  \
392  KOKKOS_INLINE_FUNCTION \
393  value_type coeff(int i) const { \
394  return (c OPER expr2.coeff(i)); \
395  } \
396  \
397  KOKKOS_INLINE_FUNCTION \
398  value_type fastAccessCoeff(int i) const { \
399  return (c OPER expr2.fastAccessCoeff(i)); \
400  } \
401  \
402  template <int i> \
403  KOKKOS_INLINE_FUNCTION \
404  value_type getCoeff() const { \
405  return c OPER expr2.template getCoeff<i>(); \
406  } \
407  \
408  protected: \
409  \
410  const ConstT& c; \
411  typename const_expr_ref<T2>::type expr2; \
412  }; \
413  \
414  template <typename T1, typename T2> \
415  KOKKOS_INLINE_FUNCTION \
416  OP< T1, T2 > \
417  OPNAME (const Expr<T1>& expr1, \
418  const Expr<T2>& expr2) \
419  { \
420  typedef OP< typename Expr<T1>::derived_type, \
421  typename Expr<T2>::derived_type > expr_t; \
422  \
423  return expr_t(expr1.derived(), expr2.derived()); \
424  } \
425  \
426  template <typename T1, typename T2> \
427  KOKKOS_INLINE_FUNCTION \
428  OP< volatile T1, volatile T2 > \
429  OPNAME (const volatile Expr<T1>& expr1, \
430  const volatile Expr<T2>& expr2) \
431  { \
432  typedef typename Expr<T1>::derived_type derived1; \
433  typedef typename Expr<T2>::derived_type derived2; \
434  typedef OP< typename add_volatile<derived1>::type, \
435  typename add_volatile<derived2>::type > expr_t; \
436  \
437  return expr_t(expr1.derived(), expr2.derived()); \
438  } \
439  \
440  template <typename T1, typename T2> \
441  KOKKOS_INLINE_FUNCTION \
442  OP< T1, volatile T2 > \
443  OPNAME (const Expr<T1>& expr1, \
444  const volatile Expr<T2>& expr2) \
445  { \
446  typedef typename Expr<T1>::derived_type derived1; \
447  typedef typename Expr<T2>::derived_type derived2; \
448  typedef OP< derived1, \
449  typename add_volatile<derived2>::type > expr_t; \
450  \
451  return expr_t(expr1.derived(), expr2.derived()); \
452  } \
453  \
454  template <typename T1, typename T2> \
455  KOKKOS_INLINE_FUNCTION \
456  OP< volatile T1, T2 > \
457  OPNAME (const volatile Expr<T1>& expr1, \
458  const Expr<T2>& expr2) \
459  { \
460  typedef typename Expr<T1>::derived_type derived1; \
461  typedef typename Expr<T2>::derived_type derived2; \
462  typedef OP< typename add_volatile<derived1>::type, \
463  derived2 > expr_t; \
464  \
465  return expr_t(expr1.derived(), expr2.derived()); \
466  } \
467  \
468  template <typename T> \
469  KOKKOS_INLINE_FUNCTION \
470  OP< typename T::value_type, T > \
471  OPNAME (const typename T::value_type& c, \
472  const Expr<T>& expr) \
473  { \
474  typedef typename T::value_type ConstT; \
475  typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
476  \
477  return expr_t(c, expr.derived()); \
478  } \
479  \
480  template <typename T> \
481  KOKKOS_INLINE_FUNCTION \
482  OP< typename T::value_type, volatile T > \
483  OPNAME (const typename T::value_type& c, \
484  const volatile Expr<T>& expr) \
485  { \
486  typedef typename T::value_type ConstT; \
487  typedef typename Expr<T>::derived_type derived; \
488  typedef OP< ConstT, \
489  typename add_volatile<derived>::type > expr_t; \
490  \
491  return expr_t(c, expr.derived()); \
492  } \
493  \
494  template <typename T> \
495  KOKKOS_INLINE_FUNCTION \
496  OP< T, typename T::value_type > \
497  OPNAME (const Expr<T>& expr, \
498  const typename T::value_type& c) \
499  { \
500  typedef typename T::value_type ConstT; \
501  typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
502  \
503  return expr_t(expr.derived(), c); \
504  } \
505  \
506  template <typename T> \
507  KOKKOS_INLINE_FUNCTION \
508  OP< volatile T, typename T::value_type > \
509  OPNAME (const volatile Expr<T>& expr, \
510  const typename T::value_type& c) \
511  { \
512  typedef typename T::value_type ConstT; \
513  typedef typename Expr<T>::derived_type derived; \
514  typedef OP< typename add_volatile<derived>::type, \
515  ConstT > expr_t; \
516  \
517  return expr_t(expr.derived(), c); \
518  } \
519  } \
520  \
521  template <typename T1, typename T2> \
522  struct IsExpr< MP::OP<T1,T2> > { \
523  static const bool value = true; \
524  }; \
525  \
526  template <typename T1, typename T2> \
527  struct BaseExprType< MP::OP<T1,T2> > { \
528  typedef typename MP::OP<T1,T2>::base_expr_type type; \
529  }; \
530 }
531 
532 MP_BINARYOP_MACRO(operator+, AdditionOp, +)
533 MP_BINARYOP_MACRO(operator-, SubtractionOp, -)
534 MP_BINARYOP_MACRO(operator*, MultiplicationOp, *)
535 MP_BINARYOP_MACRO(operator/, DivisionOp, /)
536 
537 #undef MP_BINARYOP_MACRO
538 
539 #define MP_BINARYOP_MACRO(OPNAME,OP,OPER) \
540 namespace Sacado { \
541  namespace MP { \
542  \
543  template <typename T1, typename T2> \
544  class OP : \
545  public Expr< OP< T1, T2 > > { \
546  \
547  public: \
548  \
549  typedef typename T1::value_type value_type_1; \
550  typedef typename T2::value_type value_type_2; \
551  typedef typename Sacado::Promote<value_type_1, \
552  value_type_2>::type value_type; \
553  \
554  typedef typename T1::storage_type storage_type; \
555  typedef typename T1::base_expr_type base_expr_type; \
556  \
557  \
558  KOKKOS_INLINE_FUNCTION \
559  OP(const T1& expr1_, const T2& expr2_) : \
560  expr1(expr1_), expr2(expr2_) {} \
561  \
562  KOKKOS_INLINE_FUNCTION \
563  std::string name() const { \
564  return expr1.name() + std::string(#OPER) + expr2.name(); \
565  } \
566  \
567  KOKKOS_INLINE_FUNCTION \
568  int size() const { \
569  int sz1 = expr1.size(), sz2 = expr2.size(); \
570  return sz1 > sz2 ? sz1 : sz2; \
571  } \
572  \
573  KOKKOS_INLINE_FUNCTION \
574  bool hasFastAccess(int sz) const { \
575  return expr1.hasFastAccess(sz) && expr2.hasFastAccess(sz); \
576  } \
577  \
578  KOKKOS_INLINE_FUNCTION \
579  value_type val() const { \
580  return OPER(expr1.val(), expr2.val()); \
581  } \
582  \
583  KOKKOS_INLINE_FUNCTION \
584  value_type coeff(int i) const { \
585  return OPER(expr1.coeff(i), expr2.coeff(i)); \
586  } \
587  \
588  KOKKOS_INLINE_FUNCTION \
589  value_type fastAccessCoeff(int i) const { \
590  return OPER(expr1.fastAccessCoeff(i), expr2.fastAccessCoeff(i)); \
591  } \
592  \
593  template <int i> \
594  KOKKOS_INLINE_FUNCTION \
595  value_type getCoeff() const { \
596  return OPER(expr1.template getCoeff<i>(), \
597  expr2.template getCoeff<i>()); \
598  } \
599  \
600  protected: \
601  \
602  typename const_expr_ref<T1>::type expr1; \
603  typename const_expr_ref<T2>::type expr2; \
604  \
605  }; \
606  \
607  template <typename T1> \
608  class OP< T1, typename T1::value_type > : \
609  public Expr< OP< T1, typename T1::value_type > > { \
610  \
611  public: \
612  \
613  typedef typename T1::value_type value_type; \
614  typedef typename T1::value_type ConstT; \
615  \
616  typedef typename T1::storage_type storage_type; \
617  typedef typename T1::base_expr_type base_expr_type; \
618  \
619  KOKKOS_INLINE_FUNCTION \
620  OP(const T1& expr1_, const ConstT& c_) : \
621  expr1(expr1_), c(c_) {} \
622  \
623  KOKKOS_INLINE_FUNCTION \
624  std::string name() const { \
625  return expr1.name() + std::string(#OPER) + std::string("c"); \
626  } \
627  \
628  KOKKOS_INLINE_FUNCTION \
629  int size() const { return expr1.size(); } \
630  \
631  KOKKOS_INLINE_FUNCTION \
632  bool hasFastAccess(int sz) const { \
633  return expr1.hasFastAccess(sz); \
634  } \
635  \
636  KOKKOS_INLINE_FUNCTION \
637  value_type val() const { \
638  return OPER(expr1.val(), c); \
639  } \
640  \
641  KOKKOS_INLINE_FUNCTION \
642  value_type coeff(int i) const { \
643  return OPER(expr1.coeff(i), c); \
644  } \
645  \
646  KOKKOS_INLINE_FUNCTION \
647  value_type fastAccessCoeff(int i) const { \
648  return OPER(expr1.fastAccessCoeff(i), c); \
649  } \
650  \
651  template <int i> \
652  KOKKOS_INLINE_FUNCTION \
653  value_type getCoeff() const { \
654  return OPER(expr1.template getCoeff<i>(), c); \
655  } \
656  \
657  protected: \
658  \
659  typename const_expr_ref<T1>::type expr1; \
660  const ConstT& c; \
661  }; \
662  \
663  template <typename T2> \
664  class OP< typename T2::value_type, T2 > : \
665  public Expr< OP< typename T2::value_type, T2 > > { \
666  \
667  public: \
668  \
669  typedef typename T2::value_type value_type; \
670  typedef typename T2::value_type ConstT; \
671  \
672  typedef typename T2::storage_type storage_type; \
673  typedef typename T2::base_expr_type base_expr_type; \
674  \
675  KOKKOS_INLINE_FUNCTION \
676  OP(const ConstT& c_, const T2& expr2_) : \
677  c(c_), expr2(expr2_) {} \
678  \
679  KOKKOS_INLINE_FUNCTION \
680  std::string name() const { \
681  return std::string("c") + std::string(#OPER) + expr2.name(); \
682  } \
683  \
684  KOKKOS_INLINE_FUNCTION \
685  int size() const { return expr2.size(); } \
686  \
687  KOKKOS_INLINE_FUNCTION \
688  bool hasFastAccess(int sz) const { \
689  return expr2.hasFastAccess(sz); \
690  } \
691  \
692  KOKKOS_INLINE_FUNCTION \
693  value_type val() const { \
694  return OPER(c, expr2.val()); \
695  } \
696  \
697  KOKKOS_INLINE_FUNCTION \
698  value_type coeff(int i) const { \
699  return OPER(c, expr2.coeff(i)); \
700  } \
701  \
702  KOKKOS_INLINE_FUNCTION \
703  value_type fastAccessCoeff(int i) const { \
704  return OPER(c, expr2.fastAccessCoeff(i)); \
705  } \
706  \
707  template <int i> \
708  KOKKOS_INLINE_FUNCTION \
709  value_type getCoeff() const { \
710  return OPER(c, expr2.template getCoeff<i>()); \
711  } \
712  \
713  protected: \
714  \
715  const ConstT& c; \
716  typename const_expr_ref<T2>::type expr2; \
717  }; \
718  \
719  template <typename T1, typename T2> \
720  KOKKOS_INLINE_FUNCTION \
721  OP< T1, T2 > \
722  OPNAME (const Expr<T1>& expr1, \
723  const Expr<T2>& expr2) \
724  { \
725  typedef OP< typename Expr<T1>::derived_type, \
726  typename Expr<T2>::derived_type > expr_t; \
727  \
728  return expr_t(expr1.derived(), expr2.derived()); \
729  } \
730  \
731  template <typename T> \
732  KOKKOS_INLINE_FUNCTION \
733  OP< typename T::value_type, T > \
734  OPNAME (const typename T::value_type& c, \
735  const Expr<T>& expr) \
736  { \
737  typedef typename T::value_type ConstT; \
738  typedef OP< ConstT, typename Expr<T>::derived_type > expr_t; \
739  \
740  return expr_t(c, expr.derived()); \
741  } \
742  \
743  template <typename T> \
744  KOKKOS_INLINE_FUNCTION \
745  OP< T, typename T::value_type > \
746  OPNAME (const Expr<T>& expr, \
747  const typename T::value_type& c) \
748  { \
749  typedef typename T::value_type ConstT; \
750  typedef OP< typename Expr<T>::derived_type, ConstT > expr_t; \
751  \
752  return expr_t(expr.derived(), c); \
753  } \
754  } \
755  \
756  template <typename T1, typename T2> \
757  struct IsExpr< MP::OP<T1,T2> > { \
758  static const bool value = true; \
759  }; \
760  \
761  template <typename T1, typename T2> \
762  struct BaseExprType< MP::OP<T1,T2> > { \
763  typedef typename MP::OP<T1,T2>::base_expr_type type; \
764  }; \
765 }
766 
769 #ifdef __CUDACC__
772 #else
775 #endif
776 
777 #undef MP_BINARYOP_MACRO
778 
779 //-------------------------- Relational Operators -----------------------
780 
781 #define MP_RELOP_MACRO(OP) \
782 namespace Sacado { \
783  namespace MP { \
784  \
785  template <typename T1, typename T2> \
786  KOKKOS_INLINE_FUNCTION \
787  bool \
788  operator OP (const Expr<T1>& expr1, \
789  const Expr<T2>& expr2) \
790  { \
791  return expr1.derived().val() OP expr2.derived().val(); \
792  } \
793  \
794  template <typename T1, typename T2> \
795  KOKKOS_INLINE_FUNCTION \
796  bool \
797  operator OP (const volatile Expr<T1>& expr1, \
798  const volatile Expr<T2>& expr2) \
799  { \
800  return expr1.derived().val() OP expr2.derived().val(); \
801  } \
802  \
803  template <typename T1, typename T2> \
804  KOKKOS_INLINE_FUNCTION \
805  bool \
806  operator OP (const volatile Expr<T1>& expr1, \
807  const Expr<T2>& expr2) \
808  { \
809  return expr1.derived().val() OP expr2.derived().val(); \
810  } \
811  \
812  template <typename T1, typename T2> \
813  KOKKOS_INLINE_FUNCTION \
814  bool \
815  operator OP (const Expr<T1>& expr1, \
816  const volatile Expr<T2>& expr2) \
817  { \
818  return expr1.derived().val() OP expr2.derived().val(); \
819  } \
820  \
821  template <typename T2> \
822  KOKKOS_INLINE_FUNCTION \
823  bool \
824  operator OP (const typename T2::value_type& a, \
825  const Expr<T2>& expr2) \
826  { \
827  return a OP expr2.derived().val(); \
828  } \
829  \
830  template <typename T2> \
831  KOKKOS_INLINE_FUNCTION \
832  bool \
833  operator OP (const typename T2::value_type& a, \
834  const volatile Expr<T2>& expr2) \
835  { \
836  return a OP expr2.derived().val(); \
837  } \
838  \
839  template <typename T1> \
840  KOKKOS_INLINE_FUNCTION \
841  bool \
842  operator OP (const Expr<T1>& expr1, \
843  const typename T1::value_type& b) \
844  { \
845  return expr1.derived().val() OP b; \
846  } \
847  \
848  template <typename T1> \
849  KOKKOS_INLINE_FUNCTION \
850  bool \
851  operator OP (const volatile Expr<T1>& expr1, \
852  const typename T1::value_type& b) \
853  { \
854  return expr1.derived().val() OP b; \
855  } \
856  } \
857 }
858 
859 MP_RELOP_MACRO(==)
860 MP_RELOP_MACRO(!=)
863 MP_RELOP_MACRO(<=)
864 MP_RELOP_MACRO(>=)
865 MP_RELOP_MACRO(<<=)
866 MP_RELOP_MACRO(>>=)
869 
870 #undef MP_RELOP_MACRO
871 
872 namespace Sacado {
873 
874  namespace MP {
875 
876  template <typename T>
877  KOKKOS_INLINE_FUNCTION
878  bool operator ! (const Expr<T>& expr)
879  {
880  return ! expr.derived().val();
881  }
882 
883  } // namespace MP
884 
885 } // namespace Sacado
886 
887 
888 //-------------------------- Boolean Operators -----------------------
889 namespace Sacado {
890 
891  namespace MP {
892 
893  template <typename T>
894  KOKKOS_INLINE_FUNCTION
895  bool toBool(const Expr<T>& xx) {
896  const typename Expr<T>::derived_type& x =
897  xx.derived();
898  bool is_zero = true;
899  for (int i=0; i<x.size(); i++)
900  is_zero = is_zero && (x.coeff(i) == 0.0);
901  return !is_zero;
902  }
903 
904  } // namespace MP
905 
906 } // namespace Sacado
907 
908 #define PCE_BOOL_MACRO(OP) \
909 namespace Sacado { \
910  namespace MP { \
911  \
912  template <typename T1, typename T2> \
913  KOKKOS_INLINE_FUNCTION \
914  bool \
915  operator OP (const Expr<T1>& expr1, \
916  const Expr<T2>& expr2) \
917  { \
918  return toBool(expr1) OP toBool(expr2); \
919  } \
920  \
921  template <typename T2> \
922  KOKKOS_INLINE_FUNCTION \
923  bool \
924  operator OP (const typename T2::value_type& a, \
925  const Expr<T2>& expr2) \
926  { \
927  return a OP toBool(expr2); \
928  } \
929  \
930  template <typename T1> \
931  KOKKOS_INLINE_FUNCTION \
932  bool \
933  operator OP (const Expr<T1>& expr1, \
934  const typename T1::value_type& b) \
935  { \
936  return toBool(expr1) OP b; \
937  } \
938  } \
939 }
940 
941 PCE_BOOL_MACRO(&&)
942 PCE_BOOL_MACRO(||)
943 
944 #undef PCE_BOOL_MACRO
945 
946 
947 //-------------------------- I/O Operators -----------------------
948 
949 namespace Sacado {
950 
951  namespace MP {
952 
953  template <typename T>
954  std::ostream& operator << (std::ostream& os,
955  const Expr<T>& x) {
956  typedef typename T::storage_type storage_type;
958  os << a;
959  return os;
960  }
961 
962  } // namespace MP
963 
964 } // namespace Sacado
expr expr ASinhOp
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > fabs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
expr expr TanhOp
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 MultiplicationOp
expr expr ATanhOp
atanh(expr.val())
#define MP_BINARYOP_MACRO(OPNAME, OP, OPER)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 j expr1 expr1 expr1 expr1 j expr1 c *expr2 expr1 c expr1 c expr1 c expr1 DivisionOp
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
expr expr ASinOp
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
expr expr TanOp
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
atan2(expr1.val(), expr2.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
asinh(expr.val())
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< T > &expr)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 j expr1 expr1 expr1 expr1 j expr1 c *expr2 expr1 c expr1 c expr1 c expr1 expr1 expr1 expr1 j *expr1 expr2 expr1 expr1 j *expr1 c expr2 expr1 c expr1 expr2 expr1 expr2 expr1 Atan2Op
#define MP_UNARYOP_MACRO(OPNAME, OP, OPER)
#define MP_RELOP_MACRO(OP)
expr expr CoshOp
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
expr expr CosOp
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
expr2 j expr1 expr1 expr2 expr2 j expr1 c c c c PowerOp
expr expr SinhOp
std::ostream & operator<<(std::ostream &os, const Expr< T > &x)
acosh(expr.val())
expr expr SinOp
expr expr expr expr ExpOp
expr expr SqrtOp
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
expr expr AbsOp
expr expr ACoshOp
expr expr ATanOp
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)
#define PCE_BOOL_MACRO(OP)
expr expr ACosOp