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