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 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_ARITHTRAITS_MP_VECTOR_HPP
11 #define KOKKOS_ARITHTRAITS_MP_VECTOR_HPP
12 
13 #include "Sacado_MP_Vector.hpp"
14 #if KOKKOS_VERSION >= 40799
15 #include "KokkosKernels_ArithTraits.hpp"
16 #else
17 #include "Kokkos_ArithTraits.hpp"
18 #endif
19 #include "KokkosBatched_Vector.hpp"
20 
21 //----------------------------------------------------------------------------
22 // Specializations of Kokkos{Kernels}::ArithTraits for Sacado::MP::Vector scalar type
23 //----------------------------------------------------------------------------
24 
25 #if KOKKOS_VERSION >= 40799
26 namespace KokkosKernels {
27 #else
28 namespace Kokkos {
29 #endif
30 
31 template <typename S>
32 class ArithTraits< Sacado::MP::Vector<S> > {
33 public:
35 
38  typedef ArithTraits<base_value_type> BAT;
39 
40 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
41  typedef typename BAT::mag_type mag_type;
42 #else
43  typedef val_type mag_type;
44 #endif
45 
46  static const bool is_specialized = true;
47  static const bool is_signed = BAT::is_signed;
48  static const bool is_integer = BAT::is_integer;
49  static const bool is_exact = BAT::is_exact;
50  static const bool is_complex = BAT::is_complex;
51 
52  static KOKKOS_FORCEINLINE_FUNCTION bool isInf (const val_type& x) {
53  bool res = false;
54  for (ordinal_type i=0; i<x.size(); ++i)
55  res = res || BAT::isInf(x.fastAccessCoeff(i));
56  return res;
57  }
58  static KOKKOS_FORCEINLINE_FUNCTION bool isNan (const val_type& x) {
59  bool res = false;
60  for (ordinal_type i=0; i<x.size(); ++i)
61  res = res || BAT::isInf(x.fastAccessCoeff(i));
62  return res;
63  }
64  static KOKKOS_FORCEINLINE_FUNCTION mag_type abs (const val_type& x) {
65  const ordinal_type sz = x.size();
66 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
67  mag_type n = mag_type(0.0);
68  for (ordinal_type i=0; i<sz; ++i)
69  n += BAT::abs( x.fastAccessCoeff(i) );
70 #else
71  mag_type n(sz, 0.0);
72  for (ordinal_type i=0; i<sz; ++i)
73  n.fastAccessCoeff(i) = BAT::abs( x.fastAccessCoeff(i) );
74 #endif
75  return n;
76  }
77  static KOKKOS_FORCEINLINE_FUNCTION val_type zero () {
78  return val_type(0.0);
79  }
80  static KOKKOS_FORCEINLINE_FUNCTION val_type one () {
81  return val_type(1.0);
82  }
83  static KOKKOS_FORCEINLINE_FUNCTION val_type min () {
84  return BAT::min();
85  }
86  static KOKKOS_FORCEINLINE_FUNCTION val_type max () {
87  return BAT::max();
88  }
89  static KOKKOS_FORCEINLINE_FUNCTION val_type real (const val_type& x) {
90  const ordinal_type sz = x.size();
91  val_type y(sz, base_value_type(0.0));
92  for (ordinal_type i=0; i<sz; ++i)
93  y.fastAccessCoeff(i) = BAT::real(x.fastAccessCoeff(i));
94  return y;
95  }
96  static KOKKOS_FORCEINLINE_FUNCTION val_type imag (const val_type& x) {
97  const ordinal_type sz = x.size();
98  val_type y(sz, base_value_type(0.0));
99  for (ordinal_type i=0; i<sz; ++i)
100  y.fastAccessCoeff(i) = BAT::imag(x.fastAccessCoeff(i));
101  return y;
102  }
103  static KOKKOS_FORCEINLINE_FUNCTION val_type conj (const val_type& x) {
104  const ordinal_type sz = x.size();
105  val_type y(sz, base_value_type(0.0));
106  for (ordinal_type i=0; i<sz; ++i)
107  y.fastAccessCoeff(i) = BAT::conj(x.fastAccessCoeff(i));
108  return y;
109  }
110  static KOKKOS_FORCEINLINE_FUNCTION val_type pow (const val_type& x,
111  const val_type& y) {
112  return std::pow(x, y);
113  }
114  static KOKKOS_FORCEINLINE_FUNCTION val_type sqrt (const val_type& x) {
115  return std::sqrt(x);
116  }
117  static KOKKOS_FORCEINLINE_FUNCTION val_type log (const val_type& x) {
118  return std::log(x);
119  }
120  static KOKKOS_FORCEINLINE_FUNCTION val_type log10 (const val_type& x) {
121  return std::log10(x);
122  }
123  static KOKKOS_FORCEINLINE_FUNCTION val_type nan () {
124  return BAT::nan();
125  }
126  static KOKKOS_FORCEINLINE_FUNCTION mag_type epsilon () {
127  return BAT::epsilon();
128  }
129 
130  // Backwards compatibility with Teuchos::ScalarTraits.
132  typedef typename BAT::halfPrecision base_half_precision;
133  typedef typename BAT::doublePrecision base_double_precision;
134  typedef typename Sacado::mpl::apply<S,ordinal_type,base_half_precision>::type half_storage;
135  typedef typename Sacado::mpl::apply<S,ordinal_type,base_double_precision>::type double_storage;
138  static const bool isComplex = is_complex;
139  static const bool isOrdinal = is_integer;
140  static const bool isComparable = BAT::isComparable;
141  static const bool hasMachineParameters = BAT::hasMachineParameters;
142  static bool isnaninf (const val_type& x) {
143  return isNan (x) || isInf (x);
144  }
145  static KOKKOS_FORCEINLINE_FUNCTION mag_type magnitude (const val_type& x) {
146  return abs (x);
147  }
148  static KOKKOS_FORCEINLINE_FUNCTION val_type conjugate (const val_type& x) {
149  return conj (x);
150  }
151  static std::string name () {
152  return Sacado::StringName<val_type>::eval();
153  }
154  static KOKKOS_FORCEINLINE_FUNCTION val_type squareroot (const val_type& x) {
155  return sqrt (x);
156  }
157  static KOKKOS_FORCEINLINE_FUNCTION mag_type eps () {
158  return epsilon ();
159  }
160  static KOKKOS_FORCEINLINE_FUNCTION mag_type sfmin () {
161  return BAT::sfmin();
162  }
163  static KOKKOS_FORCEINLINE_FUNCTION int base () {
164  return BAT::base();
165  }
166  static KOKKOS_FORCEINLINE_FUNCTION mag_type prec () {
167  return BAT::prec();
168  }
169  static KOKKOS_FORCEINLINE_FUNCTION int t () {
170  return BAT::t();
171  }
172  static KOKKOS_FORCEINLINE_FUNCTION mag_type rnd () {
173  return BAT::rnd();
174  }
175  static KOKKOS_FORCEINLINE_FUNCTION int emin () {
176  return BAT::emin();
177  }
178  static KOKKOS_FORCEINLINE_FUNCTION mag_type rmin () {
179  return BAT::rmin();
180  }
181  static KOKKOS_FORCEINLINE_FUNCTION int emax () {
182  return BAT::emax();
183  }
184  static KOKKOS_FORCEINLINE_FUNCTION mag_type rmax () {
185  return BAT::rmax();
186  }
187 };
188 
189 } // namespace Kokkos
190 
191 namespace KokkosBatched {
192 
193  template <typename S>
194  struct MagnitudeScalarType< Sacado::MP::Vector<S> > {
196 #if KOKKOS_VERSION >= 40799
197  typedef typename KokkosKernels::ArithTraits<val_type>::mag_type type;
198 #else
199  typedef typename Kokkos::ArithTraits<val_type>::mag_type type;
200 #endif
201  };
202 
203 }
204 
205 #endif /* #ifndef KOKKOS_ARITHTRAITS_MP_VECTOR_HPP */
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
static KOKKOS_FORCEINLINE_FUNCTION mag_type magnitude(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type conjugate(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION mag_type eps()
static KOKKOS_FORCEINLINE_FUNCTION mag_type abs(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type pow(const val_type &x, const val_type &y)
static KOKKOS_FORCEINLINE_FUNCTION val_type real(const val_type &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
static KOKKOS_FORCEINLINE_FUNCTION val_type sqrt(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type log10(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION mag_type epsilon()
static KOKKOS_FORCEINLINE_FUNCTION val_type one()
static KOKKOS_FORCEINLINE_FUNCTION mag_type rmin()
static KOKKOS_FORCEINLINE_FUNCTION val_type zero()
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
static KOKKOS_FORCEINLINE_FUNCTION mag_type sfmin()
static KOKKOS_FORCEINLINE_FUNCTION val_type max()
static KOKKOS_FORCEINLINE_FUNCTION val_type min()
static KOKKOS_FORCEINLINE_FUNCTION val_type nan()
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Sacado::mpl::apply< S, ordinal_type, base_double_precision >::type double_storage
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
static KOKKOS_FORCEINLINE_FUNCTION bool isNan(const val_type &x)
Sacado::Random< double > rnd
static KOKKOS_FORCEINLINE_FUNCTION mag_type rmax()
static KOKKOS_FORCEINLINE_FUNCTION val_type squareroot(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type log(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION val_type conj(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION mag_type prec()
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
static KOKKOS_FORCEINLINE_FUNCTION mag_type rnd()
static KOKKOS_FORCEINLINE_FUNCTION bool isInf(const val_type &x)
int n
Sacado::mpl::apply< S, ordinal_type, base_half_precision >::type half_storage
static KOKKOS_FORCEINLINE_FUNCTION val_type imag(const val_type &x)