Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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 <cuda_runtime_api.h>
47 // including math functions via math_functions.h is deprecated in cuda version >= 10.0
48 // the deprecation warning indicates to use cuda_runtime_api.h instead
49 #if CUDART_VERSION < 10000
50 #include <math_functions.h>
51 #endif
52#endif
53
54#define OPNAME operator+
55#define OPER +
57#undef OPNAME
58#undef OPER
59
60#define OPNAME operator-
61#define OPER -
63#undef OPNAME
64#undef OPER
65
66#define OPNAME exp
68#undef OPNAME
69
70#define OPNAME log
72#undef OPNAME
73
74#define OPNAME log10
76#undef OPNAME
77
78#define OPNAME sqrt
80#undef OPNAME
81
82#define OPNAME cbrt
84#undef OPNAME
85
86#define OPNAME cos
88#undef OPNAME
89
90#define OPNAME sin
92#undef OPNAME
93
94#define OPNAME tan
96#undef OPNAME
97
98#define OPNAME acos
100#undef OPNAME
101
102#define OPNAME asin
104#undef OPNAME
105
106#define OPNAME atan
108#undef OPNAME
109
110#define OPNAME cosh
112#undef OPNAME
113
114#define OPNAME sinh
116#undef OPNAME
117
118#define OPNAME tanh
120#undef OPNAME
121
122#define OPNAME acosh
124#undef OPNAME
125
126#define OPNAME asinh
128#undef OPNAME
129
130#define OPNAME atanh
132#undef OPNAME
133
134#define OPNAME abs
136#undef OPNAME
137
138#define OPNAME fabs
140#undef OPNAME
141
142#define OPNAME ceil
144#undef OPNAME
145
146#define OPNAME operator+
147#define OPER +
149#undef OPNAME
150#undef OPER
151
152#define OPNAME operator-
153#define OPER -
155#undef OPNAME
156#undef OPER
157
158#define OPNAME operator*
159#define OPER *
161#undef OPNAME
162#undef OPER
163
164#define OPNAME operator/
165#define OPER /
167#undef OPNAME
168#undef OPER
169
170#define OPNAME atan2
172#undef OPNAME
173
174#define OPNAME pow
176#undef OPNAME
177
178#define OPNAME max
180#undef OPNAME
181
182#define OPNAME min
184#undef OPNAME
185
186//#ifdef __CUDACC__
187//MP_BINARYOP_MACRO(max, ::max)
188//MP_BINARYOP_MACRO(min, ::min)
189//#else
190//MP_BINARYOP_MACRO(max, std::max)
191//MP_BINARYOP_MACRO(min, std::min)
192//#endif
193
194//-------------------------- Relational Operators -----------------------
195
196#define MP_RELOP_MACRO(OP) \
197namespace Sacado { \
198 namespace MP { \
199 \
200 template <typename O, typename T, int N, typename D> \
201 KOKKOS_INLINE_FUNCTION \
202 bool \
203 operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
204 const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
205 { \
206 return a.val() OP b.val(); \
207 } \
208 \
209 template <typename O, typename T, int N, typename D> \
210 KOKKOS_INLINE_FUNCTION \
211 bool \
212 operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
213 const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
214 { \
215 return a OP b.val(); \
216 } \
217 \
218 template <typename O, typename T, int N, typename D> \
219 KOKKOS_INLINE_FUNCTION \
220 bool \
221 operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
222 const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
223 { \
224 return a.val() OP b; \
225 } \
226 } \
227}
228
239
240#undef MP_RELOP_MACRO
241
242namespace Sacado {
243
244 namespace MP {
245
246 template <typename O, typename T, int N, typename D>
247 KOKKOS_INLINE_FUNCTION
249 {
250 return ! a.val();
251 }
252
253 } // namespace MP
254
255} // namespace Sacado
256
257
258//-------------------------- Boolean Operators -----------------------
259namespace Sacado {
260
261 namespace MP {
262
263 template <typename O, typename T, int N, typename D>
264 KOKKOS_INLINE_FUNCTION
266 bool is_zero = true;
267 for (int i=0; i<x.size(); i++)
268 is_zero = is_zero && (x.coeff(i) == 0.0);
269 return !is_zero;
270 }
271
272 } // namespace MP
273
274} // namespace Sacado
275
276#define PCE_BOOL_MACRO(OP) \
277namespace Sacado { \
278 namespace MP { \
279 \
280 template <typename O, typename T, int N, typename D> \
281 KOKKOS_INLINE_FUNCTION \
282 bool \
283 operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
284 const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
285 { \
286 return toBool(a) OP toBool(b); \
287 } \
288 \
289 template <typename O, typename T, int N, typename D> \
290 KOKKOS_INLINE_FUNCTION \
291 bool \
292 operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
293 const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
294 { \
295 return a OP toBool(b); \
296 } \
297 \
298 template <typename O, typename T, int N, typename D> \
299 KOKKOS_INLINE_FUNCTION \
300 bool \
301 operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
302 const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
303 { \
304 return toBool(a) OP b; \
305 } \
306 } \
307}
308
311
312#undef PCE_BOOL_MACRO
#define PCE_BOOL_MACRO(OP)
#define MP_RELOP_MACRO(OP)
#define PCE_BOOL_MACRO(OP)
Statically allocated storage class.
KOKKOS_INLINE_FUNCTION bool operator!(const Expr< T > &expr)
KOKKOS_INLINE_FUNCTION bool toBool(const Expr< T > &xx)