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