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