Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SacadoMPVectorUnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 
17 
18 #include "Kokkos_Core.hpp"
19 #include "Kokkos_Complex.hpp"
20 
21 //
22 // Currently this doesn't test:
23 // * the device
24 // * threaded storage (needs the device)
25 // * strided storage with non-trivial stride
26 //
27 
28 // Common setup for unit tests
29 template <typename VectorType>
30 struct UnitTestSetup {
31 
32  typedef VectorType vec_type;
33  typedef typename vec_type::value_type value_type;
34 
35  double rtol, atol;
36  double crtol, catol;
37  int sz;
40 
42  rtol = 1e-4;
43  atol = 1e-5;
44  crtol = 1e-12;
45  catol = 1e-12;
46  a = 3.1;
47  sz = 8;
48 
49  // Create vector
50  x.reset(sz);
51  y.reset(sz);
52  cx.reset(1);
53  cx = a;
54  for (int i=0; i<sz; i++) {
55  x.fastAccessCoeff(i) = 0.1*i;
56  y.fastAccessCoeff(i) = 0.25*i;
57  }
58  }
59 };
60 
65 #define UNARY_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME, USING_OP) \
66  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
67  UTS setup; \
68  UTS::vec_type u = OP(setup.x); \
69  UTS::vec_type v(setup.sz, 0.0); \
70  for (int i=0; i<setup.sz; i++) \
71  { \
72  USING_OP \
73  v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
74  } \
75  success = compareVecs(u, "u",v, "v", \
76  setup.rtol, setup.atol, out); \
77  } \
78  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const) { \
79  UTS setup; \
80  UTS::vec_type u = OP(setup.cx); \
81  UTS::vec_type v(1, 0.0); \
82  for (int i=0; i<v.size(); i++) \
83  { \
84  USING_OP \
85  v.fastAccessCoeff(i) = OP(setup.cx.fastAccessCoeff(0)); \
86  } \
87  success = compareVecs(u, "u",v, "v", \
88  setup.rtol, setup.atol, out); \
89  } \
90  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
91  UTS setup; \
92  UTS::vec_type u; \
93  u = OP(setup.x); \
94  UTS::vec_type v(setup.sz, 0.0); \
95  for (int i=0; i<setup.sz; i++) \
96  { \
97  USING_OP \
98  v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
99  } \
100  success = compareVecs(u, "u",v, "v", \
101  setup.rtol, setup.atol, out); \
102  }
103 
104 #define BINARY_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME) \
105  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
106  UTS setup; \
107  UTS::vec_type u = setup.x OP setup.y; \
108  UTS::vec_type v(setup.sz, 0.0); \
109  for (int i=0; i<setup.sz; i++) \
110  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
111  setup.y.fastAccessCoeff(i); \
112  success = compareVecs(u, "u",v, "v", \
113  setup.rtol, setup.atol, out); \
114  } \
115  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const) { \
116  UTS setup; \
117  UTS::vec_type u = setup.a OP setup.y; \
118  UTS::vec_type v(setup.sz, 0.0); \
119  for (int i=0; i<setup.sz; i++) \
120  v.fastAccessCoeff(i) = setup.a OP setup.y.fastAccessCoeff(i); \
121  success = compareVecs(u, "u",v, "v", \
122  setup.rtol, setup.atol, out); \
123  } \
124  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const) { \
125  UTS setup; \
126  UTS::vec_type u = setup.x OP setup.a ; \
127  UTS::vec_type v(setup.sz, 0.0); \
128  for (int i=0; i<setup.sz; i++) \
129  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
130  setup.a; \
131  success = compareVecs(u, "u",v, "v", \
132  setup.rtol, setup.atol, out); \
133  } \
134  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_both_const) { \
135  UTS setup; \
136  UTS::vec_type u = setup.cx OP setup.cx; \
137  UTS::vec_type v(1, 0.0); \
138  for (int i=0; i<v.size(); i++) \
139  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
140  setup.cx.fastAccessCoeff(0); \
141  success = compareVecs(u, "u",v, "v", \
142  setup.rtol, setup.atol, out); \
143  } \
144  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const2) { \
145  UTS setup; \
146  UTS::vec_type u = setup.cx OP setup.x; \
147  UTS::vec_type v(setup.sz, 0.0); \
148  for (int i=0; i<setup.sz; i++) \
149  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
150  setup.x.fastAccessCoeff(i); \
151  success = compareVecs(u, "u",v, "v", \
152  setup.rtol, setup.atol, out); \
153  } \
154  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const2) { \
155  UTS setup; \
156  UTS::vec_type u = setup.x OP setup.cx; \
157  UTS::vec_type v(setup.sz, 0.0); \
158  for (int i=0; i<setup.sz; i++) \
159  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
160  setup.cx.fastAccessCoeff(0); \
161  success = compareVecs(u, "u",v, "v", \
162  setup.rtol, setup.atol, out); \
163  } \
164  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
165  UTS setup; \
166  UTS::vec_type u; \
167  u = setup.x OP setup.y; \
168  UTS::vec_type v(setup.sz, 0.0); \
169  for (int i=0; i<setup.sz; i++) \
170  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
171  setup.y.fastAccessCoeff(i); \
172  success = compareVecs(u, "u",v, "v", \
173  setup.rtol, setup.atol, out); \
174  } \
175  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const_resize) { \
176  UTS setup; \
177  UTS::vec_type u; \
178  u = setup.a OP setup.y; \
179  UTS::vec_type v(setup.sz, 0.0); \
180  for (int i=0; i<setup.sz; i++) \
181  v.fastAccessCoeff(i) = setup.a OP \
182  setup.y.fastAccessCoeff(i); \
183  success = compareVecs(u, "u",v, "v", \
184  setup.rtol, setup.atol, out); \
185  } \
186  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const_resize) { \
187  UTS setup; \
188  UTS::vec_type u; \
189  u = setup.x OP setup.a; \
190  UTS::vec_type v(setup.sz, 0.0); \
191  for (int i=0; i<setup.sz; i++) \
192  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
193  setup.a; \
194  success = compareVecs(u, "u",v, "v", \
195  setup.rtol, setup.atol, out); \
196  }
197 
198 #define BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, OP, SOP, USING_SOP, OPNAME) \
199  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
200  UTS setup; \
201  UTS::vec_type u = OP(setup.x,setup.y); \
202  UTS::vec_type v(setup.sz, 0.0); \
203  for (int i=0; i<setup.sz; i++) \
204  { \
205  USING_SOP \
206  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
207  setup.y.fastAccessCoeff(i)); \
208  } \
209  success = compareVecs(u, "u",v, "v", \
210  setup.rtol, setup.atol, out); \
211  } \
212  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const) { \
213  UTS setup; \
214  UTS::vec_type u = OP(setup.a,setup.y); \
215  UTS::vec_type v(setup.sz, 0.0); \
216  for (int i=0; i<setup.sz; i++) \
217  { \
218  USING_SOP \
219  v.fastAccessCoeff(i) = SOP(setup.a, \
220  setup.y.fastAccessCoeff(i)); \
221  } \
222  success = compareVecs(u, "u",v, "v", \
223  setup.rtol, setup.atol, out); \
224  } \
225  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const) { \
226  UTS setup; \
227  UTS::vec_type u = OP(setup.x,setup.a); \
228  UTS::vec_type v(setup.sz, 0.0); \
229  for (int i=0; i<setup.sz; i++) \
230  { \
231  USING_SOP \
232  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
233  setup.a); \
234  } \
235  success = compareVecs(u, "u",v, "v", \
236  setup.rtol, setup.atol, out); \
237  } \
238  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_both_const) { \
239  UTS setup; \
240  UTS::vec_type u = OP(setup.cx,setup.cx); \
241  UTS::vec_type v(1, 0.0); \
242  for (int i=0; i<v.size(); i++) \
243  { \
244  USING_SOP \
245  v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
246  setup.cx.fastAccessCoeff(0)); \
247  } \
248  success = compareVecs(u, "u",v, "v", \
249  setup.rtol, setup.atol, out); \
250  } \
251  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const2) { \
252  UTS setup; \
253  UTS::vec_type u = OP(setup.cx,setup.x); \
254  UTS::vec_type v(setup.sz, 0.0); \
255  for (int i=0; i<setup.sz; i++) \
256  { \
257  USING_SOP \
258  v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
259  setup.x.fastAccessCoeff(i)); \
260  } \
261  success = compareVecs(u, "u",v, "v", \
262  setup.rtol, setup.atol, out); \
263  } \
264  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const2) { \
265  UTS setup; \
266  UTS::vec_type u = OP(setup.x,setup.cx); \
267  UTS::vec_type v(setup.sz, 0.0); \
268  for (int i=0; i<setup.sz; i++) \
269  { \
270  USING_SOP \
271  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
272  setup.cx.fastAccessCoeff(0)); \
273  } \
274  success = compareVecs(u, "u",v, "v", \
275  setup.rtol, setup.atol, out); \
276  } \
277  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
278  UTS setup; \
279  UTS::vec_type u; \
280  u = OP(setup.x,setup.y); \
281  UTS::vec_type v(setup.sz, 0.0); \
282  for (int i=0; i<setup.sz; i++) \
283  { \
284  USING_SOP \
285  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
286  setup.y.fastAccessCoeff(i)); \
287  } \
288  success = compareVecs(u, "u",v, "v", \
289  setup.rtol, setup.atol, out); \
290  } \
291  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const_resize) { \
292  UTS setup; \
293  UTS::vec_type u; \
294  u = OP(setup.a,setup.y); \
295  UTS::vec_type v(setup.sz, 0.0); \
296  for (int i=0; i<setup.sz; i++) \
297  { \
298  USING_SOP \
299  v.fastAccessCoeff(i) = SOP(setup.a, \
300  setup.y.fastAccessCoeff(i)); \
301  } \
302  success = compareVecs(u, "u",v, "v", \
303  setup.rtol, setup.atol, out); \
304  } \
305  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const_resize) { \
306  UTS setup; \
307  UTS::vec_type u; \
308  u = OP(setup.x,setup.a); \
309  UTS::vec_type v(setup.sz, 0.0); \
310  for (int i=0; i<setup.sz; i++) \
311  { \
312  USING_SOP \
313  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
314  setup.a); \
315  } \
316  success = compareVecs(u, "u",v, "v", \
317  setup.rtol, setup.atol, out); \
318  }
319 
320 #define OPASSIGN_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME) \
321  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
322  UTS setup; \
323  UTS::vec_type u = std::sin(setup.x); \
324  UTS::vec_type v = std::sin(setup.x); \
325  u OP setup.x; \
326  for (int i=0; i<setup.sz; i++) \
327  v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
328  success = compareVecs(u, "u",v, "v", \
329  setup.rtol, setup.atol, out); \
330  } \
331  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const) { \
332  UTS setup; \
333  UTS::vec_type u = std::sin(setup.x); \
334  UTS::vec_type v = std::sin(setup.x); \
335  u OP setup.a; \
336  for (int i=0; i<setup.sz; i++) \
337  v.fastAccessCoeff(i) OP setup.a; \
338  success = compareVecs(u, "u",v, "v", \
339  setup.rtol, setup.atol, out); \
340  } \
341  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const2) { \
342  UTS setup; \
343  UTS::vec_type u = std::sin(setup.x); \
344  UTS::vec_type v = std::sin(setup.x); \
345  u OP setup.cx; \
346  for (int i=0; i<setup.sz; i++) \
347  v.fastAccessCoeff(i) OP setup.cx.fastAccessCoeff(0); \
348  success = compareVecs(u, "u",v, "v", \
349  setup.rtol, setup.atol, out); \
350  } \
351  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
352  UTS setup; \
353  UTS::vec_type u = setup.a; \
354  UTS::vec_type v(setup.sz, 0.0); \
355  u OP setup.x; \
356  for (int i=0; i<setup.sz; i++) { \
357  v.fastAccessCoeff(i) = setup.a; \
358  v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
359  } \
360  success = compareVecs(u, "u",v, "v", \
361  setup.rtol, setup.atol, out); \
362  }
363 
364 #define SAXPY_UNIT_TEST(VEC, SCALAR_T) \
365  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy) { \
366  UTS setup; \
367  UTS::vec_type u = std::sin(setup.x); \
368  UTS::vec_type v = std::sin(setup.x); \
369  u += setup.x*setup.y; \
370  for (int i=0; i<setup.sz; i++) \
371  v.fastAccessCoeff(i) += \
372  setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
373  success = compareVecs(u, "u",v, "v", \
374  setup.rtol, setup.atol, out); \
375  } \
376  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_resize) { \
377  UTS setup; \
378  UTS::vec_type u = setup.cx; \
379  UTS::vec_type v(setup.sz, 0.0); \
380  u += setup.x*setup.y; \
381  for (int i=0; i<setup.sz; i++) \
382  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) + \
383  setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
384  success = compareVecs(u, "u",v, "v", \
385  setup.rtol, setup.atol, out); \
386  } \
387  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_const) { \
388  UTS setup; \
389  UTS::vec_type u = std::sin(setup.x); \
390  UTS::vec_type v = std::sin(setup.x); \
391  u += setup.a*setup.y; \
392  for (int i=0; i<setup.sz; i++) \
393  v.fastAccessCoeff(i) += \
394  setup.a*setup.y.fastAccessCoeff(i); \
395  success = compareVecs(u, "u",v, "v", \
396  setup.rtol, setup.atol, out); \
397  } \
398  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_const2) { \
399  UTS setup; \
400  UTS::vec_type u = std::sin(setup.x); \
401  UTS::vec_type v = std::sin(setup.x); \
402  u += setup.cx*setup.y; \
403  for (int i=0; i<setup.sz; i++) \
404  v.fastAccessCoeff(i) += \
405  setup.cx.fastAccessCoeff(0)*setup.y.fastAccessCoeff(i); \
406  success = compareVecs(u, "u",v, "v", \
407  setup.rtol, setup.atol, out); \
408  }
409 
410 #define TERNARY_UNIT_TEST(VEC, SCALAR_T) \
411  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, ternay) { \
412  UTS setup; \
413  UTS::vec_type u = std::sin(setup.x); \
414  UTS::vec_type v = -std::sin(setup.x); \
415  u = u >= 0 ? -u : u; \
416  success = compareVecs(u, "u", v, "v", \
417  setup.rtol, setup.atol, out); \
418  }
419 
424 #define VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T) \
425  UNARY_UNIT_TEST(VEC, SCALAR_T, + , UnaryPlus ,) \
426  UNARY_UNIT_TEST(VEC, SCALAR_T, - , UnaryMinus,) \
427  UNARY_UNIT_TEST(VEC, SCALAR_T, exp , Exp , using std::exp; ) \
428  UNARY_UNIT_TEST(VEC, SCALAR_T, log , Log , using std::log; ) \
429  UNARY_UNIT_TEST(VEC, SCALAR_T, log10, Log10 , using std::log10;) \
430  UNARY_UNIT_TEST(VEC, SCALAR_T, sqrt , Sqrt , using std::sqrt; ) \
431  UNARY_UNIT_TEST(VEC, SCALAR_T, sin , Sin , using std::sin; ) \
432  UNARY_UNIT_TEST(VEC, SCALAR_T, cos , Cos , using std::cos; ) \
433  UNARY_UNIT_TEST(VEC, SCALAR_T, tan , Tan , using std::tan; ) \
434  UNARY_UNIT_TEST(VEC, SCALAR_T, sinh , Sinh , using std::sinh; ) \
435  UNARY_UNIT_TEST(VEC, SCALAR_T, cosh , Cosh , using std::cosh; ) \
436  UNARY_UNIT_TEST(VEC, SCALAR_T, tanh , Tanh , using std::tanh; ) \
437  UNARY_UNIT_TEST(VEC, SCALAR_T, asin , ASin , using std::asin; ) \
438  UNARY_UNIT_TEST(VEC, SCALAR_T, acos , ACos , using std::acos; ) \
439  UNARY_UNIT_TEST(VEC, SCALAR_T, atan , ATan , using std::atan; ) \
440  UNARY_UNIT_TEST(VEC, SCALAR_T, asinh, ASinh , using std::asinh;) \
441  UNARY_UNIT_TEST(VEC, SCALAR_T, acosh, ACosh , using std::acosh;) \
442  UNARY_UNIT_TEST(VEC, SCALAR_T, atanh, ATanh , using std::atanh;) \
443  \
444  BINARY_UNIT_TEST(VEC, SCALAR_T, +, Plus) \
445  BINARY_UNIT_TEST(VEC, SCALAR_T, -, Minus) \
446  BINARY_UNIT_TEST(VEC, SCALAR_T, *, Times) \
447  BINARY_UNIT_TEST(VEC, SCALAR_T, /, Divide) \
448  \
449  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, pow, pow, using std::pow;, Pow) \
450  \
451  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, +=, PlusEqual) \
452  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, -=, MinusEqual) \
453  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, *=, TimesEqual) \
454  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, /=, DivideEqual) \
455  \
456  SAXPY_UNIT_TEST(VEC, SCALAR_T) \
457  \
458  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_constructor ) { \
459  UTS setup; \
460  UTS::vec_type u{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
461  UTS::vec_type v(setup.sz, 0.0); \
462  for (int i=0; i<setup.sz; i++) \
463  v.fastAccessCoeff(i) = i+1; \
464  success = compareVecs(u, "u", v, "v", \
465  setup.rtol, setup.atol, out); \
466  } \
467  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_copy ) { \
468  UTS setup; \
469  UTS::vec_type u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
470  UTS::vec_type v(setup.sz, 0.0); \
471  for (int i=0; i<setup.sz; i++) \
472  v.fastAccessCoeff(i) = i+1; \
473  success = compareVecs(u, "u", v, "v", \
474  setup.rtol, setup.atol, out); \
475  } \
476  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_assign ) { \
477  UTS setup; \
478  UTS::vec_type u; \
479  u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
480  UTS::vec_type v(setup.sz, 0.0); \
481  for (int i=0; i<setup.sz; i++) \
482  v.fastAccessCoeff(i) = i+1; \
483  success = compareVecs(u, "u", v, "v", \
484  setup.rtol, setup.atol, out); \
485  } \
486  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, range_based_for ) { \
487  UTS setup; \
488  UTS::vec_type u(setup.sz, 0.0); \
489  for (auto& z : u) { z = 3.0; } \
490  UTS::vec_type v(setup.sz, 3.0); \
491  success = compareVecs(u, "u", v, "v", \
492  setup.rtol, setup.atol, out); \
493  }
494 
498  #define VECTOR_UNIT_TESTS_SFS_ANY_VALUE_TYPE(SCALAR_T) \
499  TEUCHOS_UNIT_TEST( StaticFixedVector##_##SCALAR_T, initializer_list_constructor_partial ) {\
500  UTS setup; \
501  UTS::vec_type u{ 1.0}; \
502  UTS::vec_type v(setup.sz, 1.0); \
503  success = compareVecs(u, "u", v, "v", \
504  setup.rtol, setup.atol, out); \
505  } \
506  TEUCHOS_UNIT_TEST( StaticFixedVector##_##SCALAR_T, initializer_list_constructor_empty ) { \
507  UTS setup; \
508  UTS::vec_type u{ std::initializer_list<typename UTS::value_type>()}; \
509  UTS::vec_type v(setup.sz, 0.0); \
510  success = compareVecs(u, "u", v, "v", \
511  setup.rtol, setup.atol, out); \
512  }
513 
517 #define VECTOR_UNIT_TESTS_COMPLEX_TYPE(VEC,SCALAR_T) \
518  /* Run the series of tests for any type. */ \
519  VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T)
520 
526 #define VECTOR_UNIT_TESTS_REAL_TYPE(VEC,SCALAR_T) \
527  /* Run the series of tests for any type. */ \
528  VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T) \
529  /* Operator cbrt not supported for complex type but supported for real type. */ \
530  UNARY_UNIT_TEST(VEC, SCALAR_T, cbrt , Cbrt, using std::cbrt;) \
531  /* Operator atan2 not supported for complex type but supported for real type. */ \
532  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, atan2, atan2, using std::atan2;, ATan2) \
533  /* Operators min and max are not supported for complex type. */ \
534  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, max , max , using std::max ;, Max) \
535  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, min , min , using std::min ;, Min) \
536  /* Operators fmin and fmax are not supported for complex type. */ \
537  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, fmax , fmax , using std::fmax ;, FMax) \
538  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, fmin , fmin , using std::fmin ;, FMin) \
539  /* Ternary test uses 'operator<' that is not defined for complex type. */ \
540  TERNARY_UNIT_TEST(VEC, SCALAR_T)
541 
545 #define TEST_DYNAMIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__macro_for_tests__)\
546  typedef Kokkos::DefaultExecutionSpace execution_space; \
547  typedef Stokhos::__storage_type__<int,__scalar_type__,execution_space> storage_type; \
548  typedef Sacado::MP::Vector<storage_type> vec_type; \
549  typedef UnitTestSetup<vec_type> UTS; \
550  __macro_for_tests__(__vec_type__,__scalar_type__)
551 
552 namespace DynamicVecTest
553 {
554  TEST_DYNAMIC_STORAGE(DynamicStorage, DynamicVector, double, VECTOR_UNIT_TESTS_REAL_TYPE)
555 }
556 
557 namespace DynamicStridedVecTest
558 {
559  TEST_DYNAMIC_STORAGE(DynamicStridedStorage, DynamicStridedVector, double, VECTOR_UNIT_TESTS_REAL_TYPE)
560 }
561 
565 #define TEST_STATIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
566  typedef ::Kokkos::DefaultExecutionSpace execution_space; \
567  typedef ::Stokhos::__storage_type__<int,__scalar_type__,__storage_size__,execution_space> storage_type; \
568  typedef ::Sacado::MP::Vector<storage_type> vec_type; \
569  typedef UnitTestSetup<vec_type> UTS; \
570  __macro_for_tests__(__vec_type__,__scalar_type_name__)
571 
572 namespace StaticVecTest
573 {
574  TEST_STATIC_STORAGE(StaticStorage, StaticVector, double, double, 8, VECTOR_UNIT_TESTS_REAL_TYPE)
575 }
576 
580 #define TEST_STATIC_FIXED_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
581  TEST_STATIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
582  VECTOR_UNIT_TESTS_SFS_ANY_VALUE_TYPE(__scalar_type_name__)
583 
584 
585 namespace StaticFixedVecTest
586 {
587  namespace Double {TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, double , double, 8, VECTOR_UNIT_TESTS_REAL_TYPE )}
588 
589 // Skip std::complex when compiling with CUDA, because std::complex isn't supported in that case.
590 // Note that even though the tests aren't run on the device, nvcc still complains that __device__ code functions are called
591 // from __host__ code (or vice versa).
592 #if !defined(KOKKOS_ENABLE_CUDA) && !defined(KOKKOS_ENABLE_HIP)
593  namespace Complex_std {TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, std ::complex<double>, std_complex_double, 8, VECTOR_UNIT_TESTS_COMPLEX_TYPE)}
594 #endif
595 
596  // Always test for Kokkos::complex because it is always shipped as part of Kokkos, whatever the space.
597  namespace Complex_Kokkos{TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, ::Kokkos::complex<double>, kokkos_complex_double, 8, VECTOR_UNIT_TESTS_COMPLEX_TYPE)}
598 }
#define VECTOR_UNIT_TESTS_REAL_TYPE(VEC, SCALAR_T)
#define TEST_DYNAMIC_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __macro_for_tests__)
#define TEST_STATIC_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __scalar_type_name__, __storage_size__, __macro_for_tests__)
#define TEST_STATIC_FIXED_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __scalar_type_name__, __storage_size__, __macro_for_tests__)
#define VECTOR_UNIT_TESTS_COMPLEX_TYPE(VEC, SCALAR_T)
vec_type::value_type value_type