42 #ifndef SACADO_UQ_PCE_SCALARTRAITSIMP_HPP 43 #define SACADO_UQ_PCE_SCALARTRAITSIMP_HPP 45 #include "Teuchos_ScalarTraits.hpp" 46 #include "Teuchos_SerializationTraits.hpp" 47 #include "Teuchos_RCP.hpp" 48 #include "Teuchos_Assert.hpp" 49 #include "Sacado_mpl_apply.hpp" 50 #include "Teuchos_as.hpp" 59 template <
typename PCEType>
64 typedef Teuchos::ScalarTraits<value_type>
TVT;
70 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_mag_type>::type
storage_mag_type;
71 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_half_type>::type
storage_half_type;
72 typedef typename Sacado::mpl::apply<storage_type,ordinal_type,value_double_type>::type
storage_double_type;
75 typedef typename Sacado::mpl::apply<PCEType, storage_half_type>::type
halfPrecision;
76 typedef typename Sacado::mpl::apply<PCEType, storage_double_type>::type
doublePrecision;
111 return a.inner_product(b);
121 y.val() = TVT::conjugate(
x.val());
149 for (
int i=0; i<
x.size(); i++)
150 if (TVT::isnaninf(
x.fastAccessCoeff(i)))
155 static void seedrandom(
unsigned int s) { TVT::seedrandom(s); }
159 static const char *
name() {
return "Sacado::UQ::PCE<>"; }
174 template <
typename TypeTo,
typename PCEType>
176 typedef typename Sacado::ValueType<PCEType>::type
ValueT;
177 typedef Teuchos::ValueTypeConversionTraits<TypeTo,ValueT>
VTCT;
179 return VTCT::convert(t.val());
182 return VTCT::safeConvert(t.val());
187 template <
typename Ordinal,
typename PCEType>
189 typedef typename Sacado::ValueType<PCEType>::type
ValueT;
190 typedef Teuchos::SerializationTraits<Ordinal,ValueT>
vSerT;
191 typedef Teuchos::SerializationTraits<Ordinal,int>
iSerT;
192 typedef Teuchos::SerializationTraits<Ordinal,Ordinal>
oSerT;
206 for (
Ordinal i=0; i<count; i++) {
207 int sz = buffer[i].size();
208 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
209 Ordinal b2 = vSerT::fromCountToIndirectBytes(sz, buffer[i].coeff());
210 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
221 for (
Ordinal i=0; i<count; i++) {
223 int sz = buffer[i].size();
224 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &sz);
225 iSerT::serialize(1, &sz, b1, charBuffer);
229 Ordinal b2 = vSerT::fromCountToIndirectBytes(sz, buffer[i].coeff());
230 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
231 oSerT::serialize(1, &b2, b3, charBuffer);
233 vSerT::serialize(sz, buffer[i].coeff(), b2, charBuffer);
240 const char charBuffer[]) {
243 while (bytes_used < bytes) {
246 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
251 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
252 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
265 const char charBuffer[],
268 for (
Ordinal i=0; i<count; i++) {
271 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
272 const int *sz = iSerT::convertFromCharPtr(charBuffer);
278 if (buffer[i].size() != *sz)
279 buffer[i].reset(buffer[i].
cijk(), *sz);
280 buffer[i].copyForWrite();
283 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
284 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
286 vSerT::deserialize(*b2, charBuffer, *sz, buffer[i].coeff());
298 template <
typename Ordinal,
typename PCEType,
typename ValueSerializer>
311 typedef typename Sacado::ValueType<PCEType>::type
ValueT;
312 typedef Teuchos::SerializationTraits<Ordinal,int>
iSerT;
313 typedef Teuchos::SerializationTraits<Ordinal,Ordinal>
oSerT;
316 Teuchos::RCP<const ValueSerializer>
vs;
325 const Teuchos::RCP<const ValueSerializer>& vs_) :
340 const PCEType buffer[])
const {
344 for (
Ordinal i=0; i<count; i++) {
345 int my_sz = buffer[i].size();
355 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &
sz);
356 Ordinal b2 =
vs->fromCountToIndirectBytes(
sz, cx->coeff());
357 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
369 char charBuffer[])
const {
372 for (
Ordinal i=0; i<count; i++) {
374 int my_sz = buffer[i].size();
384 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &
sz);
385 iSerT::serialize(1, &
sz, b1, charBuffer);
389 Ordinal b2 =
vs->fromCountToIndirectBytes(
sz, cx->coeff());
390 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
391 oSerT::serialize(1, &b2, b3, charBuffer);
393 vs->serialize(
sz, cx->coeff(), b2, charBuffer);
402 const char charBuffer[])
const {
405 while (bytes_used < bytes) {
408 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
413 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
414 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
427 const char charBuffer[],
430 for (
Ordinal i=0; i<count; i++) {
433 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
434 const int *my_sz = iSerT::convertFromCharPtr(charBuffer);
438 buffer[i].reset(
cijk);
441 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
442 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
444 vs->deserialize(*b2, charBuffer, *my_sz, buffer[i].coeff());
458 #endif // SACADO_FAD_SCALARTRAITSIMP_HPP KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
static Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[])
Return the number of objects for bytes of storage.
Sacado::mpl::apply< storage_type, ordinal_type, value_half_type >::type storage_half_type
Stokhos::StandardStorage< int, double > storage_type
static void serialize(const Ordinal count, const PCEType buffer[], const Ordinal bytes, char charBuffer[])
Serialize to an indirect char[] buffer.
void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, PCEType buffer[]) const
Deserialize from an indirect char[] buffer.
Teuchos::SerializationTraits< Ordinal, Ordinal > oSerT
Serializer object for all PCE types.
Implementation for Teuchos::ScalarTraits for all PCE types.
static PCEType log10(const PCEType &x)
TVT::halfPrecision value_half_type
TVT::coordinateType coordinateType
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
PCESerializerImp(const cijk_type &cijk_, const Teuchos::RCP< const ValueSerializer > &vs_)
Implementation for Teuchos::ValueTypeConversionTraits for all PCE types.
static value_mag_type rmin()
static const bool isOrdinal
static magnitudeType real(const PCEType &x)
Sacado::mpl::apply< PCEType, storage_half_type >::type halfPrecision
Teuchos::SerializationTraits< Ordinal, int > iSerT
static value_mag_type base()
Ordinal fromCountToIndirectBytes(const Ordinal count, const PCEType buffer[]) const
Return the number of bytes for count objects.
static bool isnaninf(const PCEType &x)
static value_mag_type t()
static value_mag_type rnd()
static PCEType conjugate(const PCEType &x)
Teuchos::ValueTypeConversionTraits< TypeTo, ValueT > VTCT
TVT::doublePrecision value_double_type
static value_mag_type rmax()
static value_mag_type eps()
Sacado::ValueType< PCEType >::type ValueT
static const bool isComplex
static const bool hasMachineParameters
static magnitudeType imag(const PCEType &x)
Sacado::mpl::apply< storage_type, ordinal_type, value_double_type >::type storage_double_type
PCEType::storage_type storage_type
PCEType::cijk_type cijk_type
Typename of cijk.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
storage_type::ordinal_type ordinal_type
static const bool isComparable
ValueSerializer value_serializer_type
Typename of value serializer.
static PCEType squareroot(const PCEType &x)
static PCEType log(const PCEType &x)
static innerProductType innerProduct(const PCEType &a, const PCEType &b)
static TypeTo safeConvert(const PCEType t)
static value_mag_type sfmin()
Sacado::ValueType< PCEType >::type ValueT
Sacado::ValueType< PCEType >::type ValueT
static void seedrandom(unsigned int s)
void serialize(const Ordinal count, const PCEType buffer[], const Ordinal bytes, char charBuffer[]) const
Serialize to an indirect char[] buffer.
Sacado::mpl::apply< storage_type, ordinal_type, value_mag_type >::type storage_mag_type
Sacado::Random< double > rnd
storage_type::value_type value_type
Teuchos::ScalarTraits< value_type > TVT
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 const bool supportsDirectSerialization
Whether the type T supports direct serialization.
static const char * name()
Teuchos::SerializationTraits< Ordinal, Ordinal > oSerT
static const bool supportsDirectSerialization
Whether the type T supports direct serialization.
Sacado::UQ::PCE< storage_type > PCEType
Teuchos::SerializationTraits< Ordinal, ValueT > vSerT
static value_mag_type emax()
static PCEType pow(const PCEType &x, const PCEType &y)
Teuchos::SerializationTraits< Ordinal, int > iSerT
static Ordinal fromCountToIndirectBytes(const Ordinal count, const PCEType buffer[])
Return the number of bytes for count objects.
static TypeTo convert(const PCEType t)
Implementation of Teuchos::SerializationTraits for all PCE types.
TVT::magnitudeType value_mag_type
cijk_type getSerializerCijk() const
Return specified serializer size.
static value_mag_type emin()
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
value_mag_type magnitudeType
Sacado::mpl::apply< PCEType, storage_double_type >::type doublePrecision
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[]) const
Return the number of objects for bytes of storage.
value_type innerProductType
static void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, PCEType buffer[])
Deserialize from an indirect char[] buffer.
Teuchos::RCP< const value_serializer_type > getValueSerializer() const
Get nested value serializer.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
Teuchos::RCP< const ValueSerializer > vs
static value_mag_type prec()
static magnitudeType magnitude(const PCEType &a)