25 template <
typename TayType>
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 taylor test " <<
i;
64 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
66 success = success && success2;
72 template <
typename TayType,
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();
89 x[
i].resize(sz-1,
true);
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 taylor test " <<
i;
116 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
118 success = success && success2;
124 template <
typename TayType,
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++)
146 x[
i].fastAccessCoeff(j).
resize(sz_inner-1,
true);
147 x[
i].val().
resize(sz_inner-1,
true);
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 taylor test " <<
i;
175 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i]
177 success = success && success2;
183 #define TAY_SERIALIZATION_TESTS(TayType, TAY) \
184 TEUCHOS_UNIT_TEST( TAY##_Serialization, Uniform ) { \
187 ValueTypeSerializer<int,TayType> tts( \
188 rcp(new ValueTypeSerializer<int,double>), p+1); \
189 Teuchos::Array<TayType> x(n); \
190 for (int i=0; i<n; i++) { \
191 x[i] = TayType(p, rnd.number()); \
192 for (int j=0; j<=p; j++) \
193 x[i].fastAccessCoeff(j) = rnd.number(); \
195 bool success1 = testSerialization( \
196 x, std::string(#TAY) + " Uniform", out); \
197 bool success2 = testSerializationObject( \
198 tts, x, std::string(#TAY) + " Uniform TTS", out); \
199 success = success1 && success2; \
202 TEUCHOS_UNIT_TEST( TAY##_Serialization, Empty ) { \
204 ValueTypeSerializer<int,TayType> tts( \
205 rcp(new ValueTypeSerializer<int,double>), 7); \
206 Teuchos::Array<TayType> x(n); \
207 for (int i=0; i<n; i++) { \
208 x[i] = TayType(rnd.number()); \
210 bool success1 = testSerialization( \
211 x, std::string(#TAY) + " Empty", out); \
212 bool success2 = testSerializationObject( \
213 tts, x, std::string(#TAY) + " Empty TTS", out); \
214 success = success1 && success2; \
217 TEUCHOS_UNIT_TEST( TAY##_Serialization, Mixed ) { \
219 int p[] = { 5, 0, 8, 8, 3, 0 }; \
220 ValueTypeSerializer<int,TayType> tts( \
221 rcp(new ValueTypeSerializer<int,double>), 9); \
222 Teuchos::Array<TayType> x(n); \
223 for (int i=0; i<n; i++) { \
224 x[i] = TayType(p[i], rnd.number()); \
225 for (int j=0; j<=p[i]; j++) \
226 x[i].fastAccessCoeff(j) = rnd.number(); \
228 bool success1 = testSerialization( \
229 x, std::string(#TAY) + " Mixed", out); \
230 bool success2 = testSerializationObject( \
231 tts, x, std::string(#TAY) + " Mixed TTS", out); \
232 success = success1 && success2; \
235 TEUCHOS_UNIT_TEST( TAY##_Serialization, NestedUniform ) { \
236 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
240 RCP< ValueTypeSerializer<int,TayType> > tts = \
241 rcp(new ValueTypeSerializer<int,TayType>( \
242 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
243 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
244 Teuchos::Array<TayTayType> x(n); \
245 for (int i=0; i<n; i++) { \
246 TayType f(p1, rnd.number()); \
247 for (int k=0; k<=p1; k++) \
248 f.fastAccessCoeff(k) = rnd.number(); \
249 x[i] = TayTayType(p2, f); \
250 for (int j=0; j<=p2; j++) { \
251 TayType g(p1, rnd.number()); \
252 for (int k=0; k<=p1; k++) \
253 g.fastAccessCoeff(k) = rnd.number(); \
254 x[i].fastAccessCoeff(j) = g; \
257 bool success1 = testSerialization( \
258 x, std::string(#TAY) + " Nested Uniform", out); \
259 bool success2 = testNestedSerializationObject( \
260 ttts, x, std::string(#TAY) + " Nested Uniform TTS", out); \
261 success = success1 && success2; \
264 TEUCHOS_UNIT_TEST( TAY##_Serialization, NestedEmptyInner ) { \
265 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
269 RCP< ValueTypeSerializer<int,TayType> > tts = \
270 rcp(new ValueTypeSerializer<int,TayType>( \
271 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
272 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
273 Teuchos::Array<TayTayType> x(n); \
274 for (int i=0; i<n; i++) { \
275 TayType f(p1, rnd.number()); \
276 for (int k=0; k<=p1; k++) \
277 f.fastAccessCoeff(k) = rnd.number(); \
278 x[i] = TayTayType(p2, f); \
279 for (int j=0; j<=p2; j++) \
280 x[i].fastAccessCoeff(j) = rnd.number(); \
282 bool success1 = testSerialization( \
283 x, std::string(#TAY) + " Nested Empty Inner", out); \
284 bool success2 = testNestedSerializationObject( \
285 ttts, x, std::string(#TAY) + " Nested Empty Inner TTS", out); \
286 success = success1 && success2; \
289 TEUCHOS_UNIT_TEST( TAY##_Serialization, NestedEmptyOuter ) { \
290 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
293 RCP< ValueTypeSerializer<int,TayType> > tts = \
294 rcp(new ValueTypeSerializer<int,TayType>( \
295 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
296 ValueTypeSerializer<int,TayTayType> ttts(tts, 5); \
297 Teuchos::Array<TayTayType> x(n); \
298 for (int i=0; i<n; i++) { \
299 TayType f(p1, rnd.number()); \
300 for (int k=0; k<=p1; k++) \
301 f.fastAccessCoeff(k) = rnd.number(); \
302 x[i] = TayTayType(f); \
304 bool success1 = testSerialization( \
305 x, std::string(#TAY) + " Nested Empty Outer", out); \
306 bool success2 = testNestedSerializationObject( \
307 ttts, x, std::string(#TAY) + " Nested Empty Outer TTS", out); \
308 success = success1 && success2; \
311 TEUCHOS_UNIT_TEST( TAY##_Serialization, NestedEmptyAll ) { \
312 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
314 RCP< ValueTypeSerializer<int,TayType> > tts = \
315 rcp(new ValueTypeSerializer<int,TayType>( \
316 rcp(new ValueTypeSerializer<int,double>), 5)); \
317 ValueTypeSerializer<int,TayTayType> ttts(tts, 5); \
318 Teuchos::Array<TayTayType> x(n); \
319 for (int i=0; i<n; i++) { \
320 x[i] = rnd.number(); \
322 bool success1 = testSerialization( \
323 x, std::string(#TAY) + " Nested Empty All", out); \
324 bool success2 = testNestedSerializationObject( \
325 ttts, x, std::string(#TAY) + " Nested Empty All TTS", out); \
326 success = success1 && success2; \
333 int main(
int argc,
char* argv[] ) {
bool testNestedSerializationObject(const Serializer &serializer, Teuchos::Array< FadType > &x, const std::string &tag, Teuchos::FancyOStream &out)
#define TAY_SERIALIZATION_TESTS(TayType, TAY)
bool testSerialization(const Teuchos::Array< FadType > &x, const std::string &tag, Teuchos::FancyOStream &out)
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)
void resize(size_type new_size, const value_type &x=value_type())
static SACADO_INLINE_FUNCTION bool eval(const T &x, const T &y)
Sacado::Random< double > rnd