Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_MP_Vector_SFS_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 #define OPNAME operator+
50 #define OPER +
52 #undef OPNAME
53 #undef OPER
54 
55 #define OPNAME operator-
56 #define OPER -
58 #undef OPNAME
59 #undef OPER
60 
61 #define OPNAME exp
63 #undef OPNAME
64 
65 #define OPNAME log
67 #undef OPNAME
68 
69 #define OPNAME log10
71 #undef OPNAME
72 
73 #define OPNAME sqrt
75 #undef OPNAME
76 
77 #define OPNAME cbrt
79 #undef OPNAME
80 
81 #define OPNAME cos
83 #undef OPNAME
84 
85 #define OPNAME sin
87 #undef OPNAME
88 
89 #define OPNAME tan
91 #undef OPNAME
92 
93 #define OPNAME acos
95 #undef OPNAME
96 
97 #define OPNAME asin
99 #undef OPNAME
100 
101 #define OPNAME atan
103 #undef OPNAME
104 
105 #define OPNAME cosh
107 #undef OPNAME
108 
109 #define OPNAME sinh
111 #undef OPNAME
112 
113 #define OPNAME tanh
115 #undef OPNAME
116 
117 #define OPNAME acosh
119 #undef OPNAME
120 
121 #define OPNAME asinh
123 #undef OPNAME
124 
125 #define OPNAME atanh
127 #undef OPNAME
128 
129 #define OPNAME abs
131 #undef OPNAME
132 
133 #define OPNAME fabs
135 #undef OPNAME
136 
137 #define OPNAME ceil
139 #undef OPNAME
140 
141 #define OPNAME operator+
142 #define OPER +
144 #undef OPNAME
145 #undef OPER
146 
147 #define OPNAME operator-
148 #define OPER -
150 #undef OPNAME
151 #undef OPER
152 
153 #define OPNAME operator*
154 #define OPER *
156 #undef OPNAME
157 #undef OPER
158 
159 #define OPNAME operator/
160 #define OPER /
162 #undef OPNAME
163 #undef OPER
164 
165 #define OPNAME atan2
167 #undef OPNAME
168 
169 #define OPNAME pow
171 #undef OPNAME
172 
173 #define OPNAME max
175 #undef OPNAME
176 
177 #define OPNAME min
179 #undef OPNAME
180 
181 //#ifdef __CUDACC__
182 //MP_BINARYOP_MACRO(max, ::max)
183 //MP_BINARYOP_MACRO(min, ::min)
184 //#else
185 //MP_BINARYOP_MACRO(max, std::max)
186 //MP_BINARYOP_MACRO(min, std::min)
187 //#endif
188 
189 //-------------------------- Relational Operators -----------------------
190 
191 #define MP_RELOP_MACRO(OP) \
192 namespace Sacado { \
193  namespace MP { \
194  \
195  template <typename O, typename T, int N, typename D> \
196  KOKKOS_INLINE_FUNCTION \
197  bool \
198  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
199  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
200  { \
201  return a.val() OP b.val(); \
202  } \
203  \
204  template <typename O, typename T, int N, typename D> \
205  KOKKOS_INLINE_FUNCTION \
206  bool \
207  operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
208  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
209  { \
210  return a OP b.val(); \
211  } \
212  \
213  template <typename O, typename T, int N, typename D> \
214  KOKKOS_INLINE_FUNCTION \
215  bool \
216  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
217  const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
218  { \
219  return a.val() OP b; \
220  } \
221  } \
222 }
223 
224 MP_RELOP_MACRO(==)
225 MP_RELOP_MACRO(!=)
228 MP_RELOP_MACRO(<=)
229 MP_RELOP_MACRO(>=)
230 MP_RELOP_MACRO(<<=)
231 MP_RELOP_MACRO(>>=)
234 
235 #undef MP_RELOP_MACRO
236 
237 namespace Sacado {
238 
239  namespace MP {
240 
241  template <typename O, typename T, int N, typename D>
242  KOKKOS_INLINE_FUNCTION
244  {
245  return ! a.val();
246  }
247 
248  } // namespace MP
249 
250 } // namespace Sacado
251 
252 
253 //-------------------------- Boolean Operators -----------------------
254 namespace Sacado {
255 
256  namespace MP {
257 
258  template <typename O, typename T, int N, typename D>
259  KOKKOS_INLINE_FUNCTION
261  bool is_zero = true;
262  for (int i=0; i<x.size(); i++)
263  is_zero = is_zero && (x.coeff(i) == 0.0);
264  return !is_zero;
265  }
266 
267  } // namespace MP
268 
269 } // namespace Sacado
270 
271 #define PCE_BOOL_MACRO(OP) \
272 namespace Sacado { \
273  namespace MP { \
274  \
275  template <typename O, typename T, int N, typename D> \
276  KOKKOS_INLINE_FUNCTION \
277  bool \
278  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
279  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
280  { \
281  return toBool(a) OP toBool(b); \
282  } \
283  \
284  template <typename O, typename T, int N, typename D> \
285  KOKKOS_INLINE_FUNCTION \
286  bool \
287  operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
288  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
289  { \
290  return a OP toBool(b); \
291  } \
292  \
293  template <typename O, typename T, int N, typename D> \
294  KOKKOS_INLINE_FUNCTION \
295  bool \
296  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
297  const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
298  { \
299  return toBool(a) OP b; \
300  } \
301  } \
302 }
303 
304 PCE_BOOL_MACRO(&&)
305 PCE_BOOL_MACRO(||)
306 
307 #undef PCE_BOOL_MACRO
Statically allocated storage class.
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< T > &expr)
#define MP_RELOP_MACRO(OP)
#define PCE_BOOL_MACRO(OP)