25 template <
typename FadType>
27 const std::string& tag,
35 Ordinal bytes = SerT::fromCountToIndirectBytes(count, &x[0]);
36 char *charBuffer =
new char[bytes];
37 SerT::serialize(count, &x[0], bytes, charBuffer);
40 Ordinal count2 = SerT::fromIndirectBytesToCount(bytes, charBuffer);
42 SerT::deserialize(bytes, charBuffer, count2, &x2[0]);
47 bool success = (count == count2);
48 out << tag <<
" serialize/deserialize count test";
53 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
59 out << tag <<
" serialize/deserialize fad test " <<
i;
64 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
66 success = success && success2;
72 template <
typename FadType,
typename Serializer>
75 const std::string& tag,
82 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
83 char *charBuffer =
new char[bytes];
84 serializer.serialize(count, &x[0], bytes, charBuffer);
87 Ordinal sz = serializer.getSerializerSize();
92 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
94 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
99 bool success = (count == count2);
100 out << tag <<
" serialize/deserialize count test";
105 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
111 out << tag <<
" serialize/deserialize fad test " <<
i;
116 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
118 success = success && success2;
124 template <
typename FadType,
typename Serializer>
127 const std::string& tag,
134 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
135 char *charBuffer =
new char[bytes];
136 serializer.serialize(count, &x[0], bytes, charBuffer);
139 Ordinal sz = serializer.getSerializerSize();
140 typedef typename Serializer::value_serializer_type VST;
142 Ordinal sz_inner = vs->getSerializerSize();
145 for (Ordinal j=0; j<sz; j++)
147 x[
i].val().expand(sz_inner);
151 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
153 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
155 delete [] charBuffer;
158 bool success = (count == count2);
159 out << tag <<
" serialize/deserialize count test";
164 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
170 out << tag <<
" serialize/deserialize fad test " <<
i;
175 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
177 success = success && success2;
183 #define FAD_SERIALIZATION_TESTS(FadType, FAD) \
184 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadUniform ) { \
187 ValueTypeSerializer<int,FadType> fts( \
188 rcp(new ValueTypeSerializer<int,double>), p); \
189 Teuchos::Array<FadType> x(n); \
190 for (int i=0; i<n; i++) { \
191 x[i] = FadType(p, rnd.number()); \
192 for (int j=0; j<p; j++) \
193 x[i].fastAccessDx(j) = rnd.number(); \
195 bool success1 = testSerialization( \
196 x, std::string(#FAD) + " Uniform", out); \
197 bool success2 = testSerializationObject( \
198 fts, x, std::string(#FAD) + " Uniform FTS", out); \
199 success = success1 && success2; \
202 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadEmpty ) { \
204 ValueTypeSerializer<int,FadType> fts( \
205 rcp(new ValueTypeSerializer<int,double>), 5); \
206 Teuchos::Array<FadType> x(n); \
207 for (int i=0; i<n; i++) { \
208 x[i] = FadType(rnd.number()); \
210 bool success1 = testSerialization(x, std::string( \
211 #FAD) + " Empty", out); \
212 bool success2 = testSerializationObject( \
213 fts, x, std::string(#FAD) + " Empty FTS", out); \
214 success = success1 && success2; \
217 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadMixed ) { \
219 int p[] = { 5, 0, 8, 8, 3, 0 }; \
220 ValueTypeSerializer<int,FadType> fts( \
221 rcp(new ValueTypeSerializer<int,double>), 8); \
222 Teuchos::Array<FadType> x(n); \
223 for (int i=0; i<n; i++) { \
224 x[i] = FadType(p[i], rnd.number()); \
225 for (int j=0; j<p[i]; j++) \
226 x[i].fastAccessDx(j) = rnd.number(); \
228 bool success1 = testSerialization( \
229 x, std::string(#FAD) + " Mixed", out); \
230 bool success2 = testSerializationObject( \
231 fts, x, std::string(#FAD) + " Mixed FTS", out); \
232 success = success1 && success2; \
235 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadFadUniform ) { \
236 typedef Sacado::mpl::apply<FadType,FadType>::type FadFadType; \
240 RCP< ValueTypeSerializer<int,FadType> > fts = \
241 rcp(new ValueTypeSerializer<int,FadType>( \
242 rcp(new ValueTypeSerializer<int,double>), p1)); \
243 ValueTypeSerializer<int,FadFadType> ffts(fts, p2); \
244 Teuchos::Array<FadFadType> x(n); \
245 for (int i=0; i<n; i++) { \
246 FadType f(p1, rnd.number()); \
247 for (int k=0; k<p1; k++) \
248 f.fastAccessDx(k) = rnd.number(); \
249 x[i] = FadFadType(p2, f); \
250 for (int j=0; j<p2; j++) { \
251 FadType g(p1, rnd.number()); \
252 for (int k=0; k<p1; k++) \
253 g.fastAccessDx(k) = rnd.number(); \
254 x[i].fastAccessDx(j) = g; \
257 bool success1 = testSerialization( \
258 x, std::string(#FAD) + " Nested Uniform", out); \
260 testNestedSerializationObject( \
261 ffts, x, std::string(#FAD) + " Nested Uniform", out); \
262 success = success1 && success2; \
265 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadFadEmptyInner ) { \
266 typedef Sacado::mpl::apply<FadType,FadType>::type FadFadType; \
270 RCP< ValueTypeSerializer<int,FadType> > fts = \
271 rcp(new ValueTypeSerializer<int,FadType>( \
272 rcp(new ValueTypeSerializer<int,double>), p1)); \
273 ValueTypeSerializer<int,FadFadType> ffts(fts, p2); \
274 Teuchos::Array<FadFadType> x(n); \
275 for (int i=0; i<n; i++) { \
276 FadType f(p1, rnd.number()); \
277 for (int k=0; k<p1; k++) \
278 f.fastAccessDx(k) = rnd.number(); \
279 x[i] = FadFadType(p2, f); \
280 for (int j=0; j<p2; j++) \
281 x[i].fastAccessDx(j) = rnd.number(); \
283 bool success1 = testSerialization( \
284 x, std::string(#FAD) + " Nested Empty Inner", out); \
285 bool success2 = testNestedSerializationObject( \
286 ffts, x, std::string(#FAD) + " Nested Empty Inner FTS", out); \
287 success = success1 && success2; \
290 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadFadEmptyOuter ) { \
291 typedef Sacado::mpl::apply<FadType,FadType>::type FadFadType; \
294 RCP< ValueTypeSerializer<int,FadType> > fts = \
295 rcp(new ValueTypeSerializer<int,FadType>( \
296 rcp(new ValueTypeSerializer<int,double>), p1)); \
297 ValueTypeSerializer<int,FadFadType> ffts(fts, 5); \
298 Teuchos::Array<FadFadType> x(n); \
299 for (int i=0; i<n; i++) { \
300 FadType f(p1, rnd.number()); \
301 for (int k=0; k<p1; k++) \
302 f.fastAccessDx(k) = rnd.number(); \
303 x[i] = FadFadType(f); \
305 bool success1 =testSerialization( \
306 x, std::string(#FAD) + " Nested Empty Outer", out); \
307 bool success2 =testNestedSerializationObject( \
308 ffts, x, std::string(#FAD) + " Nested Empty Outer FTS", out); \
309 success = success1 && success2; \
312 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadFadEmptyAll ) { \
313 typedef Sacado::mpl::apply<FadType,FadType>::type FadFadType; \
315 RCP< ValueTypeSerializer<int,FadType> > fts = \
316 rcp(new ValueTypeSerializer<int,FadType>( \
317 rcp(new ValueTypeSerializer<int,double>), 5)); \
318 ValueTypeSerializer<int,FadFadType> ffts(fts, 5); \
319 Teuchos::Array<FadFadType> x(n); \
320 for (int i=0; i<n; i++) { \
321 x[i] = rnd.number(); \
323 bool success1 = testSerialization( \
324 x, std::string(#FAD) + " Nested Empty All", out); \
325 bool success2 = testNestedSerializationObject( \
326 ffts, x, std::string(#FAD) + " Nested Empty All FTS", out); \
327 success = success1 && success2; \
330 #define SFAD_SERIALIZATION_TESTS(FadType, FAD) \
331 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadUniform ) { \
334 ValueTypeSerializer<int,FadType> fts( \
335 rcp(new ValueTypeSerializer<int,double>), p); \
336 Teuchos::Array<FadType> x(n); \
337 for (int i=0; i<n; i++) { \
338 x[i] = FadType(p, rnd.number()); \
339 for (int j=0; j<p; j++) \
340 x[i].fastAccessDx(j) = rnd.number(); \
342 bool success1 = testSerialization( \
343 x, std::string(#FAD) + " Uniform", out); \
344 bool success2 = testSerializationObject( \
345 fts, x, std::string(#FAD) + " Uniform FTS", out); \
346 success = success1 && success2; \
349 TEUCHOS_UNIT_TEST( FAD##_Serialization, FadFadUniform ) { \
350 typedef Sacado::mpl::apply<FadType,FadType>::type FadFadType; \
354 RCP< ValueTypeSerializer<int,FadType> > fts = \
355 rcp(new ValueTypeSerializer<int,FadType>( \
356 rcp(new ValueTypeSerializer<int,double>), p1)); \
357 ValueTypeSerializer<int,FadFadType> ffts(fts, p2); \
358 Teuchos::Array<FadFadType> x(n); \
359 for (int i=0; i<n; i++) { \
360 FadType f(p1, rnd.number()); \
361 for (int k=0; k<p1; k++) \
362 f.fastAccessDx(k) = rnd.number(); \
363 x[i] = FadFadType(p2, f); \
364 for (int j=0; j<p2; j++) { \
365 FadType g(p1, rnd.number()); \
366 for (int k=0; k<p1; k++) \
367 g.fastAccessDx(k) = rnd.number(); \
368 x[i].fastAccessDx(j) = g; \
371 bool success1 = testSerialization( \
372 x, std::string(#FAD) + " Nested Uniform", out); \
373 bool success2 = testNestedSerializationObject( \
374 ffts, x, std::string(#FAD) + " Nested Uniform FTS", out); \
375 success = success1 && success2; \
408 int main(
int argc,
char* argv[] ) {
#define FAD_SERIALIZATION_TESTS(FadType, FAD)
bool testNestedSerializationObject(const Serializer &serializer, Teuchos::Array< FadType > &x, const std::string &tag, Teuchos::FancyOStream &out)
bool testSerialization(const Teuchos::Array< FadType > &x, const std::string &tag, Teuchos::FancyOStream &out)
GeneralFad< StaticStorage< T, Num > > SLFad
#define SFAD_SERIALIZATION_TESTS(FadType, FAD)
bool testSerializationObject(const Serializer &serializer, Teuchos::Array< FadType > &x, const std::string &tag, Teuchos::FancyOStream &out)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
GeneralFad< DynamicStorage< T > > DFad
static SACADO_INLINE_FUNCTION bool eval(const T &x, const T &y)
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
Sacado::Random< double > rnd
GeneralFad< StaticFixedStorage< T, Num > > SFad