Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_ArithTraits_MP_Vector.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 #ifndef KOKKOS_ARITHTRAITS_MP_VECTOR_HPP
43 #define KOKKOS_ARITHTRAITS_MP_VECTOR_HPP
44 
45 #include "Sacado_MP_Vector.hpp"
46 #include "Kokkos_ArithTraits.hpp"
47 #include "KokkosBatched_Vector.hpp"
48 
49 //----------------------------------------------------------------------------
50 // Specializations of Kokkos::ArithTraits for Sacado::MP::Vector scalar type
51 //----------------------------------------------------------------------------
52 
53 namespace Kokkos {
54 namespace Details {
55 
56 template <typename S>
57 class ArithTraits< Sacado::MP::Vector<S> > {
58 public:
60 
63  typedef ArithTraits<base_value_type> BAT;
64 
65 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
66  typedef typename BAT::mag_type mag_type;
67 #else
68  typedef val_type mag_type;
69 #endif
70 
71  static const bool is_specialized = true;
72  static const bool is_signed = BAT::is_signed;
73  static const bool is_integer = BAT::is_integer;
74  static const bool is_exact = BAT::is_exact;
75  static const bool is_complex = BAT::is_complex;
76 
77  static KOKKOS_FORCEINLINE_FUNCTION bool isInf (const val_type& x) {
78  bool res = false;
79  for (ordinal_type i=0; i<x.size(); ++i)
80  res = res || BAT::isInf(x.fastAccessCoeff(i));
81  return res;
82  }
83  static KOKKOS_FORCEINLINE_FUNCTION bool isNan (const val_type& x) {
84  bool res = false;
85  for (ordinal_type i=0; i<x.size(); ++i)
86  res = res || BAT::isInf(x.fastAccessCoeff(i));
87  return res;
88  }
89  static KOKKOS_FORCEINLINE_FUNCTION mag_type abs (const val_type& x) {
90  const ordinal_type sz = x.size();
91 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
92  mag_type n = mag_type(0.0);
93  for (ordinal_type i=0; i<sz; ++i)
94  n += BAT::abs( x.fastAccessCoeff(i) );
95 #else
96  mag_type n(sz, 0.0);
97  for (ordinal_type i=0; i<sz; ++i)
98  n.fastAccessCoeff(i) = BAT::abs( x.fastAccessCoeff(i) );
99 #endif
100  return n;
101  }
102  static KOKKOS_FORCEINLINE_FUNCTION val_type zero () {
103  return val_type(0.0);
104  }
105  static KOKKOS_FORCEINLINE_FUNCTION val_type one () {
106  return val_type(1.0);
107  }
108  static KOKKOS_FORCEINLINE_FUNCTION val_type min () {
109  return BAT::min();
110  }
111  static KOKKOS_FORCEINLINE_FUNCTION val_type max () {
112  return BAT::max();
113  }
114  static KOKKOS_FORCEINLINE_FUNCTION val_type real (const val_type& x) {
115  const ordinal_type sz = x.size();
116  val_type y(sz, base_value_type(0.0));
117  for (ordinal_type i=0; i<sz; ++i)
118  y.fastAccessCoeff(i) = BAT::real(x.fastAccessCoeff(i));
119  return y;
120  }
121  static KOKKOS_FORCEINLINE_FUNCTION val_type imag (const val_type& x) {
122  const ordinal_type sz = x.size();
123  val_type y(sz, base_value_type(0.0));
124  for (ordinal_type i=0; i<sz; ++i)
125  y.fastAccessCoeff(i) = BAT::imag(x.fastAccessCoeff(i));
126  return y;
127  }
128  static KOKKOS_FORCEINLINE_FUNCTION val_type conj (const val_type& x) {
129  const ordinal_type sz = x.size();
130  val_type y(sz, base_value_type(0.0));
131  for (ordinal_type i=0; i<sz; ++i)
132  y.fastAccessCoeff(i) = BAT::conj(x.fastAccessCoeff(i));
133  return y;
134  }
135  static KOKKOS_FORCEINLINE_FUNCTION val_type pow (const val_type& x,
136  const val_type& y) {
137  return std::pow(x, y);
138  }
139  static KOKKOS_FORCEINLINE_FUNCTION val_type sqrt (const val_type& x) {
140  return std::sqrt(x);
141  }
142  static KOKKOS_FORCEINLINE_FUNCTION val_type log (const val_type& x) {
143  return std::log(x);
144  }
145  static KOKKOS_FORCEINLINE_FUNCTION val_type log10 (const val_type& x) {
146  return std::log10(x);
147  }
148  static KOKKOS_FORCEINLINE_FUNCTION val_type nan () {
149  return BAT::nan();
150  }
151  static KOKKOS_FORCEINLINE_FUNCTION mag_type epsilon () {
152  return BAT::epsilon();
153  }
154 
155  // Backwards compatibility with Teuchos::ScalarTraits.
157  typedef typename BAT::halfPrecision base_half_precision;
158  typedef typename BAT::doublePrecision base_double_precision;
159  typedef typename Sacado::mpl::apply<S,ordinal_type,base_half_precision>::type half_storage;
160  typedef typename Sacado::mpl::apply<S,ordinal_type,base_double_precision>::type double_storage;
163  static const bool isComplex = is_complex;
164  static const bool isOrdinal = is_integer;
165  static const bool isComparable = BAT::isComparable;
166  static const bool hasMachineParameters = BAT::hasMachineParameters;
167  static bool isnaninf (const val_type& x) {
168  return isNan (x) || isInf (x);
169  }
170  static KOKKOS_FORCEINLINE_FUNCTION mag_type magnitude (const val_type& x) {
171  return abs (x);
172  }
173  static KOKKOS_FORCEINLINE_FUNCTION val_type conjugate (const val_type& x) {
174  return conj (x);
175  }
176  static std::string name () {
177  return Sacado::StringName<val_type>::eval();
178  }
179  static KOKKOS_FORCEINLINE_FUNCTION val_type squareroot (const val_type& x) {
180  return sqrt (x);
181  }
182  static KOKKOS_FORCEINLINE_FUNCTION mag_type eps () {
183  return epsilon ();
184  }
185  static KOKKOS_FORCEINLINE_FUNCTION mag_type sfmin () {
186  return BAT::sfmin();
187  }
188  static KOKKOS_FORCEINLINE_FUNCTION int base () {
189  return BAT::base();
190  }
191  static KOKKOS_FORCEINLINE_FUNCTION mag_type prec () {
192  return BAT::prec();
193  }
194  static KOKKOS_FORCEINLINE_FUNCTION int t () {
195  return BAT::t();
196  }
197  static KOKKOS_FORCEINLINE_FUNCTION mag_type rnd () {
198  return BAT::rnd();
199  }
200  static KOKKOS_FORCEINLINE_FUNCTION int emin () {
201  return BAT::emin();
202  }
203  static KOKKOS_FORCEINLINE_FUNCTION mag_type rmin () {
204  return BAT::rmin();
205  }
206  static KOKKOS_FORCEINLINE_FUNCTION int emax () {
207  return BAT::emax();
208  }
209  static KOKKOS_FORCEINLINE_FUNCTION mag_type rmax () {
210  return BAT::rmax();
211  }
212 };
213 
214 }
215 }
216 
217 namespace KokkosBatched {
218 
219  template <typename S>
220  struct MagnitudeScalarType< Sacado::MP::Vector<S> > {
222  typedef typename Kokkos::Details::ArithTraits<val_type>::mag_type type;
223  };
224 
225 }
226 
227 #endif /* #ifndef KOKKOS_ARITHTRAITS_MP_VECTOR_HPP */
static KOKKOS_FORCEINLINE_FUNCTION val_type conj(const val_type &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
static KOKKOS_FORCEINLINE_FUNCTION val_type real(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type sqrt(const val_type &x)
Sacado::mpl::apply< S, ordinal_type, base_half_precision >::type half_storage
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
static KOKKOS_FORCEINLINE_FUNCTION val_type pow(const val_type &x, const val_type &y)
static KOKKOS_FORCEINLINE_FUNCTION bool isInf(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type imag(const val_type &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
static KOKKOS_FORCEINLINE_FUNCTION mag_type abs(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION bool isNan(const val_type &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Sacado::Random< double > rnd
static KOKKOS_FORCEINLINE_FUNCTION val_type squareroot(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type log10(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type log(const val_type &x)
Sacado::mpl::apply< S, ordinal_type, base_double_precision >::type double_storage
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
int n
static KOKKOS_FORCEINLINE_FUNCTION mag_type magnitude(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type conjugate(const val_type &x)