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