32 #ifndef SACADO_TAY_SCALARTRAITSIMP_HPP 33 #define SACADO_TAY_SCALARTRAITSIMP_HPP 35 #ifdef HAVE_SACADO_TEUCHOS 50 template <
typename TayType>
51 struct ScalarTraitsImp {
54 typedef typename mpl::apply<TayType,typename Teuchos::ScalarTraits<ValueT>::magnitudeType>::type magnitudeType;
55 typedef typename mpl::apply<TayType,typename Teuchos::ScalarTraits<ValueT>::halfPrecision>::type halfPrecision;
56 typedef typename mpl::apply<TayType,typename Teuchos::ScalarTraits<ValueT>::doublePrecision>::type doublePrecision;
60 static const bool isComparable =
62 static const bool hasMachineParameters =
94 static magnitudeType magnitude(
const TayType&
a) {
96 TEUCHOS_SCALAR_TRAITS_NAN_INF_ERR(
97 a,
"Error, the input value to magnitude(...) a = " <<
a <<
100 "Complex magnitude is not a differentiable " 101 "function of complex inputs.");
104 magnitudeType b(
a.degree(),
107 for (
int i=1; i<=
a.degree(); i++)
108 b.fastAccessCoeff(i) =
111 for (
int i=1; i<=
a.degree(); i++)
112 b.fastAccessCoeff(i) =
116 static ValueT zero() {
119 static ValueT one() {
124 static TayType conjugate(
const TayType& x) {
127 "Complex conjugate is not a differentiable " 128 "function of complex inputs.");
137 static TayType real(
const TayType& x) {
140 "Real component is not a differentiable " 141 "function of complex inputs.");
150 static TayType imag(
const TayType& x) {
153 "Imaginary component is not a differentiable " 154 "function of complex inputs.");
159 static ValueT nan() {
162 static bool isnaninf(
const TayType& x) {
163 for (
int i=0; i<=x.degree(); i++)
168 static void seedrandom(
unsigned int s) {
171 static ValueT random() {
174 static std::string name() {
177 static TayType squareroot(
const TayType& x) {
179 TEUCHOS_SCALAR_TRAITS_NAN_INF_ERR(
180 x,
"Error, the input value to squareroot(...) a = " << x <<
181 " can not be NaN!" );
185 static TayType
pow(
const TayType& x,
const TayType& y) {
190 static bool is_complex_real(
const ValueT& x) {
196 static bool is_tay_real(
const TayType& x) {
200 for (
int i=0; i<=x.degree(); i++)
201 if (!is_complex_real(x.fastAccessCoeff(i)))
210 template <
typename Ordinal,
typename TayType,
typename Serializer>
211 struct SerializationImp {
224 static const bool supportsDirectSerialization =
false;
230 static Ordinal fromCountToIndirectBytes(
const Serializer& vs,
232 const TayType buffer[],
237 for (
Ordinal i=0; i<count; i++) {
238 unsigned int my_sz = buffer[i].degree()+1;
239 unsigned int tot_sz = sz;
240 if (sz == 0) tot_sz = my_sz;
241 if (tot_sz != my_sz) {
242 x =
new TayType(buffer[i]);
243 x->resize(tot_sz-1,
true);
248 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
249 Ordinal b2 = vs.fromCountToIndirectBytes(
250 tot_sz, &(cx->fastAccessCoeff(0)));
251 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
262 static void serialize (
const Serializer& vs,
264 const TayType buffer[],
270 for (
Ordinal i=0; i<count; i++) {
272 unsigned int my_sz = buffer[i].degree()+1;
273 unsigned int tot_sz = sz;
274 if (sz == 0) tot_sz = my_sz;
275 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
276 iSerT::serialize(1, &tot_sz, b1, charBuffer);
280 if (tot_sz != my_sz) {
281 x =
new TayType(buffer[i]);
282 x->resize(tot_sz-1,
true);
287 Ordinal b2 = vs.fromCountToIndirectBytes(
288 tot_sz, &(cx->fastAccessCoeff(0)));
289 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
290 oSerT::serialize(1, &b2, b3, charBuffer);
292 vs.serialize(tot_sz, &(cx->fastAccessCoeff(0)), b2, charBuffer);
302 static Ordinal fromIndirectBytesToCount(
const Serializer& vs,
304 const char charBuffer[],
308 while (bytes_used < bytes) {
311 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
316 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
317 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
329 static void deserialize (
const Serializer& vs,
331 const char charBuffer[],
335 for (
Ordinal i=0; i<count; i++) {
338 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
339 const unsigned int *my_sz = iSerT::convertFromCharPtr(charBuffer);
343 unsigned int tot_sz = sz;
344 if (sz == 0) tot_sz = *my_sz;
345 buffer[i] = TayType(tot_sz-1, 0.0);
348 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
349 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
351 vs.deserialize(*b2, charBuffer, *my_sz,
352 &(buffer[i].fastAccessCoeff(0)));
363 template <
typename Ordinal,
typename TayType>
364 struct SerializationTraitsImp {
375 typedef typename DS::DefaultSerializerType ValueSerializer;
378 typedef SerializationImp<Ordinal,TayType,ValueSerializer> Imp;
383 static const bool supportsDirectSerialization =
384 Imp::supportsDirectSerialization;
391 const TayType buffer[]) {
392 return Imp::fromCountToIndirectBytes(
393 DS::getDefaultSerializer(), count, buffer);
397 static void serialize (
const Ordinal count,
398 const TayType buffer[],
402 DS::getDefaultSerializer(), count, buffer, bytes, charBuffer);
407 const char charBuffer[]) {
408 return Imp::fromIndirectBytesToCount(
409 DS::getDefaultSerializer(), bytes, charBuffer);
413 static void deserialize (
const Ordinal bytes,
414 const char charBuffer[],
418 DS::getDefaultSerializer(), bytes, charBuffer, count, buffer);
426 template <
typename Ordinal,
typename TayType,
typename ValueSerializer>
427 class SerializerImp {
432 typedef SerializationImp<Ordinal,TayType,ValueSerializer> Imp;
443 typedef ValueSerializer value_serializer_type;
446 static const bool supportsDirectSerialization =
447 Imp::supportsDirectSerialization;
455 Ordinal getSerializerSize()
const {
return sz; }
466 const TayType buffer[])
const {
467 return Imp::fromCountToIndirectBytes(*vs, count, buffer, sz);
471 void serialize (
const Ordinal count,
472 const TayType buffer[],
474 char charBuffer[])
const {
475 Imp::serialize(*vs, count, buffer, bytes, charBuffer, sz);
480 const char charBuffer[])
const {
481 return Imp::fromIndirectBytesToCount(*vs, bytes, charBuffer, sz);
485 void deserialize (
const Ordinal bytes,
486 const char charBuffer[],
488 TayType buffer[])
const {
489 return Imp::deserialize(*vs, bytes, charBuffer, count, buffer, sz);
500 #endif // HAVE_SACADO_TEUCHOS 502 #endif // SACADO_FAD_SCALARTRAITSIMP_HPP
static std::string eval()
static magnitudeType eps()
PowExprType< Expr< T1 >, Expr< T2 > >::expr_type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static magnitudeType real(T a)
pow(expr1.val(), expr2.val())
static magnitudeType emax()
static magnitudeType base()
static magnitudeType rmax()
static magnitudeType sfmin()
static magnitudeType prec()
static magnitudeType rmin()
static void seedrandom(unsigned int s)
static magnitudeType magnitude(T a)
Sacado::Random< double > rnd
static magnitudeType emin()
static magnitudeType rnd()