49 #include "Sacado_Fad_DFad.hpp"
50 #include "Sacado_mpl_apply.hpp"
51 #include "Sacado_Random.hpp"
57 template <
typename PCEType,
typename FadType>
68 typedef typename Sacado::mpl::apply<FadType,PCEType>::type
FadPCEType;
79 for (
int i=0; i<d; i++)
89 Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
102 template <
typename PCEType>
104 const std::string& tag,
112 Ordinal bytes = SerT::fromCountToIndirectBytes(count, &
x[0]);
113 char *charBuffer =
new char[bytes];
114 SerT::serialize(count, &
x[0], bytes, charBuffer);
115 Ordinal count2 = SerT::fromIndirectBytesToCount(bytes, charBuffer);
118 bool success = (count == count2);
119 out << tag <<
" serialize/deserialize count test";
124 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
129 for (
Ordinal i=0; i<count2; i++)
130 x2[i].reset(
x[i].
cijk());
131 SerT::deserialize(bytes, charBuffer, count2, &x2[0]);
133 delete [] charBuffer;
136 for (
Ordinal i=0; i<count; i++) {
137 bool success2 = Sacado::IsEqual<PCEType>::eval(
x[i], x2[i]);
138 out << tag <<
" serialize/deserialize pce test " << i;
143 out <<
": \n\tExpected: " <<
x[i] <<
", \n\tGot: " << x2[i]
145 success = success && success2;
151 template <
typename PCEType,
typename Serializer>
153 const Serializer& serializer,
154 const std::string& tag,
161 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &
x[0]);
162 char *charBuffer =
new char[bytes];
163 serializer.serialize(count, &
x[0], bytes, charBuffer);
166 for (
Ordinal i=0; i<count; i++)
167 x[i].reset(serializer.getSerializerCijk());
170 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
172 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
174 delete [] charBuffer;
177 bool success = (count == count2);
178 out << tag <<
" serialize/deserialize count test";
183 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
187 for (
Ordinal i=0; i<count; i++) {
188 bool success2 = Sacado::IsEqual<PCEType>::eval(
x[i], x2[i]);
189 out << tag <<
" serialize/deserialize pce test " << i;
194 out <<
": \n\tExpected: " <<
x[i] <<
", \n\tGot: " << x2[i]
196 success = success && success2;
202 template <
typename PCEType,
typename Serializer>
204 const Serializer& serializer,
205 const std::string& tag,
212 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &
x[0]);
213 char *charBuffer =
new char[bytes];
214 serializer.serialize(count, &
x[0], bytes, charBuffer);
217 Ordinal sz = serializer.getSerializerSize();
218 typedef typename Serializer::value_serializer_type VST;
220 for (
Ordinal i=0; i<count; i++) {
224 x[i].val().reset(vs->getSerializerCijk());
228 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
230 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
232 delete [] charBuffer;
235 bool success = (count == count2);
236 out << tag <<
" serialize/deserialize count test";
241 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
245 for (
Ordinal i=0; i<count; i++) {
246 bool success2 = Sacado::IsEqual<PCEType>::eval(
x[i], x2[i]);
247 out << tag <<
" serialize/deserialize pce test " << i;
252 out <<
": \n\tExpected: " <<
x[i] <<
", \n\tGot: " << x2[i]
254 success = success && success2;
265 Sacado::Random<double>
rnd;
270 for (
int i=0; i<
n; i++) {
271 x[i].reset(
setup.kokkos_cijk);
276 x, std::string(
"UQ::PCE") +
" Uniform", out);
278 x, *
setup.pce_serializer, std::string(
"UQ::PCE") +
" Uniform PTS", out);
279 success = success1 && success2;
286 for (
int i=0; i<
n; i++) {
290 x, std::string(
"UQ::PCE") +
" Empty", out);
292 x, *
setup.pce_serializer, std::string(
"UQ::PCE") +
" Empty PTS", out);
293 success = success1 && success2;
299 int p[] = { 5, 0, 8, 8, 3, 0 };
301 for (
int i=0; i<
n; i++) {
302 x[i].reset(
setup.kokkos_cijk, p[i]);
303 for (
int j=0;
j<p[i];
j++)
307 x, std::string(
"UQ::PCE") +
" Mixed", out);
309 x, *
setup.pce_serializer, std::string(
"UQ::PCE") +
" Mixed PTS", out);
310 success = success1 && success2;
315 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
319 for (
int i=0; i<
n; i++) {
321 for (
int k=0; k<
setup.sz; k++)
322 f.fastAccessCoeff(k) =
rnd.number();
323 x[i] = FadPCEType(p,
f);
324 for (
int j=0;
j<p;
j++) {
326 for (
int k=0; k<
setup.sz; k++)
327 g.fastAccessCoeff(k) =
rnd.number();
328 x[i].fastAccessDx(
j) =
g;
333 std::string(
"UQ::PCE") +
" Nested Uniform", out);
337 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
341 for (
int i=0; i<
n; i++) {
343 for (
int k=0; k<
setup.sz; k++)
344 f.fastAccessCoeff(k) =
rnd.number();
345 x[i] = FadPCEType(p,
f);
346 for (
int j=0;
j<p;
j++)
351 x, *
setup.fad_pce_serializer,
352 std::string(
"UQ::PCE") +
" Nested Empty Inner", out);
356 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
359 for (
int i=0; i<
n; i++) {
361 for (
int k=0; k<
setup.sz; k++)
362 f.fastAccessCoeff(k) =
rnd.number();
363 x[i] = FadPCEType(
f);
367 x, *
setup.fad_pce_serializer,
368 std::string(
"UQ::PCE") +
" Nested Empty Outer", out);
372 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
375 for (
int i=0; i<
n; i++) {
380 x, *
setup.fad_pce_serializer,
381 std::string(
"UQ::PCE") +
" Nested Empty All", out);
387 Kokkos::initialize();