42#ifndef SACADO_MP_SCALAR_TRAITS_IMP_HPP
43#define SACADO_MP_SCALAR_TRAITS_IMP_HPP
45#include "Teuchos_ScalarTraits.hpp"
46#include "Teuchos_SerializationTraits.hpp"
47#include "Teuchos_SerializationTraitsHelpers.hpp"
48#include "Teuchos_Assert.hpp"
49#include "Teuchos_TestForException.hpp"
50#include "Sacado_mpl_apply.hpp"
55 template <
typename S,
bool reduct_across_vector>
66 typedef Teuchos::ScalarTraits<value_type>
TVT;
72 typedef typename Sacado::mpl::apply<S,ordinal_type,value_mag_type>::type
storage_mag_type;
73 typedef typename Sacado::mpl::apply<S,ordinal_type,value_half_type>::type
storage_half_type;
79 typedef typename Teuchos::ScalarTraits<value_type>::coordinateType
coordinateType;
81 static const bool isComplex = TVT::isComplex;
82 static const bool isOrdinal = TVT::isOrdinal;
83 static const bool isComparable = TVT::isComparable;
84 static const bool hasMachineParameters = TVT::hasMachineParameters;
124 for (
int i=0; i<sz; i++)
125 y.fastAccessCoeff(i) = TVT::conjugate(x.fastAccessCoeff(i));
154 for (
int i=0; i<x.size(); i++)
155 if (TVT::isnaninf(x.fastAccessCoeff(i)))
160 static void seedrandom(
unsigned int s) { TVT::seedrandom(s); }
164 static const char *
name() {
return "Sacado::MP::Vector<>"; }
169 return std::pow(x,y);
181 template <
typename S>
186 typedef Teuchos::ScalarTraits<value_type>
TVT;
199 typedef typename Teuchos::ScalarTraits<value_type>::coordinateType
coordinateType;
201 static const bool isComplex = TVT::isComplex;
202 static const bool isOrdinal = TVT::isOrdinal;
203 static const bool isComparable = TVT::isComparable;
204 static const bool hasMachineParameters = TVT::hasMachineParameters;
238 for (
int i=0; i<sz; i++)
239 y.fastAccessCoeff(i) = TVT::conjugate(x.fastAccessCoeff(i));
246 for (
int i=0; i<sz; i++)
247 y.fastAccessCoeff(i) = TVT::real(x.fastAccessCoeff(i));
254 for (
int i=0; i<sz; i++)
255 y.fastAccessCoeff(i) = TVT::imag(x.fastAccessCoeff(i));
262 for (
int i=0; i<x.size(); i++)
263 if (TVT::isnaninf(x.fastAccessCoeff(i)))
268 static void seedrandom(
unsigned int s) { TVT::seedrandom(s); }
272 static const char *
name() {
return "Sacado::MP::Vector<>"; }
277 return std::pow(x,y);
287 template <
typename Ordinal,
typename VecType,
typename Serializer>
293 typedef typename Sacado::ValueType<VecType>::type
ValueT;
296 typedef Teuchos::SerializationTraits<Ordinal,int>
iSerT;
299 typedef Teuchos::SerializationTraits<Ordinal,Ordinal>
oSerT;
312 const VecType buffer[],
317 for (
Ordinal i=0; i<count; i++) {
318 int my_sz = buffer[i].size();
320 if (sz == 0) tot_sz = my_sz;
321 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
322 if (tot_sz != my_sz) {
331 Ordinal b2 = vs.fromCountToIndirectBytes(tot_sz, cx->coeff());
332 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
343 const VecType buffer[],
349 for (
Ordinal i=0; i<count; i++) {
351 int my_sz = buffer[i].size();
353 if (sz == 0) tot_sz = my_sz;
354 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
355 iSerT::serialize(1, &tot_sz, b1, charBuffer);
359 if (tot_sz != my_sz) {
368 Ordinal b2 = vs.fromCountToIndirectBytes(tot_sz, cx->coeff());
369 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
370 oSerT::serialize(1, &b2, b3, charBuffer);
372 vs.serialize(tot_sz, cx->coeff(), b2, charBuffer);
382 const char charBuffer[],
386 while (bytes_used < bytes) {
389 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
394 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
395 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
409 const char charBuffer[],
413 for (
Ordinal i=0; i<count; i++) {
416 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
417 const int *my_sz = iSerT::convertFromCharPtr(charBuffer);
422 if (sz == 0) tot_sz = *my_sz;
423 buffer[i] = VecType(tot_sz,
ValueT(0.0));
426 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
427 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
429 vs.deserialize(*b2, charBuffer, *my_sz, buffer[i].coeff());
439 template <
typename Ordinal,
typename VecType,
bool is_static = false>
445 typedef typename Sacado::ValueType<VecType>::type
ValueT;
448 typedef Teuchos::DefaultSerializer<Ordinal,ValueT>
DS;
454 typedef SerializationImp<Ordinal,VecType,ValueSerializer>
Imp;
460 Imp::supportsDirectSerialization;
467 const VecType buffer[]) {
468 return Imp::fromCountToIndirectBytes(
469 DS::getDefaultSerializer(), count, buffer);
474 const VecType buffer[],
478 DS::getDefaultSerializer(), count, buffer, bytes, charBuffer);
483 const char charBuffer[]) {
484 return Imp::fromIndirectBytesToCount(
485 DS::getDefaultSerializer(), bytes, charBuffer);
490 const char charBuffer[],
494 DS::getDefaultSerializer(), bytes, charBuffer, count, buffer);
502 template <
typename Ordinal,
typename VecType>
504 typedef typename Sacado::ValueType<VecType>::type
ValueT;
505 typedef Teuchos::SerializationTraits<Ordinal,ValueT>
vSerT;
506 typedef Teuchos::DirectSerializationTraits<Ordinal,VecType>
DSerT;
511 vSerT::supportsDirectSerialization;
518 return DSerT::fromCountToDirectBytes(count);
523 return DSerT::convertToCharPtr(ptr);
528 return DSerT::convertToCharPtr(ptr);
533 return DSerT::fromDirectBytesToCount(bytes);
538 return DSerT::convertFromCharPtr(ptr);
543 return DSerT::convertFromCharPtr(ptr);
553 const VecType buffer[]) {
555 return DSerT::fromCountToIndirectBytes(count, buffer);
557 return STI::fromCountToIndirectBytes(count, buffer);
562 const VecType buffer[],
566 return DSerT::serialize(count, buffer, bytes, charBuffer);
568 return STI::serialize(count, buffer, bytes, charBuffer);
573 const char charBuffer[]) {
575 return DSerT::fromIndirectBytesToCount(bytes, charBuffer);
577 return STI::fromIndirectBytesToCount(bytes, charBuffer);
582 const char charBuffer[],
586 return DSerT::deserialize(bytes, charBuffer, count, buffer);
588 return STI::deserialize(bytes, charBuffer, count, buffer);
596 template <
typename Ordinal,
typename VecType,
typename ValueSerializer>
602 typedef SerializationImp<Ordinal,VecType,ValueSerializer>
Imp;
605 Teuchos::RCP<const ValueSerializer>
vs;
617 Imp::supportsDirectSerialization;
636 const VecType buffer[])
const {
637 return Imp::fromCountToIndirectBytes(*
vs, count, buffer,
sz);
642 const VecType buffer[],
644 char charBuffer[])
const {
645 Imp::serialize(*
vs, count, buffer, bytes, charBuffer,
sz);
650 const char charBuffer[])
const {
651 return Imp::fromIndirectBytesToCount(*
vs, bytes, charBuffer,
sz);
656 const char charBuffer[],
658 VecType buffer[])
const {
659 return Imp::deserialize(*
vs, bytes, charBuffer, count, buffer,
sz);
An indirect serialization object for all Vector types.
Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[]) const
Return the number of objects for bytes of storage.
Ordinal sz
Specified number of derivative components;.
Ordinal fromCountToIndirectBytes(const Ordinal count, const VecType buffer[]) const
Return the number of bytes for count objects.
Teuchos::RCP< const value_serializer_type > getValueSerializer() const
Get nested value serializer.
void serialize(const Ordinal count, const VecType buffer[], const Ordinal bytes, char charBuffer[]) const
Serialize to an indirect char[] buffer.
Teuchos::RCP< const ValueSerializer > vs
Serializer for value types.
Ordinal getSerializerSize() const
Return specified serializer size.
SerializerImp(const Teuchos::RCP< const ValueSerializer > &vs_, Ordinal sz_=0)
Constructor.
ValueSerializer value_serializer_type
Typename of value serializer.
SerializationImp< Ordinal, VecType, ValueSerializer > Imp
Implementation.
static const bool supportsDirectSerialization
Whether we support direct serialization.
void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, VecType buffer[]) const
Deserialize from an indirect char[] buffer.
static ScalarType pow(const ScalarType &x, const ScalarType &y)
static ScalarType real(const ScalarType &x)
static value_mag_type rmin()
TVT::halfPrecision value_half_type
static value_mag_type sfmin()
TVT::magnitudeType value_mag_type
Sacado::MP::Vector< storage_mag_type > magnitudeType
Teuchos::ScalarTraits< value_type >::coordinateType coordinateType
static value_mag_type eps()
Sacado::MP::Vector< S > ScalarType
static value_mag_type emax()
static magnitudeType magnitude(const ScalarType &a)
static value_mag_type rnd()
Sacado::mpl::apply< S, ordinal_type, value_mag_type >::type storage_mag_type
static bool isnaninf(const ScalarType &x)
static ScalarType conjugate(const ScalarType &x)
static ScalarType imag(const ScalarType &x)
Sacado::MP::Vector< storage_double_type > doublePrecision
static void seedrandom(unsigned int s)
TVT::doublePrecision value_double_type
static ScalarType random()
static value_mag_type t()
static ScalarType log(const ScalarType &x)
Sacado::MP::Vector< storage_half_type > halfPrecision
static value_mag_type rmax()
Sacado::mpl::apply< S, ordinal_type, value_double_type >::type storage_double_type
Teuchos::ScalarTraits< value_type > TVT
static value_mag_type emin()
static ScalarType log10(const ScalarType &x)
Sacado::mpl::apply< S, ordinal_type, value_half_type >::type storage_half_type
static value_mag_type prec()
static const char * name()
static ScalarType squareroot(const ScalarType &x)
static value_mag_type base()
S::ordinal_type ordinal_type
static value_mag_type prec()
static ScalarType log(const ScalarType &x)
static value_mag_type t()
Sacado::mpl::apply< S, ordinal_type, value_half_type >::type storage_half_type
static value_mag_type eps()
Teuchos::ScalarTraits< value_type > TVT
TVT::doublePrecision value_double_type
static ScalarType squareroot(const ScalarType &x)
Sacado::MP::Vector< S > ScalarType
static ScalarType pow(const ScalarType &x, const ScalarType &y)
Sacado::MP::Vector< storage_half_type > halfPrecision
static value_mag_type rmin()
static value_mag_type base()
Sacado::mpl::apply< S, ordinal_type, value_double_type >::type storage_double_type
S::ordinal_type ordinal_type
Sacado::mpl::apply< S, ordinal_type, value_mag_type >::type storage_mag_type
static value_mag_type rnd()
value_mag_type magnitudeType
static ScalarType random()
static value_mag_type sfmin()
static value_mag_type emin()
static magnitudeType real(const ScalarType &x)
static value_mag_type rmax()
TVT::halfPrecision value_half_type
static magnitudeType magnitude(const ScalarType &a)
static value_mag_type emax()
static ScalarType log10(const ScalarType &x)
static const char * name()
Sacado::MP::Vector< storage_double_type > doublePrecision
static void seedrandom(unsigned int s)
static ScalarType conjugate(const ScalarType &x)
static bool isnaninf(const ScalarType &x)
TVT::magnitudeType value_mag_type
Teuchos::ScalarTraits< value_type >::coordinateType coordinateType
static magnitudeType imag(const ScalarType &x)
Serialization implementation for all Vector types.
static void deserialize(const Serializer &vs, const Ordinal bytes, const char charBuffer[], const Ordinal count, VecType buffer[], const Ordinal sz=0)
Deserialize from an indirect char[] buffer.
static Ordinal fromCountToIndirectBytes(const Serializer &vs, const Ordinal count, const VecType buffer[], const Ordinal sz=0)
Return the number of bytes for count objects.
Sacado::ValueType< VecType >::type ValueT
Value type.
static const bool supportsDirectSerialization
Whether the type T supports direct serialization.
static void serialize(const Serializer &vs, const Ordinal count, const VecType buffer[], const Ordinal bytes, char charBuffer[], const Ordinal sz=0)
Serialize to an indirect char[] buffer.
static Ordinal fromIndirectBytesToCount(const Serializer &vs, const Ordinal bytes, const char charBuffer[], const Ordinal sz=0)
Return the number of objects for bytes of storage.
Teuchos::SerializationTraits< Ordinal, Ordinal > oSerT
How to serialize ordinals.
Teuchos::SerializationTraits< Ordinal, int > iSerT
How to serialize ints.
static void serialize(const Ordinal count, const VecType buffer[], const Ordinal bytes, char charBuffer[])
Serialize to an indirect char[] buffer.
Sacado::ValueType< VecType >::type ValueT
Teuchos::DirectSerializationTraits< Ordinal, VecType > DSerT
static Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[])
Return the number of objects for bytes of storage.
static const VecType * convertFromCharPtr(const char *ptr)
Convert the pointer type from char*.
static void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, VecType buffer[])
Deserialize from an indirect char[] buffer.
Sacado::MP::SerializationTraitsImp< Ordinal, VecType > STI
static Ordinal fromCountToIndirectBytes(const Ordinal count, const VecType buffer[])
Return the number of bytes for count objects.
static char * convertToCharPtr(VecType *ptr)
Convert the pointer type to char*.
static const char * convertToCharPtr(const VecType *ptr)
Convert the pointer type to const char*.
static Ordinal fromDirectBytesToCount(const Ordinal bytes)
Return the number of objects for bytes of storage.
Teuchos::SerializationTraits< Ordinal, ValueT > vSerT
static VecType * convertFromCharPtr(char *ptr)
Convert the pointer type from char*.
static Ordinal fromCountToDirectBytes(const Ordinal count)
Return the number of bytes for count objects.
Implementation of Teuchos::SerializationTraits for all Vector types.
Teuchos::DefaultSerializer< Ordinal, ValueT > DS
Default serializer for values.
static const bool supportsDirectSerialization
Whether the type T supports direct serialization.
static Ordinal fromCountToIndirectBytes(const Ordinal count, const VecType buffer[])
Return the number of bytes for count objects.
SerializationImp< Ordinal, VecType, ValueSerializer > Imp
Implementation.
static Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[])
Return the number of objects for bytes of storage.
static void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, VecType buffer[])
Deserialize from an indirect char[] buffer.
Sacado::ValueType< VecType >::type ValueT
Value type of Vec type.
DS::DefaultSerializerType ValueSerializer
Default serializer type for values.
static void serialize(const Ordinal count, const VecType buffer[], const Ordinal bytes, char charBuffer[])
Serialize to an indirect char[] buffer.