42 #ifndef SACADO_UQ_PCE_SCALARTRAITSIMP_HPP 43 #define SACADO_UQ_PCE_SCALARTRAITSIMP_HPP 45 #ifdef HAVE_SACADO_TEUCHOS 51 #include "Sacado_mpl_apply.hpp" 61 template <
typename PCEType>
62 struct PCEScalarTraitsImp {
71 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_mag_type>::type storage_mag_type;
72 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_half_type>::type storage_half_type;
73 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_double_type>::type storage_double_type;
75 typedef typename Sacado::mpl::apply<PCEType, storage_mag_type>::type magnitudeType;
77 typedef typename Sacado::mpl::apply<PCEType, storage_half_type>::type halfPrecision;
78 typedef typename Sacado::mpl::apply<PCEType, storage_double_type>::type doublePrecision;
84 static const bool isComparable =
86 static const bool hasMachineParameters =
129 static magnitudeType magnitude(
const PCEType& a) {
133 static innerProductType innerProduct(
const PCEType& a,
const PCEType& b) {
134 return a.inner_product(b);
174 static bool isnaninf(
const PCEType&
x) {
175 for (
int i=0; i<
x.size(); i++)
181 static void seedrandom(
unsigned int s) {
189 static const char * name() {
190 return "Sacado::UQ::PCE<>";
218 static bool is_pce_real(
const PCEType&
x) {
222 for (
int i=0; i<
x.size(); i++)
223 if (!is_complex_real(
x.fastAccessCoeff(i)))
232 template <
typename TypeTo,
typename PCEType>
233 struct PCEValueTypeConversionTraitsImp {
234 typedef typename Sacado::ValueType<PCEType>::type ValueT;
236 static TypeTo convert(
const PCEType t ) {
237 return VTCT::convert(t.val());
239 static TypeTo safeConvert(
const PCEType t ) {
240 return VTCT::safeConvert(t.val());
245 template <
typename Ordinal,
typename PCEType>
246 class PCESerializationTraitsImp {
247 typedef typename Sacado::ValueType<PCEType>::type ValueT;
255 static const bool supportsDirectSerialization =
false;
264 for (
Ordinal i=0; i<count; i++) {
265 int sz = buffer[i].size();
266 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
267 Ordinal b2 = vSerT::fromCountToIndirectBytes(sz, buffer[i].coeff());
268 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
275 static void serialize (
const Ordinal count,
279 for (
Ordinal i=0; i<count; i++) {
281 int sz = buffer[i].size();
282 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
283 iSerT::serialize(1, &sz, b1, charBuffer);
287 Ordinal b2 = vSerT::fromCountToIndirectBytes(sz, buffer[i].coeff());
288 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
289 oSerT::serialize(1, &b2, b3, charBuffer);
291 vSerT::serialize(sz, buffer[i].coeff(), b2, charBuffer);
298 const char charBuffer[]) {
301 while (bytes_used < bytes) {
304 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
309 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
310 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
322 static void deserialize (
const Ordinal bytes,
323 const char charBuffer[],
326 for (
Ordinal i=0; i<count; i++) {
329 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
330 const int *sz = iSerT::convertFromCharPtr(charBuffer);
336 if (buffer[i].size() != *sz)
337 buffer[i].reset(buffer[i].
cijk(), *sz);
338 buffer[i].copyForWrite();
341 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
342 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
344 vSerT::deserialize(*b2, charBuffer, *sz, buffer[i].coeff());
356 template <
typename Ordinal,
typename PCEType,
typename ValueSerializer>
357 class PCESerializerImp {
362 typedef ValueSerializer value_serializer_type;
365 typedef typename PCEType::cijk_type cijk_type;
369 typedef typename Sacado::ValueType<PCEType>::type ValueT;
380 static const bool supportsDirectSerialization =
false;
382 PCESerializerImp(
const cijk_type& cijk_,
384 cijk(cijk_), vs(vs_), sz(
cijk.dimension()) {}
387 cijk_type getSerializerCijk()
const {
return cijk; }
398 const PCEType buffer[])
const {
402 for (
Ordinal i=0; i<count; i++) {
403 int my_sz = buffer[i].size();
413 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
414 Ordinal b2 = vs->fromCountToIndirectBytes(sz, cx->coeff());
415 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
424 void serialize (
const Ordinal count,
427 char charBuffer[])
const {
430 for (
Ordinal i=0; i<count; i++) {
432 int my_sz = buffer[i].size();
442 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
443 iSerT::serialize(1, &sz, b1, charBuffer);
447 Ordinal b2 = vs->fromCountToIndirectBytes(sz, cx->coeff());
448 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
449 oSerT::serialize(1, &b2, b3, charBuffer);
451 vs->serialize(sz, cx->coeff(), b2, charBuffer);
460 const char charBuffer[])
const {
463 while (bytes_used < bytes) {
466 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
471 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
472 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
484 void deserialize (
const Ordinal bytes,
485 const char charBuffer[],
488 for (
Ordinal i=0; i<count; i++) {
491 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
492 const int *my_sz = iSerT::convertFromCharPtr(charBuffer);
496 buffer[i].reset(
cijk);
499 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
500 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
502 vs->deserialize(*b2, charBuffer, *my_sz, buffer[i].coeff());
516 #endif // HAVE_SACADO_TEUCHOS 518 #endif // SACADO_FAD_SCALARTRAITSIMP_HPP KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
Stokhos::StandardStorage< int, double > storage_type
static magnitudeType eps()
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
static magnitudeType real(T a)
static magnitudeType emax()
static magnitudeType base()
static magnitudeType rmax()
static magnitudeType sfmin()
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
static magnitudeType prec()
static magnitudeType rmin()
Sacado::Random< double > rnd
static void seedrandom(unsigned int s)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
static magnitudeType magnitude(T a)
Sacado::UQ::PCE< storage_type > PCEType
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
static magnitudeType emin()
static magnitudeType rnd()
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y