Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
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 operator+
138 #define OPER +
140 #undef OPNAME
141 #undef OPER
142 
143 #define OPNAME operator-
144 #define OPER -
146 #undef OPNAME
147 #undef OPER
148 
149 #define OPNAME operator*
150 #define OPER *
152 #undef OPNAME
153 #undef OPER
154 
155 #define OPNAME operator/
156 #define OPER /
158 #undef OPNAME
159 #undef OPER
160 
161 #define OPNAME atan2
163 #undef OPNAME
164 
165 #define OPNAME pow
167 #undef OPNAME
168 
169 #define OPNAME max
171 #undef OPNAME
172 
173 #define OPNAME min
175 #undef OPNAME
176 
177 //#ifdef __CUDACC__
178 //MP_BINARYOP_MACRO(max, ::max)
179 //MP_BINARYOP_MACRO(min, ::min)
180 //#else
181 //MP_BINARYOP_MACRO(max, std::max)
182 //MP_BINARYOP_MACRO(min, std::min)
183 //#endif
184 
185 //-------------------------- Relational Operators -----------------------
186 
187 #define MP_RELOP_MACRO(OP) \
188 namespace Sacado { \
189  namespace MP { \
190  \
191  template <typename O, typename T, int N, typename D> \
192  KOKKOS_INLINE_FUNCTION \
193  bool \
194  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
195  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
196  { \
197  return a.val() OP b.val(); \
198  } \
199  \
200  template <typename O, typename T, int N, typename D> \
201  KOKKOS_INLINE_FUNCTION \
202  bool \
203  operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
204  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
205  { \
206  return a 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 Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
213  const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
214  { \
215  return a.val() OP b; \
216  } \
217  } \
218 }
219 
220 MP_RELOP_MACRO(==)
221 MP_RELOP_MACRO(!=)
224 MP_RELOP_MACRO(<=)
225 MP_RELOP_MACRO(>=)
226 MP_RELOP_MACRO(<<=)
227 MP_RELOP_MACRO(>>=)
230 
231 #undef MP_RELOP_MACRO
232 
233 namespace Sacado {
234 
235  namespace MP {
236 
237  template <typename O, typename T, int N, typename D>
238  KOKKOS_INLINE_FUNCTION
240  {
241  return ! a.val();
242  }
243 
244  } // namespace MP
245 
246 } // namespace Sacado
247 
248 
249 //-------------------------- Boolean Operators -----------------------
250 namespace Sacado {
251 
252  namespace MP {
253 
254  template <typename O, typename T, int N, typename D>
255  KOKKOS_INLINE_FUNCTION
257  bool is_zero = true;
258  for (int i=0; i<x.size(); i++)
259  is_zero = is_zero && (x.coeff(i) == 0.0);
260  return !is_zero;
261  }
262 
263  } // namespace MP
264 
265 } // namespace Sacado
266 
267 #define PCE_BOOL_MACRO(OP) \
268 namespace Sacado { \
269  namespace MP { \
270  \
271  template <typename O, typename T, int N, typename D> \
272  KOKKOS_INLINE_FUNCTION \
273  bool \
274  operator OP (const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
275  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
276  { \
277  return toBool(a) OP toBool(b); \
278  } \
279  \
280  template <typename O, typename T, int N, typename D> \
281  KOKKOS_INLINE_FUNCTION \
282  bool \
283  operator OP (const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& a, \
284  const Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& b) \
285  { \
286  return 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 Vector< Stokhos::StaticFixedStorage<O,T,N,D> >& a, \
293  const typename Vector< Stokhos::StaticFixedStorage<O,T,N,D> >::value_type& b) \
294  { \
295  return toBool(a) OP b; \
296  } \
297  } \
298 }
299 
300 PCE_BOOL_MACRO(&&)
301 PCE_BOOL_MACRO(||)
302 
303 #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)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
#define MP_RELOP_MACRO(OP)
#define PCE_BOOL_MACRO(OP)